You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

26 lines
657 B

<?php
namespace App\Domains\Identity\Actions\AccessControl;
use App\Domains\Identity\Enums\RoleType;
use App\Domains\Identity\Models\Role;
use Exception;
use function in_array;
class RemoveSystemRole
{
/**
* @throws Exception
*/
public function execute(Role $role): void
{
if (in_array($role->name, [RoleType::ADMIN->value, RoleType::SYSTEM_ADMIN->value])) {
throw new Exception(__('domains/identity/messages.exceptions.cannot_remove_system_role'));
}
if ($role->users()->exists()) {
throw new Exception(__('domains/identity/messages.exceptions.role_has_users'));
}
}
}