getPermissions() public method

Get the permissions for one or more roles.
public getPermissions ( integer | array $RoleID ) : array
$RoleID integer | array One or more role IDs to get the permissions for.
return array Returns an array of permissions.
Example #1
0
 /**
  *
  *
  * @param int $UserID
  * @param bool $Refresh
  * @return array|object|false
  */
 public function getSession($UserID, $Refresh = false)
 {
     // Ask for the user. This will check cache first.
     $User = $this->getID($UserID, DATASET_TYPE_OBJECT);
     if (!$User) {
         return false;
     }
     // If we require confirmation and user is not confirmed
     $ConfirmEmail = self::requireConfirmEmail();
     $Confirmed = val('Confirmed', $User);
     if ($ConfirmEmail && !$Confirmed) {
         // Replace permissions with those of the ConfirmEmailRole
         $ConfirmEmailRoleID = RoleModel::getDefaultRoles(RoleModel::TYPE_UNCONFIRMED);
         if (!is_array($ConfirmEmailRoleID) || count($ConfirmEmailRoleID) == 0) {
             throw new Exception(sprintf(t('No role configured with a type of "%s".'), RoleModel::TYPE_UNCONFIRMED), 400);
         }
         $RoleModel = new RoleModel();
         $permissionsModel = new Vanilla\Permissions();
         $RolePermissions = $RoleModel->getPermissions($ConfirmEmailRoleID);
         $permissionsModel->compileAndLoad($RolePermissions);
         $Permissions = $permissionsModel->getPermissions();
         // Ensure Confirm Email role can always sign in
         if (!$Permissions->has('Garden.SignIn.Allow')) {
             $Permissions->set('Garden.SignIn.Allow', true);
         }
         $User->Permissions = $Permissions->getPermissions();
         // Otherwise normal loadings!
     } else {
         if ($User && ($User->Permissions == '' || Gdn::cache()->activeEnabled())) {
             $userPermissions = $this->getPermissions($UserID);
             $User->Permissions = $userPermissions->getPermissions();
         }
     }
     // Remove secret info from session
     unset($User->Password, $User->HashMethod);
     return $User;
 }
Example #2
0
 /**
  *
  *
  * @param $UserID
  * @param bool $Refresh
  * @return array|bool|null|object|type
  */
 public function getSession($UserID, $Refresh = false)
 {
     // Ask for the user. This will check cache first.
     $User = $this->getID($UserID, DATASET_TYPE_OBJECT);
     if (!$User) {
         return false;
     }
     // If we require confirmation and user is not confirmed
     $ConfirmEmail = self::requireConfirmEmail();
     $Confirmed = val('Confirmed', $User);
     if ($ConfirmEmail && !$Confirmed) {
         // Replace permissions with those of the ConfirmEmailRole
         $ConfirmEmailRoleID = RoleModel::getDefaultRoles(RoleModel::TYPE_UNCONFIRMED);
         $RoleModel = new RoleModel();
         $RolePermissions = $RoleModel->getPermissions($ConfirmEmailRoleID);
         $Permissions = UserModel::compilePermissions($RolePermissions);
         // Ensure Confirm Email role can always sign in
         if (!in_array('Garden.SignIn.Allow', $Permissions)) {
             $Permissions[] = 'Garden.SignIn.Allow';
         }
         $User->Permissions = $Permissions;
         // Otherwise normal loadings!
     } else {
         if ($User && ($User->Permissions == '' || Gdn::cache()->activeEnabled())) {
             $User->Permissions = $this->definePermissions($UserID);
         }
     }
     // Remove secret info from session
     unset($User->Password, $User->HashMethod);
     return $User;
 }