Revokes specified forum user role, and sets default forum user role
@param int|string $idOrEmail internal podium user id or email
@param string $role one of 'podiumUser', 'podiumModerator', 'podiumAdmin' or other application defined role
324400
public function actionRevokeRole($idOrEmail, $role)
    {
        if (!$user = $this->findUser($idOrEmail)) {
            return self::EXIT_CODE_ERROR;
        }
        $rbac = Podium::getInstance()->getRbac();
        if (!$role = $rbac->getRole($role)) {
            $this->stderr('No such role.' . PHP_EOL);
            return self::EXIT_CODE_ERROR;
        }
        if (strpos($role->name, 'podium') === 0) {
            $defaultPodiumRole = $rbac->getRole(Rbac::ROLE_USER);
            $this->setPodiumUserRole($user, $defaultPodiumRole);
            $this->stdout("user#{$user->id} has role '{$defaultPodiumRole->name}'" . PHP_EOL);
        } else {
            $rbac->revoke($role, $user->id);
            $this->stdout("user#{$user->id} role '{$role->name}' revoked" . PHP_EOL);
        }
    }
956360
public function detachRole($role, $reload = true)
    {
        event(new DetachingRoleFromPermission($this, $role));
        $results = $this->roles()->detach($role);
        event(new DetachedRoleFromPermission($this, $role, $results));

        $this->loadRoles($reload);

        return $results;
    }
632507
public function deassociate(string $role, string $permission): PermissionManager
    {
        return $this->associate($role, $permission, ForbidRule::class);
    }
683370
public function promoteTo($role)
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            $this->scenario = 'role';
            $this->role = $role;
            if (!$this->save()) {
                throw new Exception('User saving error!');
            }
            if (Podium::getInstance()->rbac->getRolesByUser($this->id)
                && !Podium::getInstance()->rbac->revoke(Podium::getInstance()->rbac->getRole(Rbac::ROLE_USER), $this->id)) {
                throw new Exception('User role revoking error!');
            }
            if (!Podium::getInstance()->rbac->assign(Podium::getInstance()->rbac->getRole(Rbac::ROLE_MODERATOR), $this->id)) {
                throw new Exception('User role assigning error!');
            }
            Activity::updateRole($this->id, User::ROLE_MODERATOR);

            $transaction->commit();
            Log::info('User promoted', $this->id, __METHOD__);
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
868929
public function revokeRole($role, $user_id)
    {
        $user = \App\User::findorfail($user_id);

        $user->removeRole(str_slug($role, ' '));

        return redirect('scaffold-users/edit/'.$user_id);
    }
39604
public function addRole($id, $role)
    {
        if (empty($role) || !$user = $this->getUser($id)) {
            return false;
        }

        // Add the role to the $user['roles'] array
        $user['roles'][] = $role;

        return $this->saveUser($user);
    }
432725
public function removeRole(Role $role)
    {
        $this->initializeRoles();
        if ($this->hasRole($role)) {
            $roleIdentifier = $role->getIdentifier();
            unset($this->roles[$roleIdentifier]);
            $identifierIndex = array_search($roleIdentifier, $this->roleIdentifiers);
            unset($this->roleIdentifiers[$identifierIndex]);
        }
    }
1056483
protected function addRoles(IdentityInterface $identity, AuthorizationInfo $info): PdoRealm
    {
        $statement = $this
            ->getPdo()
            ->prepare($this->getRolesQuery());
        $statement->execute([
            $identity->getIdentifier(),
        ]);

        foreach ($statement->fetchAll() as $role) {
            $info->addRole(
                new Role($role['name'])
            );
        }

        return $this;
    }
360889
public function removeRole($role)
    {
        if ($role instanceof Role) {
            $role = $role->id;
        }

        if (false !== ($index = array_search($role, $this->attributes['roles']))) {
            unset($this->attributes['roles'][$index]);
        }

        return true;
    }
1251535
public function actionShowRoles($idOrEmail)
    {
        if (!$user = $this->findUser($idOrEmail)) {
            return self::EXIT_CODE_ERROR;
        }
        $roles = Podium::getInstance()->getRbac()->getRolesByUser($user->id);
        print_r($roles);
    }
10475
public function setRoleUnauthenticated($role)
    {
        $role = (string) $role;
        if ($role === '') {
            throw new \InvalidArgumentException('$role cannot be empty');
        }

        $this->roleUnauthenticated = $role;
    }
294435
public function removeUserRole($user, $role)
    {
        $user   =   $this->findUserById($user);
        $role   =   $this->findRoleByKey($role);

        if ($user->not($role->key)) {
            return true;
        }

        return $user->leave($role);
    }
369219
public function inviteNewUser($email, $roles)
    {
        $user = static::firstOrCreate(compact('email'));
        $user->assignRole($roles);

        /** @var Invitation $invites */
        $invites = app(Invitation::class);
        $invites->generateToken($user->id);

        Detail::firstOrCreate([
            'user_id'      => $user->id,
            'display_name' => $email,
        ]);

        return $user;
    }
548934
public function revokeRole(Role $role): bool
    {
        return (new actions\RevokeRole($this->user, $role))->execute();
    }
32768
public function downgradeFromRole(Role $role): bool
    {
        $auth = \Yii::$app->getAuthManager();
        if ($auth->revoke($role, $this->id)) {
            return true;
        }
        return false;
    }
367089
public function destroy(Role $role)
    {
        try {
            $name = $role->name;
            $role->delete();

            flash()->info(__('The :name role has been deleted', ['name' => $name]));
        } catch (\Exception $e) {
            flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
        }

        return redirect(route('appshell.role.index'));
    }
129435
public function removeRole($role)
    {
        $this->roles()->detach($this->getStoredRole($role));

        $this->load('roles');

        return $this;
    }