Fetch a role from the database via its unique name.

@param string $role_name Role name
@param bool $permissions
@return bool|Role
174222
public function roleFetchByName($role_name, $permissions = true)
    {
        $role = $this->storage->roleFetchByName($role_name);
        if ($role and $permissions) {
            $this->roleLoadPermissions($role);
        }
        return $role;
    }
468444
public ArrayList<OvhPermission> serviceName_role_roleId_permission_permissionId_GET(String serviceName, String roleId, String permissionId) throws IOException {
		String qPath = "/dbaas/logs/{serviceName}/role/{roleId}/permission/{permissionId}";
		StringBuilder sb = path(qPath, serviceName, roleId, permissionId);
		String resp = exec(qPath, "GET", sb.toString(), null);
		return convertTo(resp, t5);
	}
13426
public function update($role_id, array $data)
    {
        $result = null;
        $this->hook->attach('user.role.update.before', $role_id, $data, $result, $this);

        if (isset($result)) {
            return (bool) $result;
        }

        $result = (bool) $this->db->update('role', $data, array('role_id' => $role_id));
        $this->hook->attach('user.role.update.after', $role_id, $data, $result, $this);
        return (bool) $result;
    }
271706
public Grantee getRole(String name) {

        Grantee g = (Grantee) roleMap.get(name);

        if (g == null) {
            throw Error.error(ErrorCode.X_0P000, name);
        }

        return g;
    }
465115
static function fetchByName( $roleName, $version = 0 )
    {
        return eZPersistentObject::fetchObject( eZRole::definition(),
                                                null, array( 'name' => $roleName,
                                                             'version' => $version ), true );
    }
1016946
public function retrieveEmployeeRole($role_id)
    {
        list($response, $statusCode, $httpHeader) = $this->retrieveEmployeeRoleWithHttpInfo ($role_id);
        return $response; 
    }
1150774
private function checkRoleGlobalPermission($roleName, $permissionName)
    {
        $roles = $this->getRolesByGlobalPermission($permissionName);
        if (!is_array($roles)) {
            // We log it, unless the permission name is 'root'.
            if ($roleName !== self::ROLE_ROOT) {
                $this->app['logger.system']->warn(
                    "Configuration error: Permission '$permissionName' is not granted to any roles. You should add a role for this permission to <tt>permissions.yml</tt>.",
                    ['event' => 'authentication']
                );
            }

            return false;
        }

        return in_array($roleName, $roles);
    }
1316415
public function getRolesByContentTypePermission($permissionName, $contenttype)
    {
        // Here's how it works:
        // - if a permission is granted through 'contenttype-all', it is effectively granted
        // - if a permission is granted through 'contenttypes/$contenttype', it is effectively granted
        // - if 'contenttypes/$contenttype/$permissionName' is not set, *and* the permission is granted through 'contenttype-default', it is effectively granted
        // - otherwise, the permission is denied
        $overrideRoles = $this->app['config']->get("permissions/contenttype-all/$permissionName");
        if (!is_array($overrideRoles)) {
            $overrideRoles = [];
        }
        $contenttypeRoles = $this->app['config']->get("permissions/contenttypes/$contenttype/$permissionName");
        if (!is_array($contenttypeRoles)) {
            $contenttypeRoles = $this->app['config']->get("permissions/contenttype-default/$permissionName");
        }
        if (!is_array($contenttypeRoles)) {
            $contenttypeRoles = [];
        }
        $effectiveRoles = array_unique(array_merge($overrideRoles, $contenttypeRoles));

        return $effectiveRoles;
    }
142020
public static function checkAccess($permissionName, $user = false, $params = [])
    {
        if (is_array($permissionName)) {
            $permissionName = self::createPermissionName($permissionName);
        }
        if (!$user) {
            $user = Yii::$app->user;
        }

        if (!$user->isGuest && !isset(self::$userRoles[$user->id])) {
            self::$userRoles[$user->id] = Yii::$app->authManager->getRolesByUser($user->id);
        }

        if (isset(self::$userRoles[$user->id][self::ROLE_ROOT])) {
            return true;
        }

        if (!self::$defaultRoles) {
            self::setDefaultRoles($user->id);
        }
        if (in_array($permissionName, self::$defaultRoles)) {
            return true;
        }

        return $user->can($permissionName, $params);
    }
981413
protected function getRolesWithPermission() {
    $roles_with_perm = [];

    /* @var \Drupal\user\RoleInterface[] $roles */
    $roles = Role::loadMultiple();

    // Check for each role which one has permission to "view inappropriate
    // reports".
    foreach ($roles as $role) {
      if ($role->hasPermission('view inappropriate reports')) {
        $roles_with_perm[] = $role->id();
      }
    }

    return $roles_with_perm;
  }
868175
public function roleHasPermission($permission, $force = false)
    {
        $permissions = $this->getRolesPermissions($force)->pluck('name')->toArray();

        return in_array($permission, $permissions);
    }
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;
    }
117454
public function rolePermissionAdd(Role $role, Permission $permission)
    {
        return $this->storage->rolePermissionAdd($role, $permission);
    }
1240187
public function isPermissionAssigned($permissionId, $roleIds)
    {
        $qb = $this->createQueryBuilder('rolePermission');

        $result = $qb
            ->select('rolePermission.id')
            ->where(
                $qb->expr()->andX(
                    $qb->expr()->eq('rolePermission.permissionId', $permissionId),
                    $qb->expr()->in('rolePermission.roleId', $roleIds)
                )
            )
            ->setMaxResults(1)
            ->getQuery()
            ->getArrayResult();

        return count($result) > 0;
    }
653418
public function getCompleteRole(int $role_id = null)
    {

        $roles = RoleModel::with('permissions', 'groups', 'affiliations');

        if (! is_null($role_id)) {

            $roles = $roles->where('id', $role_id)->first();

            if (! $roles) abort(404);

            return $roles;
        }

        return $roles->get();
    }
827069
private function checkRolePermission($roleName, $permissionName, $type = 'global', $item = null)
    {
        if ($type === 'global') {
            return $this->checkRoleGlobalPermission($roleName, $permissionName);
        } elseif ($type === 'roles-hierarchy') {
            return $this->checkRoleHierarchyPermission($roleName, $permissionName, $item);
        } elseif ($type === 'contenttype') {
            return $this->checkRoleContentTypePermission($roleName, $permissionName, $item);
        }

        throw new \InvalidArgumentException('Unknown permission type to check');
    }
1004792
public function permissionFetchByRole(Role $role)
    {
        $query = "
            SELECT
                p.permission_id, p.name, p.description
            FROM
                auth_permission p
            LEFT JOIN
                auth_role_permissions r ON r.permission_id = p.permission_id
            WHERE r.role_id = :role_id
        ";
        $cur = $this->db->prepare($query);
        $cur->bindParam(":role_id", $role->role_id, PDO::PARAM_INT);
        try {
            $cur->execute();
            $permissions = $cur->fetchAll(PDO::FETCH_CLASS, self::CLASS_PERMISSION);
        } catch (PDOException $db_err) {
            if ($this->logger) {
                $this->logger->error("Error trying to fetch role permissions", ['exception' => $db_err]);
            }
            return [];
        }
        return $permissions;
    }