Exemple #1
0
 /**
  * Gets user roles by default base role (full or readOnly access)
  *
  * @param int|User $user User identifier or user object
  * @return AccountRoleSuperposition
  */
 public function getUserRoles($user)
 {
     $ret = new AccountRoleSuperposition([]);
     $ret->setUser($user);
     $role = $this->getAccountRole($this->accountRoleId);
     $ret[$role->getRoleId()] = $role;
     return $ret;
 }
Exemple #2
0
 /**
  * Gets account roles superposition by specified ID of team
  *
  * @param   \Scalr_Account_User|int  $userId       The user's object or ID of the user
  * @param   int                      $teamId       The ID of the team
  * @param   int                      $accountId    The ID of the client's account
  * @return  \Scalr\Acl\Role\AccountRoleSuperposition Returns the list of the roles of account level by specified team
  */
 public function getUserRolesByTeam($user, $teamId, $accountId)
 {
     $ret = new Role\AccountRoleSuperposition(array());
     if ($user instanceof \Scalr_Account_User) {
         $userId = $user->getId();
         $ret->setUser($user);
     } else {
         $userId = $user;
         $ret->setUser($userId);
     }
     $res = $this->db->Execute("\n            SELECT ar.*\n            FROM `acl_account_roles` ar\n            JOIN `account_team_user_acls` ua ON ua.`account_role_id` = ar.`account_role_id`\n            JOIN `account_team_users` atu ON atu.`id` = ua.`account_team_user_id`\n            WHERE atu.`user_id` = ? AND atu.`team_id` = ? AND ar.`account_id` = ?\n            GROUP BY ar.`account_role_id`\n        ", array($userId, $teamId, $accountId));
     while ($rec = $res->FetchRow()) {
         $role = $this->getAccountRoleByRow($rec);
         $role->setTeamRole(false);
         $ret[$role->getRoleId()] = $role;
     }
     if (!$ret->count()) {
         //User has no roles assigned to this team so we need to use default ACL role for the team
         $res = $this->db->Execute("\n                SELECT ar.*\n                FROM `acl_account_roles` ar\n                JOIN `account_teams` at ON at.account_role_id = ar.account_role_id\n                JOIN `account_team_users` atu ON at.`id` = atu.`team_id`\n                WHERE at.id = ? AND atu.user_id = ? AND at.account_id = ?\n            ", array($teamId, $userId, $accountId));
         while ($rec = $res->FetchRow()) {
             $role = $this->getAccountRoleByRow($rec);
             $role->setTeamRole(true);
             $ret[$role->getRoleId()] = $role;
         }
     }
     return $ret;
 }