commit14
This commit is contained in:
@@ -161,16 +161,25 @@ class OrganizationConfiguration
|
||||
|
||||
private function twoAdministrators(int $tenant): void
|
||||
{
|
||||
$count = 0;
|
||||
if (count($this->permanentAdministrators($tenant)) < 2) {
|
||||
throw ValidationException::withMessages(['administrators' => 'Mantenha pelo menos dois administradores permanentes da empresa; manutenção não conta para esse mínimo.']);
|
||||
}
|
||||
}
|
||||
|
||||
/** Same permanent administrator rule for activation, updates and their preview.
|
||||
* @return list<int>
|
||||
*/
|
||||
public function permanentAdministrators(int $tenant): array
|
||||
{
|
||||
$ids = [];
|
||||
foreach (User::query()->where('tenant_id', $tenant)->get() as $user) {
|
||||
$profiles = DB::table('organization_memberships as m')->join('organization_profiles as p', 'p.id', '=', 'm.profile_id')->where('m.tenant_id', $tenant)->where('p.tenant_id', $tenant)->where('m.user_id', $user->id)->where('m.maintenance', false)->whereNull('m.expires_at')->pluck('p.permissions');
|
||||
if ($profiles->contains(fn ($json) => in_array('admin', json_decode($json, true, 32, JSON_THROW_ON_ERROR), true))) {
|
||||
$count++;
|
||||
$ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
if ($count < 2) {
|
||||
throw ValidationException::withMessages(['administrators' => 'Mantenha pelo menos dois administradores permanentes da empresa; manutenção não conta para esse mínimo.']);
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
public function initialise(User $first, User $second): void
|
||||
|
||||
Reference in New Issue
Block a user