Esempio n. 1
0
 protected function _populateTeamRoles()
 {
     if ($this->_team_roles === null) {
         $this->_team_roles = tables\ProjectAssignedTeams::getTable()->getRolesForProject($this->getID());
     }
 }
Esempio n. 2
0
 protected static function _permissionsCheck($permissions, $uid, $gid, $tid, $permission_roles_allowed, $target_id)
 {
     try {
         if (!is_array($permission_roles_allowed)) {
             $permission_roles_allowed = array();
         }
         if ($uid != 0 || $gid != 0 || $tid != 0) {
             if ($uid != 0) {
                 $new_permission_roles_allowed = array();
                 foreach ($permissions as $key => $permission) {
                     if (!array_key_exists('uid', $permission)) {
                         foreach ($permission as $pkey => $pp) {
                             if ($pp['uid'] == $uid) {
                                 if ($pp['role_id'] == 0) {
                                     return $pp['allowed'];
                                 }
                                 $new_permission_roles_allowed[] = $pp;
                             }
                         }
                     } elseif ($permission['uid'] == $uid) {
                         if ($permission['role_id'] == 0) {
                             return $permission['allowed'];
                         }
                         $new_permission_roles_allowed[] = $permission;
                     }
                 }
                 if (count($new_permission_roles_allowed)) {
                     return array_merge($permission_roles_allowed, $new_permission_roles_allowed);
                 }
             }
             if (is_array($tid) || $tid != 0) {
                 $new_permission_roles_allowed = array();
                 foreach ($permissions as $key => $permission) {
                     if (!array_key_exists('tid', $permission)) {
                         foreach ($permission as $pkey => $pp) {
                             if (is_array($tid) && in_array($pp['tid'], array_keys($tid)) || $pp['tid'] == $tid) {
                                 if ($pp['role_id'] == 0) {
                                     return $pp['allowed'];
                                 }
                                 if ($target_id == 0 && self::getCurrentProject() instanceof \thebuggenie\core\entities\Project) {
                                     $target_id = self::getCurrentProject()->getID();
                                 }
                                 if ($target_id != 0) {
                                     $role_assigned_teams = \thebuggenie\core\entities\tables\ProjectAssignedTeams::getTable()->getTeamsByRoleIDAndProjectID($pp['role_id'], $target_id);
                                     if (is_array($tid)) {
                                         foreach ($tid as $team) {
                                             if (array_key_exists($team->getID(), $role_assigned_teams)) {
                                                 $new_permission_roles_allowed[] = $pp;
                                                 break;
                                             }
                                         }
                                     } else {
                                         if (array_key_exists($tid, $role_assigned_teams)) {
                                             $new_permission_roles_allowed[] = $pp;
                                         }
                                     }
                                 } else {
                                     $new_permission_roles_allowed[] = $pp;
                                 }
                             }
                         }
                     } elseif (is_array($tid) && in_array($permission['tid'], array_keys($tid)) || $permission['tid'] == $tid) {
                         if ($permission['role_id'] == 0) {
                             return $permission['allowed'];
                         }
                         if ($target_id == 0 && self::getCurrentProject() instanceof \thebuggenie\core\entities\Project) {
                             $target_id = self::getCurrentProject()->getID();
                         }
                         if ($target_id != 0) {
                             $role_assigned_teams = \thebuggenie\core\entities\tables\ProjectAssignedTeams::getTable()->getTeamsByRoleIDAndProjectID($permission['role_id'], $target_id);
                             if (is_array($tid)) {
                                 foreach ($tid as $team) {
                                     if (array_key_exists($team->getID(), $role_assigned_teams)) {
                                         $new_permission_roles_allowed[] = $permission;
                                         break;
                                     }
                                 }
                             } else {
                                 if (array_key_exists($tid, $role_assigned_teams)) {
                                     $new_permission_roles_allowed[] = $permission;
                                 }
                             }
                         } else {
                             $new_permission_roles_allowed[] = $permission;
                         }
                     }
                 }
                 if (count($new_permission_roles_allowed)) {
                     return array_merge($permission_roles_allowed, $new_permission_roles_allowed);
                 }
             }
             if ($gid != 0) {
                 $new_permission_roles_allowed = array();
                 foreach ($permissions as $key => $permission) {
                     if (!array_key_exists('gid', $permission)) {
                         foreach ($permission as $pkey => $pp) {
                             if ($pp['gid'] == $gid) {
                                 if ($pp['role_id'] == 0) {
                                     return $pp['allowed'];
                                 }
                                 $new_permission_roles_allowed[] = 1;
                             }
                         }
                     } elseif ($permission['gid'] == $gid) {
                         if ($permission['role_id'] == 0) {
                             return $permission['allowed'];
                         }
                         $new_permission_roles_allowed[] = 1;
                     }
                 }
                 if (count($new_permission_roles_allowed)) {
                     return array_merge($permission_roles_allowed, $new_permission_roles_allowed);
                 }
             }
         }
         $new_permission_roles_allowed = array();
         foreach ($permissions as $key => $permission) {
             if (!array_key_exists('uid', $permission)) {
                 foreach ($permission as $pkey => $pp) {
                     if ($pp['uid'] + $pp['gid'] + $pp['tid'] == 0) {
                         if ($pp['role_id'] == 0) {
                             return $pp['allowed'];
                         }
                         $new_permission_roles_allowed[] = 1;
                     }
                 }
             } elseif ($permission['uid'] + $permission['gid'] + $permission['tid'] == 0) {
                 if ($permission['role_id'] == 0) {
                     return $permission['allowed'];
                 }
                 $new_permission_roles_allowed[] = 1;
             }
         }
         if (count($new_permission_roles_allowed)) {
             return array_merge($permission_roles_allowed, $new_permission_roles_allowed);
         }
     } catch (\Exception $e) {
     }
     return null;
 }
Esempio n. 3
0
 protected function _preDelete()
 {
     tables\RolePermissions::getTable()->clearPermissionsForRole($this->getID());
     tables\ProjectAssignedTeams::getTable()->deleteByRoleID($this->getID());
     tables\ProjectAssignedUsers::getTable()->deleteByRoleID($this->getID());
 }
Esempio n. 4
0
 /**
  * Get all the projects a team is associated with
  *
  * @return array
  */
 public function getAssociatedProjects()
 {
     if ($this->_associated_projects === null) {
         $this->_associated_projects = array();
         $project_ids = tables\ProjectAssignedTeams::getTable()->getProjectsByTeamID($this->getID());
         foreach ($project_ids as $project_id) {
             $this->_associated_projects[$project_id] = \thebuggenie\core\entities\Project::getB2DBTable()->selectById($project_id);
         }
     }
     return $this->_associated_projects;
 }
Esempio n. 5
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);
         }
     }
 }