Find users with permission
@param  string|Reflex\Lockdown\Permissions\PermissionInterface $permission
@return array
355350
public function findWithPermission($permission)
    {
        return array_filter(
            $this->findAll(),
            function ($user) use ($permission) {
                return $user->has($permission);
            }
        );
    }
184263
protected function getPermissionsByUser(User\UserInterface $user)
	{
		// get the user's direct permissions
		$userPerms = $this->userObjectPermission->findByUser($user);
		
		// get the permissions associated to the user's groups
		$groupPerms = $this->groupObjectPermission->findByGroups($user->getGroups());
		
		// merge the two results and return
		return $userPerms->merge($groupPerms);
	}
1282751
public function getValidator(PermissionInterface $permission)
    {
        /** @var ValidatorInterface|null $validator */
        $validator = $this->validatorPluginManager->get($permission->getValidator());

        if (!$validator) {
            throw new Exception\ValidatorNotFound(sprintf(
                'The validator \"%s\" could not be found',
                is_object($validator) ? get_class($validator) : gettype($validator)
            ));
        }

        if ($permission->getValidatorOptions()) {
            $json = $permission->getValidatorOptions();
            $options = json_decode($json, true);

            if (!$options) {
                throw new Exception\RuntimeException(sprintf(
                    'The options for validator \"%s\" must be in json format',
                    is_object($validator) ? get_class($validator) : gettype($validator)
                ));
            }

            foreach ($options as $method => $value) {
                $validator->{$method}($value);
            }
        }

        return $validator;
    }
640400
public function getPermission($permission)
    {
        if ($permission instanceof PermissionInterface) {
            $permission =   $permission->key;
        }

        return $this->permissions()
            ->key($permission)
            ->first();
    }
425270
protected function checkAccess($permission): bool
    {
        return $this->app->core->user->permissions[$this->app->getName()]->allowedTo($permission);
    }
517891
public function getResourcePermissions(ResourceInterface $resource) : array
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->getQuery();

        return $query->getResult();
    }
270856
public function checkPermission($permission)
    {
        $roleAttribute = "can_{$permission}";
        return isset($this->$roleAttribute) ? (bool)$this->$roleAttribute : false;
    }
1080245
private function restrictPermissions(array $userPermission, array $permissions)
    {
        return $this->mapPermissions($userPermission, $permissions, function($permission1, $permission2) {
            return $permission1 && $permission2;
        });
    }
897314
public function syncPermissions($permissions)
    {
        $sync = [];
        $this->mapArray($permissions, function ($permission) use (&$sync) {

            $sync[] = $this->parsePermissionId($permission);

            return $sync;
        });

        return $this->permissions()->sync($sync);
    }
180984
public function canDo($permission, $force = false)
    {
        if (! is_null($this->getUser())) {
            return $this->getUser()->canDo($permission, $force);
        }

        return false;
    }
1205383
public function hasPermission($permission, $force = false)
    {
        $permissions = $this->getAllPermissions($force)->pluck('name')->toArray();

        if (strpos($permission, '*')) {
            $permission = substr($permission, 0, -2);

            return (bool) preg_grep('~'.$permission.'~', $permissions);
        }

        return in_array($permission, $permissions);
    }
1360925
public function hasPermissionTo($permission): bool
    {
        $permissionClass = $this->getPermissionClass();

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

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

        if (! $this->getGuardNames()->contains($permission->guard_name)) {
            throw GuardDoesNotMatch::create($permission->guard_name, $this->getGuardNames());
        }

        return $this->permissions->contains('id', $permission->id);
    }
113430
public function hasPermissionTo($permission): bool
    {
        if (is_string($permission)) {
            $permission = app(Permission::class)->findByName($permission, $this->getGuardName());
        }

        if ($permission->guard_name !== $this->getGuardName()) {
            throw GuardDoesNotMatch::create($permission->guard_name, $this->getGuardName());
        }

        return $this->permissions->contains('id', $permission->id);
    }
1283016
public function hasAllPermissions($permission)
    {
        foreach ($this->getArrayFrom($permission) as $permission) {
            if (!$this->checkPermission($permission)) {
                return false;
            }
        }

        return true;
    }
71104
public function can($permission)
    {
        $permissions = $this->getPermissions();

        if (is_array($permission)) {
            $permissionCount   = count($permission);
            $intersection      = array_intersect($permissions, $permission);
            $intersectionCount = count($intersection);

            return ($permissionCount == $intersectionCount) ? true : false;
        } else {
            return in_array($permission, $permissions);
        }
    }
860987
public function hasPermissionForUser($user, ...$permission)
    {
        $params = [];

        $params[] = $user;
        foreach ($permission as $perm) {
            $params[] = $perm;
        }

        return $this->hasPolicy($params);
    }
1056629
public function hasAccess(UserInterface $user, string $permission) : bool
    {
        return $this->provider->hasRolePermission($user->getRole(), $permission);
    }