Save permission in database
@param Permission $permission
@throws NotUniqueException
@throws DatabaseException
548803
public function addPermission(Permission $permission)
    {
        try {
            $this->saveEntity($permission);
        } catch (UniqueConstraintViolationException $e) {
            throw new NotUniqueException('Permission with name ' . $permission->getName() . ' already created');
        }
    }
1115461
public function hasOnePermission($permission)
    {
        foreach ($this->getArrayFrom($permission) as $permission) {
            if ($this->checkPermission($permission)) {
                return true;
            }
        }

        return false;
    }
148998
public function hasPermission($permission)
    {
        if (!$permission) {
            return false;
        }
        foreach ($this->permissions as $perm) {
            if ($perm->name == $permission) {
                return true;
            }
        }
        return false;
    }
1012668
private function createRoles(Permission $permission): void
	{
		/* @var $role AclRole */
		foreach ($this->orm->aclRoles->findSorted() as $role) {
			$parent = null;
			if ($role->parent) {
				$parent = $role->parent->name;
			}
			$permission->addRole($role->name, $parent);
		}
	}
639114
public function update(Permission $permission)
    {
        $this->validate($this->request, [
            'name'     => 'required',
            'resource' => 'required|alpha_num',
            'slug'     => 'required|unique:permissions,slug,' . $permission->id,
        ]);

        $permission->name     = $this->request->get('name');
        $permission->resource = $this->request->get('resource');
        if (! $permission->system) {
            $permission->slug = $this->request->get('slug');
        }
        $permission->save();

        $permission->syncRoles($this->request->get('roles', []));

        return redirect()->route('administrator.permissions.index');
    }
1108313
public function attachPermission($permission)
    {
        if ($this->getPermissions()->contains($permission)) {
            return true;
        }
        $this->permissions = null;

        return $this->userPermissions()->attach($permission);
    }
1196775
public function checkPermission($permission)
    {
        return $this->getPermissions()->contains(function ($value) use ($permission) {
            return $permission == $value->id || Str::is($permission, $value->slug);
        });
    }
1054906
public function setPermissionsAttribute($permission)
    {
        if (! ($permission instanceof RolePermission)) {
            $permissionPart = $this->factory->create(RolePermission::class);
            $permissionPart->decodeBitwise($permission);

            $permission = $permissionPart;
        }

        $this->attributes['permissions'] = $permission;
    }
263987
public function hasDirectPermission($permission): bool
    {
        $permissionClass = $this->getPermissionClass();

        if (is_string($permission)) {
            $permission = $permissionClass->findByName($permission, $this->getDefaultGuardName());
            if (! $permission) {
                return false;
            }
        }

        if (is_int($permission)) {
            $permission = $permissionClass->findById($permission, $this->getDefaultGuardName());
            if (! $permission) {
                return false;
            }
        }

        if (! $permission instanceof Permission) {
            return false;
        }

        return $this->permissions->contains('id', $permission->id);
    }
770237
public function chmod($permission,$file)
    {
        if (! ftp_chmod($this->session, $permission, $file)) {
            throw new \RuntimeException('Chmod can not be changed');
        }
        return true;
    }
883112
public function hasPermission(string $permission): bool {
		$role = new role($this->user->role->name);

		return $role->hasPermission($permission);
	}
692141
protected function updatePermission($permission, $description = '', $ruleName = null, $data = null)
    {
        if (is_string($permission)) {
            $permission = $this->findPermission($permission);
        }

        echo "    > update permission $permission->name ...";
        $time = microtime(true);

        $permission->description = $description;
        $permission->ruleName    = $ruleName;
        $permission->data        = $data;

        $this->authManager->update($permission->name, $permission);
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";

        return $permission;
    }
1315050
protected function setPermissionSetting(Permission $permission, $allowed = true)
    {
        /** @var Model $this */
        if ($permission->isNewRecord()) {
            throw new PermissionException("The permission has not been saved.");
        }

        if ($this->isNewRecord()) {
            throw new PermissionException("The model has not been saved.");
        }

        $foreignKeyField = $this->getUniqueIdentifierColumnName();
        $foreignKeyValue = $this->getUniqueIdentifier();
        try {
            $assignment = PermissionAssignment::findFirst(
                new AndGroup([
                    new Equals('PermissionID', $permission->PermissionID),
                    new Equals($foreignKeyField, $foreignKeyValue),
                ])
            );
        } catch (RecordNotFoundException $ex) {
            $assignment = new PermissionAssignment();
            $assignment->PermissionID = $permission->PermissionID;
            $assignment->$foreignKeyField = $foreignKeyValue;
        }
        $assignment->Access = $allowed ? 'Allowed' : 'Denied';
        $assignment->save();

        return $assignment->PermissionAssignmentID;
    }
142494
public function hasPermission($permission)
    {
        if ($this->isAdmin()) {
            return true;
        }

        if (is_null($this->permissions)) {
            $this->permissions = $this->getPermissions();
        }

        return in_array($permission, $this->permissions);
    }
197247
public function removePermission(
        UUID $uuid,
        Permission $permission
    ) {
        if (in_array($permission, $this->permissions)) {
            $this->apply(new PermissionRemoved($uuid, $permission));
        }
    }
816526
public function attachPermission(&$permission, $reload = true)
    {
        if ($this->hasPermission($permission)) return;

        event(new AttachingPermissionToGroup($this, $permission));
        $permission = $this->permissions()->save($permission);
        event(new AttachedPermissionToGroup($this, $permission));

        $this->loadPermissions($reload);
    }
1219994
public function attachPermission($permission, $reload = true)
    {
        if ($this->hasPermission($permission)) return;

        event(new AttachingPermissionToRole($this, $permission));
        $this->permissions()->attach($permission);
        event(new AttachedPermissionToRole($this, $permission));

        $this->loadPermissions($reload);
    }