Exemplo n.º 1
0
 public function removePermission(\thebuggenie\core\entities\RolePermission $permission)
 {
     $this->_populatePermissions();
     $permission_id = $permission->getID();
     unset($this->_permissions[$permission_id]);
     tables\Permissions::getTable()->deleteRolePermission($this->getID(), $permission->getPermission(), $permission->getExpandedTargetID($this));
     $permission->delete();
 }
Exemplo n.º 2
0
 public function addRolePermission(\thebuggenie\core\entities\Role $role, \thebuggenie\core\entities\RolePermission $rolepermission)
 {
     $role_id = $role->getID();
     $crit = $this->getCriteria();
     $crit->addWhere(self::ROLE_ID, $role_id);
     $existing_identifiables = array(self::UID => array(), self::TID => array());
     $target_id = $rolepermission->getExpandedTargetID($role);
     if ($res = $this->doSelect($crit)) {
         while ($row = $res->getNextRow()) {
             $key = $row->get(self::UID) ? self::UID : self::TID;
             if (!isset($existing_identifiables[$key][$row->get($key)])) {
                 $existing_identifiables[$key][$row->get($key)] = array('id' => $row->get($key), 'target_id' => $target_id, 'permission_type_module' => array());
             }
             $existing_identifiables[$key][$row->get($key)]['permission_type_module'][] = $row->get(self::PERMISSION_TYPE) . ';' . $row->get(self::MODULE);
         }
     }
     foreach (ProjectAssignedUsers::getTable()->getUsersByRoleID($role_id) as $uid => $assigned_user) {
         if (!isset($existing_identifiables[self::UID][$uid])) {
             $existing_identifiables[self::UID][$uid] = array('id' => $uid, 'target_id' => $target_id, 'permission_type_module' => array());
         }
     }
     foreach (ProjectAssignedTeams::getTable()->getTeamsByRoleID($role_id) as $tid => $assigned_team) {
         if (!isset($existing_identifiables[self::TID][$tid])) {
             $existing_identifiables[self::TID][$tid] = array('id' => $tid, 'target_id' => $target_id, 'permission_type_module' => array());
         }
     }
     foreach ($existing_identifiables as $key => $identifiables) {
         foreach ($identifiables as $identifiable) {
             if (in_array($rolepermission->getPermission() . ';' . $rolepermission->getModule(), $identifiable['permission_type_module'])) {
                 continue;
             }
             $crit = $this->getCriteria();
             $crit->addInsert(self::SCOPE, framework\Context::getScope()->getID());
             $crit->addInsert(self::PERMISSION_TYPE, $rolepermission->getPermission());
             $crit->addInsert(self::TARGET_ID, $identifiable['target_id']);
             $crit->addInsert($key, $identifiable['id']);
             $crit->addInsert(self::ALLOWED, true);
             $crit->addInsert(self::MODULE, $rolepermission->getModule());
             $crit->addInsert(self::ROLE_ID, $role_id);
             $res = $this->doInsert($crit);
         }
     }
 }