Esempio n. 1
0
 public static function loadFixtures(\thebuggenie\core\entities\Scope $scope)
 {
     Category::loadFixtures($scope);
     Priority::loadFixtures($scope);
     Reproducability::loadFixtures($scope);
     Resolution::loadFixtures($scope);
     Severity::loadFixtures($scope);
     Status::loadFixtures($scope);
     Role::loadFixtures($scope);
     ActivityType::loadFixtures($scope);
     foreach (self::getTypes() as $type => $class) {
         framework\Context::setPermission('set_datatype_' . $type, 0, 'core', 0, 0, 0, true, $scope->getID());
     }
 }
Esempio n. 2
0
 public function getExpandedTargetID(Role $role)
 {
     $project = $role->getProject();
     return $this->hasTargetID() ? $project instanceof Project && !$role->isSystemRole() ? $this->getReplacedTargetID($project) : ($role->isSystemRole() ? '0' : $role->getItemdata()) : ($role->isSystemRole() ? '0' : $role->getItemdata());
 }
Esempio n. 3
0
 /**
  * Adds an assignee with a given role
  *
  * @param \thebuggenie\core\entities\common\Identifiable $assignee The user or team to add
  * @param Role $role The role to add
  *
  * @return null
  */
 public function addAssignee($assignee, $role = null)
 {
     $user_id = 0;
     $team_id = 0;
     if ($assignee instanceof \thebuggenie\core\entities\User) {
         $user_id = $assignee->getID();
         if (tables\ProjectAssignedUsers::getTable()->addUserToProject($this->getID(), $user_id, $role->getID()) && is_array($this->_assigned_users)) {
             $this->_assigned_users = array_merge($this->_assigned_users, tables\ProjectAssignedUsers::getTable()->getUserByProjectIDUserIDRoleID($this->getID(), $user_id, $role->getID()));
         }
     } elseif ($assignee instanceof \thebuggenie\core\entities\Team) {
         $team_id = $assignee->getID();
         if (tables\ProjectAssignedTeams::getTable()->addTeamToProject($this->getID(), $team_id, $role->getID()) && is_array($this->_assigned_users)) {
             $this->_assigned_teams = array_merge($this->_assigned_teams, tables\ProjectAssignedTeams::getTable()->getTeamByProjectIDTeamIDRoleID($this->getID(), $team_id, $role->getID()));
         }
     }
     if ($role instanceof \thebuggenie\core\entities\Role) {
         $role_id = $role->getID();
         foreach ($role->getPermissions() as $role_permission) {
             $target_id = strtolower($role_permission->getExpandedTargetID($role));
             tables\Permissions::getTable()->removeSavedPermission($user_id, 0, $team_id, $role_permission->getModule(), $role_permission->getPermission(), $target_id, framework\Context::getScope()->getID(), $role_id);
             framework\Context::setPermission($role_permission->getPermission(), $target_id, $role_permission->getModule(), $user_id, 0, $team_id, true, null, $role_id);
         }
     }
 }
Esempio n. 4
0
 public function runAddRole(framework\Request $request)
 {
     if ($this->getUser()->canManageProject($this->selected_project)) {
         if ($request['role_name']) {
             $role = new entities\Role();
             $role->setName($request['role_name']);
             $role->setProject($this->selected_project);
             $role->save();
             return $this->renderJSON(array('content' => $this->getComponentHTML('configuration/role', array('role' => $role))));
         }
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('message' => $this->getI18n()->__('You must provide a role name')));
     }
     $this->getResponse()->setHttpStatus(400);
     return $this->renderJSON(array('message' => $this->getI18n()->__('You do not have access to create new project roles')));
 }
Esempio n. 5
0
 public function runConfigureRoles(framework\Request $request)
 {
     if ($request->isPost()) {
         if (trim($request['role_name']) == '') {
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => $this->getI18n()->__('You have to specify a name for this role')));
         }
         $role = new entities\Role();
         $role->setName($request['role_name']);
         $role->save();
         return $this->renderJSON(array('content' => $this->getComponentHTML('configuration/role', array('role' => $role))));
     }
     $this->roles = entities\Role::getAll();
 }
Esempio n. 6
0
 public function componentProjectPermissions()
 {
     $this->roles = entities\Role::getAll();
     $this->project_roles = entities\Role::getByProjectID($this->project->getID());
 }
Esempio n. 7
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);
         }
     }
 }
Esempio n. 8
0
 /**
  * Configuration import page
  *
  * @param framework\Request $request
  */
 public function runIndex(framework\Request $request)
 {
     if ($request->isPost()) {
         if ($request['import_sample_data']) {
             $transaction = \b2db\Core::startTransaction();
             $users = array();
             $user1 = new entities\User();
             $user1->setUsername('john');
             $user1->setPassword('john');
             $user1->setBuddyname('John');
             $user1->setRealname('John');
             $user1->setActivated();
             $user1->setEnabled();
             $user1->save();
             $users[] = $user1;
             $user2 = new entities\User();
             $user2->setUsername('jane');
             $user2->setPassword('jane');
             $user2->setBuddyname('Jane');
             $user2->setRealname('Jane');
             $user2->setActivated();
             $user2->setEnabled();
             $user2->save();
             $users[] = $user2;
             $user3 = new entities\User();
             $user3->setUsername('jackdaniels');
             $user3->setPassword('jackdaniels');
             $user3->setBuddyname('Jack');
             $user3->setRealname('Jack Daniels');
             $user3->setActivated();
             $user3->setEnabled();
             $user3->save();
             $users[] = $user3;
             $project1 = new entities\Project();
             $project1->setName('Sample project 1');
             $project1->setOwner($users[rand(0, 2)]);
             $project1->setLeader($users[rand(0, 2)]);
             $project1->setQaResponsible($users[rand(0, 2)]);
             $project1->setDescription('This is a sample project that is awesome. Try it out!');
             $project1->setHomepage('http://www.google.com');
             $project1->save();
             $project2 = new entities\Project();
             $project2->setName('Sample project 2');
             $project2->setOwner($users[rand(0, 2)]);
             $project2->setLeader($users[rand(0, 2)]);
             $project2->setQaResponsible($users[rand(0, 2)]);
             $project2->setDescription('This is the second sample project. Not as awesome as the first one, but still worth a try!');
             $project2->setHomepage('http://www.bing.com');
             $project2->save();
             foreach (array($project1, $project2) as $project) {
                 for ($cc = 1; $cc <= 5; $cc++) {
                     $milestone = new entities\Milestone();
                     $milestone->setName("Milestone {$cc}");
                     $milestone->setProject($project);
                     $milestone->setType(entities\Milestone::TYPE_REGULAR);
                     if ((bool) rand(0, 1)) {
                         $milestone->setScheduledDate(NOW + 100000 * (20 * $cc));
                     }
                     $milestone->save();
                 }
             }
             $p1_milestones = $project1->getMilestones();
             $p2_milestones = $project2->getMilestones();
             $issues = array();
             $priorities = entities\Priority::getAll();
             $categories = entities\Category::getAll();
             $severities = entities\Severity::getAll();
             $statuses = entities\Status::getAll();
             $reproducabilities = entities\Reproducability::getAll();
             $lorem_ipsum = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->getArticleByName('LoremIpsum');
             $lorem_words = explode(' ', $lorem_ipsum->getContent());
             foreach (array('bugreport', 'featurerequest', 'enhancement', 'idea') as $issuetype) {
                 $issuetype = entities\Issuetype::getByKeyish($issuetype);
                 for ($cc = 1; $cc <= 10; $cc++) {
                     $issue1 = new entities\Issue();
                     $issue1->setProject($project1);
                     $issue1->setPostedBy($users[rand(0, 2)]);
                     $issue1->setPosted(NOW - 86400 * rand(1, 30));
                     $title_string = '';
                     $description_string = '';
                     $rand_length = rand(4, 15);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $title_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $title_string .= '.';
                             $ucnext = true;
                         }
                         $title_string .= ' ';
                     }
                     $rand_length = rand(40, 500);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $description_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $description_string .= '.';
                             $ucnext = true;
                             $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' ';
                         } else {
                             $description_string .= ' ';
                         }
                     }
                     $issue1->setTitle(ucfirst($title_string));
                     $issue1->setDescription($description_string);
                     $issue1->setIssuetype($issuetype);
                     $issue1->setMilestone($p1_milestones[array_rand($p1_milestones)]);
                     $issue1->setPriority($priorities[array_rand($priorities)]);
                     $issue1->setCategory($categories[array_rand($categories)]);
                     $issue1->setSeverity($severities[array_rand($severities)]);
                     $issue1->setReproducability($reproducabilities[array_rand($reproducabilities)]);
                     $issue1->setPercentCompleted(rand(0, 100));
                     $issue1->save();
                     $issue1->setStatus($statuses[array_rand($statuses)]);
                     if (rand(0, 1)) {
                         $issue1->setAssignee($users[array_rand($users)]);
                     }
                     $issue1->save();
                     $issues[] = $issue1;
                     $issue2 = new entities\Issue();
                     $issue2->setProject($project2);
                     $issue2->setPostedBy($users[rand(0, 2)]);
                     $issue2->setPosted(NOW - 86400 * rand(1, 30));
                     $title_string = '';
                     $description_string = '';
                     $rand_length = rand(4, 15);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $title_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $title_string .= '.';
                             $ucnext = true;
                         }
                         $title_string .= ' ';
                     }
                     $rand_length = rand(40, 500);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $description_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $description_string .= '.';
                             $ucnext = true;
                             $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' ';
                         } else {
                             $description_string .= ' ';
                         }
                     }
                     $issue2->setTitle(ucfirst($title_string));
                     $issue2->setDescription($description_string);
                     $issue2->setIssuetype($issuetype);
                     $issue2->setMilestone($p2_milestones[array_rand($p2_milestones)]);
                     $issue2->setPriority($priorities[array_rand($priorities)]);
                     $issue2->setCategory($categories[array_rand($categories)]);
                     $issue2->setSeverity($severities[array_rand($severities)]);
                     $issue2->setReproducability($reproducabilities[array_rand($reproducabilities)]);
                     $issue2->setPercentCompleted(rand(0, 100));
                     if (rand(0, 1)) {
                         $issue1->setAssignee($users[array_rand($users)]);
                     }
                     $issue2->save();
                     $issue2->setStatus($statuses[array_rand($statuses)]);
                     $issue2->save();
                     $issues[] = $issue2;
                 }
             }
             $rand_issues_to_close = rand(8, 40);
             $resolutions = entities\Resolution::getAll();
             for ($cc = 1; $cc <= $rand_issues_to_close; $cc++) {
                 $issue = array_slice($issues, array_rand($issues), 1);
                 $issue = $issue[0];
                 $issue->setResolution($resolutions[array_rand($resolutions)]);
                 $issue->close();
                 $issue->save();
             }
             $this->imported_data = true;
             $roles = entities\Role::getAll();
             foreach (array($project1, $project2) as $project) {
                 foreach ($users as $user) {
                     $project->addAssignee($user, $roles[array_rand($roles)]);
                 }
             }
             $transaction->commitAndEnd();
         }
     }
     $project1 = entities\Project::getByKey('sampleproject1');
     $project2 = entities\Project::getByKey('sampleproject2');
     $this->canimport = !$project1 instanceof entities\Project && !$project2 instanceof entities\Project;
 }
Esempio n. 9
0
 /**
  * Adds an assignee with a given role
  *
  * @param \thebuggenie\core\entities\common\Identifiable $assignee The user or team to add
  * @param Role $role The role to add
  *
  * @return null
  */
 public function addAssignee($assignee, $role = null)
 {
     $user_id = 0;
     $team_id = 0;
     if ($assignee instanceof \thebuggenie\core\entities\User) {
         $user_id = $assignee->getID();
         tables\ProjectAssignedUsers::getTable()->addUserToProject($this->getID(), $user_id, $role->getID());
     } elseif ($assignee instanceof \thebuggenie\core\entities\Team) {
         $team_id = $assignee->getID();
         tables\ProjectAssignedTeams::getTable()->addTeamToProject($this->getID(), $team_id, $role->getID());
     }
     if ($role instanceof \thebuggenie\core\entities\Role) {
         foreach ($role->getPermissions() as $role_permission) {
             $target_id = $role_permission->hasTargetID() ? $role_permission->getReplacedTargetID($this) : $this->getID();
             framework\Context::setPermission($role_permission->getPermission(), $target_id, $role_permission->getModule(), $user_id, 0, $team_id, true, null, $role->getID());
         }
     }
 }