Checks if the user can do something and if he owns the thing.

@param  string|array  $permission
@param  Object  $thing
@param  array  $options
@return boolean
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']);
    }
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);
        }
    }
1004802
public function hasPermission($permission)
    {
        $permission = !is_string($permission) ?: Permission::where(['slug' => $permission])->first();
        
        if (config('laralum.superadmin_bypass_haspermission')) {
            return true;
        }
        
        if ($permission) {
            foreach ($this->roles as $role) {
                if ($role->hasPermission($permission)) {
                    return true;
                }
            }
        }

        return false;
    }
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;
    }
948066
protected function checkPermission(array $prepared, $permission)
    {
        if (array_key_exists($permission, $prepared) && $prepared[$permission] === true) {
            return true;
        }

        $permission = (string) $permission;

        foreach ($prepared as $key => $value) {
            $key = (string) $key;

            if ((str_is($permission, $key) || str_is($key, $permission)) && $value === true) {
                return true;
            }
        }

        return false;
    }
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);
    }
11758
public static function can($permissionName, $params = [], $allowCaching = true)
    {
        $user = Yii::$app->user;
        $adminId = (array) Yii::$app->getModule('wechat')->adminId;
        return in_array($user->getId(), $adminId) || $user->can($permissionName, $params, $allowCaching);
    }
438302
public function hasPermissionTo($permission, $guardName = null): bool
    {
        if (is_string($permission)) {
            $permission = PermissionProxy::findByName(
                $permission,
                $guardName ?? $this->getDefaultGuardName()
            );
        }

        return $this->hasDirectPermission($permission) || $this->hasPermissionViaRole($permission);
    }
1337775
protected function hasPermission(string $permission, bool $return = false)
    {
        $auth = $this->getContext()->getAuthentication();
        $user = $auth->getUser();
        $acl = $this->getContext()->getAccessControlList();

        if (!$acl->hasAccess($user, $permission)) {

            if ($return) {
                return false;
            }else{
                throw HttpException::forbidden('The current user has no permission to this action');
            }
        }

        return true;
    }
1350993
private function checkIfUserHasPermission($permission)
    {
        if (!$this->isGranted($permission, $this->entityClass)) {
            throw $this->createAccessDeniedException(
                sprintf('You do not have "%s" permission on "%s" class objects.', $permission, $this->entityClass)
            );
        }
    }
195123
public function hasPermission($permission)
    {
        return $this->roles->each(function ($role) use ($permission) {
            if (in_array($permission, explode(',', $role->permissions))) {
                return true;
            }
        });

        return false;
    }
703593
public function hasDirectPermission($permission): bool
    {
        if (is_string($permission)) {
            $permission = PermissionProxy::findByName($permission, $this->getDefaultGuardName());

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

        return $this->permissions->contains('id', $permission->id);
    }
1316323
public static function require (string $permission): bool {
		if (empty($permission)) {
			return true;
		}

		return self::$user->hasPermission($permission);
	}
493252
public function hasPermission($permission): bool
    {
        if (!\in_array($permission, $this::$permissions, true)) {
            throw new \UnexpectedValueException("Permissions does not exists: {$permission}");
        }
        $accessor = PropertyAccess::createPropertyAccessor();

        return $accessor->getValue($this, $permission);
    }
288597
public function hasPermissionTo($permission, $guardName = null): bool
    {
        $permissionClass = $this->getPermissionClass();

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

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

        if (! $permission instanceof Permission) {
            throw new PermissionDoesNotExist;
        }

        return $this->hasDirectPermission($permission) || $this->hasPermissionViaRole($permission);
    }
875041
public static boolean hasPermission(Permission permission) {
        SecurityManager security = System.getSecurityManager();
        if (security != null) {
            try {
                security.checkPermission(permission);
            } catch (java.security.AccessControlException e) {
                return false;
            }
        }
        return true;
    }
110256
public function can($permission, $requireAll = false)
    {
        if (is_array($permission)) {
            foreach ($permission as $permName) {
                $hasPerm = $this->can($permName);

                if ($hasPerm && !$requireAll) {
                    return true;
                } elseif (!$hasPerm && $requireAll) {
                    return false;
                }
            }

            // If we've made it this far and $requireAll is FALSE, then NONE of the perms were found
            // If we've made it this far and $requireAll is TRUE, then ALL of the perms were found.
            // Return the value of $requireAll;
            return $requireAll;
        } else {
            foreach ($this->cachedRoles() as $role) {
                // Validate against the Permission table
                foreach ($role->cachedPermissions() as $perm) {
                    if (str_is( $permission, $perm->name) ) {
                        return true;
                    }
                }
            }
        }

        return false;
    }