Detach a permission from a role.

@param  \Arcanesoft\Contracts\Auth\Models\Permission|int  $permission
@param  bool                                              $reload

@return int
504846
public function detachPermission($permission, $reload = true)
    {
        if ( ! $this->hasPermission($permission)) return 0;

        event(new DetachingPermissionFromRole($this, $permission));
        $results = $this->permissions()->detach($permission);
        event(new DetachedPermissionFromRole($this, $permission, $results));

        $this->loadPermissions($reload);

        return $results;
    }
337805
public function permission($permission): bool
    {
        $perms = fileperms($this->getAbsoluteFilePath());

        switch ($permission) {
            case FilePermission::READ_OWNER:
                return (($perms & 0x0100) ? true : false);

            case FilePermission::WRITE_OWNER:
                return (($perms & 0x0080) ? true : false);

            case FilePermission::EXE_OWNER:
                return (($perms & 0x0040) ?
                    (($perms & 0x0800) ? null /* 's' */ : true) :
                    (($perms & 0x0800) ? null /* 'S' */ : false));

            case FilePermission::READ_USER:
                return $this->isReadable();

            case FilePermission::WRITE_USER:
                return $this->isWritable();

            case FilePermission::EXE_USER:
                return $this->isExecutable();

            case FilePermission::READ_GROUP:
                return (($perms & 0x0020) ? true : false);

            case FilePermission::WRITE_GROUP:
                return (($perms & 0x0010) ? true : false);

            case FilePermission::EXE_GROUP:
                return (($perms & 0x0008) ?
                    (($perms & 0x0400) ? null /* 's' */ : true) :
                    (($perms & 0x0400) ? null /* 'S' */ : false));

            case FilePermission::READ_OTHER:
                return (($perms & 0x0004) ? true : false);

            case FilePermission::WRITE_OTHER:
                return (($perms & 0x0002) ? true : false);

            case FilePermission::EXE_OTHER:
                return (($perms & 0x0001) ?
                    (($perms & 0x0200) ? null /* 't' */ : true) :
                    (($perms & 0x0200) ? null /* 'T' */ : false));
        }

        return true;
    }
530106
public function getPermissionStatus(string $role, string $permission, string $resource) : bool
    {
        if (!$this->roleRegistry->exists($role)) {
            throw new \Exception(
                sprintf(
                    "The role: %s doesnt exist",
                    (string)$role
                )
            );
        }

        if (!$this->permissionRegistry->exists($permission)) {
            throw new \Exception(
                sprintf(
                    "The permission: %s doesnt exist",
                    (string)$permission
                )
            );
        }

        if (!$this->resourceRegistry->exists($resource)) {
            throw new \Exception(
                sprintf(
                    "The resource: %s doesnt exist",
                    (string)$resource
                )
            );
        }

        $roleObject = $this->globalRegistry->get($role);

        if (isset($roleObject[$resource][$permission]["status"]))
        {
            return $roleObject[$resource][$permission]["status"];
        }

        $parents = $this->roleRegistry->getRegistry()[$role];

        foreach ($parents as $parentRole)
        {
            $permissionStatus = $this->getPermissionStatus($parentRole, $permission, $resource);

            if ($permissionStatus)
            {
                return true;
            }
        }

        return false;
    }
1030248
private function removeDeletedPermissions(array $permission): void
    {
        $configActions = collect($permission['actions']);

        $actions = $this->permissionRepository->makeQuery()->where('name', $permission['name'])->pluck('action');

        $removedActions = $actions->diff($configActions);

        if ($removedActions->isNotEmpty()) {
            foreach ($removedActions as $action) {
                $this->permissionRepository->deletePermission($action);
            }
        }
    }
154963
public function deny(string $role, string $permission, string $resource)
    {
        $this->allow($role, $permission, $resource, false);
    }
597210
public function revokePermission($permission)
    {
        if ($this->hasPermission($permission)) {
            unset($this->permissions[$permission]);
            return true;
        } else {
            return false;
        }
    }
1167854
public function deletePermission($permission)
    {
        if ($this->hasPermission($permission)) {
            return PermissionRole::where(
                    ['role_id' => $this->id, 'permission_id' => $permission->id]
                )->first()->delete();
        }

        return false;
    }
586455
public function remove(PermissionInterface $permission)
    {
        $this->cache($permission->key, null);

        if (! is_null($this->getPermission($permission))) {
            $this->permissions()
                ->detach($permission);
        }

        return true;
    }
274882
private function checkPermission(array &$retValue, $filePath, $permission)
    {
        $isOk = true;
        switch ($permission) {
            case self::PERMISSION_READ:
                if (!$this->checkReadable($filePath)) {
                    $retValue[] = new CheckOutcome(
                        'check.file_permission.notreadable',
                        array('%0%' => $filePath),
                        $this->getLevel()
                    );
                    $isOk = false;
                }
                break;
            case self::PERMISSION_WRITE:
                if (!$this->checkWritable($filePath)) {
                    $retValue[] = new CheckOutcome(
                        'check.file_permission.notwritable',
                        array('%0%' => $filePath),
                        $this->getLevel()
                    );
                    $isOk = false;
                }
                break;
            case self::PERMISSION_EXECUTE:
                if (!$this->checkExecutable($filePath)) {
                    $retValue[] = new CheckOutcome(
                        'check.file_permission.notexecutable',
                        array('%0%' => $filePath),
                        $this->getLevel()
                    );
                    $isOk = false;
                }
                break;
            default:
                $retValue[] = new CheckOutcome(
                    'check.file_permission.invalidtype',
                    array('%0%' => $permission),
                    CheckOutcome::ERROR
                );
                $isOk = false;
                break;
        }

        return $isOk;
    }
467208
def revoke_permission(user, permission_name):
    
    roles = get_user_roles(user)

    for role in roles:
        if permission_name in role.permission_names_list():
            permission = get_permission(permission_name)
            user.user_permissions.remove(permission)
            return

    raise RolePermissionScopeException(
        "This permission isn't in the scope of "
        "any of this user's roles.")
632507
public function deassociate(string $role, string $permission): PermissionManager
    {
        return $this->associate($role, $permission, ForbidRule::class);
    }
1038512
public function assignPermission($permission)
    {
        return $this->mapArray($permission, function ($permission) {

            $permissionId = $this->parsePermissionId($permission);

            if ( ! $this->permissions->keyBy('id')->has($permissionId) ) {
                $this->permissions()->attach($permissionId);

                return $permission;
            }

            return false;
        });
    }
1248448
public function removeRolePermission($role, $permission)
    {
        $role       =   $this->findRoleByKey($role);
        $permission =   $this->findPermissionByKey($permission);

        return $role->remove($permission);
    }
102040
public function revokeUserAccess($resource, string $action)
    {
        $resourceRule = $this->getUserPermission($resource);

        if (!$resourceRule) {
            return;
        }

        // make sure we can work with this
        if ($resourceRule && !($resourceRule instanceof UserPermissionInterface)) {
            throw new PermissionExpectedException(UserPermissionInterface::class, \get_class($resourceRule));
        }

        if ($resourceRule) {
            if (!\in_array($action, $resourceRule->getActions(), true)) {
                return;
            }
            $resourceRule->removeAction($action);
            $this->userPermissions->update($resourceRule);
        }
    }
868175
public function roleHasPermission($permission, $force = false)
    {
        $permissions = $this->getRolesPermissions($force)->pluck('name')->toArray();

        return in_array($permission, $permissions);
    }
676715
public function removeRolePermission(Role $role, Permission $permission)
    {
        $query = $this->getTable()
            ->where('role', $role->getRoleName())
            ->where('type', $permission->getType())
            ->where('action', $permission->getAction());

        if (is_null($permission->getResourceType())) {
            $query->whereNull('resource_type');
        } else {
            $query->where('resource_type', $permission->getResourceType());
        }

        if (is_null($permission->getResourceId())) {
            $query->whereNull('resource_id');
        } else {
            $query->where('resource_id', $permission->getResourceId());
        }

        $query->delete();

        $this->resetPermissionsCacheForRole($role);
    }
19813
public function detachRole($role, $reload = true)
    {
        event(new DetachingRoleFromUser($this, $role));
        $results = $this->roles()->detach($role);
        event(new DetachedRoleFromUser($this, $role, $results));

        $this->loadRoles($reload);

        return $results;
    }