@param Permission     $permission
@param TokenInterface $token
@param string|null    $objectLanguage

@return bool
185917
public function check(Permission $permission, TokenInterface $token, $objectLanguage = null)
    {
        $user = $token->getUser();

        $masks = $this->getEffectiveMasks();
        if (isset($masks[$this->userClass][$user->getId()])) {
            if ($masks[$this->userClass][$user->getId()] & $permission->getBit()) {
                return true;
            }
        }
        foreach ($user->getGroups() as $group) {
            if (isset($masks[$this->groupClass][$group->getId()])) {
                if ($masks[$this->groupClass][$group->getId()] & $permission->getBit()) {
                    return true;
                }
            }
        }

        return false;
    }
386610
protected function disallowSingleGroupPermission($permission, $object, $group)
	{
		// check to see if the permission exists
		$permObject = $this->permission->findByPermissionAndObject($permission, $object);
		
		if($permObject)
		{
			$gop = $this->groupObjectPermission->findPermission($group, $object, $permObject);
			
			if($gop)
			{
				$this->groupObjectPermission->delete($gop);
			}
		}
	}
146444
public function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        return $this->isOrganizationManager($token, $subject) ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED;
    }
1373882
protected function voteOnAttribute($attribute, $subject,
                                       TokenInterface $token)
    {
        $granted = true;
        $uroles  = array();
        foreach ($token->getRoles() as $role) {
            $uroles[] = $role->getRole();
        }
        foreach ($this->subjectPrefixes as $prefix => $proles) {
            if (substr($subject, 0, strlen($prefix)) != $prefix) {
                continue;
            }
            $granted = false;
            if (count(array_intersect($uroles, $proles)) > 0) {
                return true;
            }
        }
        return $granted;
    }
341894
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        /** @var BaseUser $user */
        $user = $token->getUser();

        return $user instanceof BaseUser && ($user->hasRole('ROLE_ADMIN') || $user->getId() === $subject->getId());
    }
425733
public function userCan($permission, $object, $user = null)
	{
		// if no user is specified, default to the Auth one
		if(is_null($user))
		{
			$user = app('auth')->user();
		}
		
		$adminGroups = $this->groupProvider()->findAdminGroups();
		
		if($adminGroups->count() > 0 && $user->inGroup($adminGroups))
			return true;
		
		// find the exact permission for the object
		$permObject = $this->permission->findByPermissionAndObject($permission, $object);
		
		// if the permission object doesn't exist, then they don't have access
		if(!$permObject)
			return false;
		
		// if the user has direct permission, allow
		$uop = $this->userObjectPermission->findPermission($user, $object, $permObject);
		
		if($uop)
			return true;
		
		// get all the groups that have that specific permission on the object
		$gop = $this->groupObjectPermission->findPermissions($object, $permObject);
		
		// if there are no groups, deny
		if(count($gop) == 0)
			return false;
		
		// get all the relevant groups
		$groups = array();
		foreach($gop as $onePermission)
		{
			$groups[] = $onePermission->getGroup();
		}
		
		// allow or deny based on whether the user is in those groups
		return $user->inGroup($groups);
	}
902316
public function canView(GroupableInterface $media, TokenInterface $token): bool
    {
        $user = $token->getUser();
        if (0 == count($media->getGroups())) {
            return true;
        }

        return parent::canView($media, $token);
    }
1102389
public function hasPermission($permission)
    {
        if (!$this->permissions->where('token', $permission)->isEmpty()) {
            return true;
        }

        foreach ($this->groups as $group) {
            foreach ($group->roles as $role) {
                if (!$role->permissions->where('token', $permission)->isEmpty()) {
                    return true;
                }
            }
        }

        foreach ($this->roles as $role) {
            if (!$role->permissions->where('token', $permission)->isEmpty()) {
                return true;
            }
        }

        return false;
    }
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;
    }
1047220
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        $user = $token->getUser();
        if (!$user instanceof UserInterface) {
            return false;
        }

        return $this->canDelete($subject);
    }
137117
protected function containsRole(TokenInterface $token, ReadNodeInterface $subject)
    {
        $tokenRoles = $this->roleHierarchy->getReachableRoles($token->getRoles());;
        foreach ($tokenRoles as $key => $role) {
            if ($role instanceof RoleInterface) {
                $tokenRoles[$key] = $role->getRole();
            }
        }

        return empty($subject->getFrontRoles())
            || ($this->accessDecisionManger->decide($token, array('IS_AUTHENTICATED_FULLY'))
                && !empty(array_intersect($tokenRoles, $subject->getFrontRoles())));
    }
965578
public function canAndOwns($permission, $thing, $options = [])
    {
        $options = Helper::checkOrSet('requireAll', $options, [false, true]);
        $options = Helper::checkOrSet('foreignKeyName', $options, [null]);
        $options = Helper::checkOrSet('team', $options, [null]);

        return $this->hasPermission($permission, $options['team'], $options['requireAll'])
                && $this->owns($thing, $options['foreignKeyName']);
    }
978302
public function grantAccessByPermission($permission, UserInterface $user = null)
    {
        $user = $user ? : $this->currentUser();
        return in_array($permission, $this->gatherPermissions($user));
    }
60106
protected function externalAccessCheck($permission, $type, $context) {
    $permissionTypeCollection = $this->getPermissionTypeCollection();
    if(!$permissionTypeCollection->has($type)) {
      throw new PermissionTypeNotRegisteredException("The permission type \"$type\" could not be found.");
    }

    $access = false;
    $permissionType = $permissionTypeCollection->get($type);
    $access = $permissionType->checkPermission($permission, $context);
    if(!is_bool($access)) {
      throw new InvalidReturnTypeException("The permission type \"$type\" must return a boolean, see Ordermind\LogicalPermissions\PermissionTypeInterface::checkPermission().");
    }

    return $access;
  }
331253
public function removeCallerPermission(Caller $caller, Permission $permission)
    {
        $query = $this->getTable()
            ->where('caller_type', $caller->getCallerType())
            ->where('caller_id', $caller->getCallerId())
            ->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->resetPermissionsCacheForCaller($caller);
    }
360833
private function checkTokenForForbiddenOrDiscouragedRule(RuleInterface $rule, string $token): bool
    {
        foreach ($rule->getRequirements() as $req) {
            if (strpos($token, $req) !== false) {
                return false;
            }
        }

        return true;
    }
139707
protected function evaluatePermission(Permission $permission, Subject $subject, Resource $resource, array $params)
    {
        if (!$permission->appliesToResource($resource)) {
            return false;
        }

        if (!$permission->evaluate($subject, $resource, $params)) {
            return false;
        }

        return true;
    }