public static function loadFixtures(TBGScope $scope) { $scope_id = $scope->getID(); $admin_group = new TBGGroup(); $admin_group->setName('Administrators'); $admin_group->setScope($scope); $admin_group->save(); TBGSettings::saveSetting('admingroup', $admin_group->getID(), 'core', $scope_id); $user_group = new TBGGroup(); $user_group->setName('Regular users'); $user_group->setScope($scope); $user_group->save(); TBGSettings::saveSetting('defaultgroup', $user_group->getID(), 'core', $scope_id); $guest_group = new TBGGroup(); $guest_group->setName('Guests'); $guest_group->setScope($scope); $guest_group->save(); // Set up initial users, and their permissions if ($scope->isDefault()) { list($guestuser_id, $adminuser_id) = TBGUser::loadFixtures($scope, $admin_group, $user_group, $guest_group); TBGUserScopesTable::getTable()->addUserToScope($guestuser_id, $scope->getID(), $guest_group->getID(), true); TBGUserScopesTable::getTable()->addUserToScope($adminuser_id, $scope->getID(), $admin_group->getID(), true); } else { $default_scope_id = TBGSettings::getDefaultScopeID(); $default_user_id = (int) TBGSettings::get(TBGSettings::SETTING_DEFAULT_USER_ID, 'core', $default_scope_id); TBGUserScopesTable::getTable()->addUserToScope($default_user_id, $scope->getID(), $user_group->getID(), true); TBGUserScopesTable::getTable()->addUserToScope(1, $scope->getID(), $admin_group->getID()); TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_USER_ID, $default_user_id, 'core', $scope->getID()); } TBGPermissionsTable::getTable()->loadFixtures($scope, $admin_group->getID(), $guest_group->getID()); }
public static function loadFixtures(TBGScope $scope) { $scope_id = $scope->getID(); $admin_group = new TBGGroup(); $admin_group->setName('Administrators'); $admin_group->setScope($scope); $admin_group->save(); TBGSettings::saveSetting('admingroup', $admin_group->getID(), 'core', $scope_id); $user_group = new TBGGroup(); $user_group->setName('Regular users'); $user_group->setScope($scope); $user_group->save(); TBGSettings::saveSetting('defaultgroup', $user_group->getID(), 'core', $scope_id); $guest_group = new TBGGroup(); $guest_group->setName('Guests'); $guest_group->setScope($scope); $guest_group->save(); // Set up initial users, and their permissions TBGUser::loadFixtures($scope, $admin_group, $user_group, $guest_group); TBGPermissionsTable::getTable()->loadFixtures($scope, $admin_group->getID(), $guest_group->getID()); }
public function runAddTeam(TBGRequest $request) { try { $mode = $request->getParameter('mode'); if ($team_name = $request->getParameter('team_name')) { if ($mode == 'clone') { try { $old_team = TBGContext::factory()->TBGTeam($request->getParameter('team_id')); } catch (Exception $e) { } if (!$old_team instanceof TBGTeam) { throw new Exception(TBGContext::getI18n()->__("You cannot clone this team")); } } if (TBGTeam::doesTeamNameExist(trim($team_name))) { throw new Exception(TBGContext::getI18n()->__("Please enter a team name that doesn't already exist")); } $team = new TBGTeam(); $team->setName($team_name); $team->save(); if ($mode == 'clone') { if ($request->getParameter('clone_permissions')) { TBGPermissionsTable::getTable()->cloneTeamPermissions($old_team->getID(), $team->getID()); } if ($request->getParameter('clone_memberships')) { TBGTeamMembersTable::getTable()->cloneTeamMemberships($old_team->getID(), $team->getID()); } $message = TBGContext::getI18n()->__('The team was cloned'); } else { $message = TBGContext::getI18n()->__('The team was added'); } return $this->renderJSON(array('failed' => false, 'message' => $message, 'content' => $this->getTemplateHTML('configuration/teambox', array('team' => $team)), 'total_count' => TBGTeam::getTeamsCount(), 'more_available' => TBGContext::getScope()->hasTeamsAvailable())); } else { throw new Exception(TBGContext::getI18n()->__('Please enter a team name')); } } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage())); } }
public function addPermission(TBGRolePermission $permission) { $permission->setRole($this); $permission->save(); if ($this->_permissions !== null) { $this->_permissions[$permission->getID()] = $permission; } TBGPermissionsTable::getTable()->addRolePermission($this->getID(), $permission); }
/** * Unlock the issue * * @param TBGRequest $request */ public function runUnlockIssue(TBGRequest $request) { if ($issue_id = $request['issue_id']) { try { $issue = TBGContext::factory()->TBGIssue($issue_id); if (!$issue->canEditIssueDetails()) { return $this->forward403(); } $issue->setLocked(false); $issue->save(); TBGPermissionsTable::getTable()->deleteByPermissionTargetIDAndModule('canviewissue', $issue_id); } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('message' => TBGContext::getI18n()->__('This issue does not exist'))); } } else { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('message' => TBGContext::getI18n()->__('This issue does not exist'))); } return $this->renderJSON(array('message' => $this->getI18n()->__('Issue access policy updated'))); }
/** * Save a permission setting * * @param string $permission_type The permission type * @param mixed $target_id The target id * @param string $module The name of the module for which the permission is valid * @param integer $uid The user id for which the permission is valid, 0 for none * @param integer $gid The group id for which the permission is valid, 0 for none * @param integer $tid The team id for which the permission is valid, 0 for none * @param boolean $allowed Allowed or not * @param integer $scope[optional] A specified scope if not the default */ public static function setPermission($permission_type, $target_id, $module, $uid, $gid, $tid, $allowed, $scope = null) { if ($scope === null) { $scope = self::getScope()->getID(); } self::removePermission($permission_type, $target_id, $module, $uid, $gid, $tid, false, $scope); TBGPermissionsTable::getTable()->setPermission($uid, $gid, $tid, $allowed, $module, $permission_type, $target_id, $scope); self::cacheAllPermissions(); }
protected function _upgradeFrom3dot2(TBGRequest $request) { set_time_limit(0); TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'installation' . DS . 'classes' . DS . 'upgrade_3.2'); foreach (array('publish', 'mailing') as $module) { TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . $module . DS . 'classes'); TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . $module . DS . 'classes' . DS . 'B2DB'); } TBGMilestonesTable::getTable()->upgrade(TBGMilestonesTable3dot2::getTable()); TBGArticlesTable::getTable()->upgrade(TBGArticlesTable3dot2::getTable()); TBGProjectsTable::getTable()->upgrade(TBGProjectsTable3dot2::getTable()); TBGLogTable::getTable()->upgrade(TBGLogTable3dot2::getTable()); TBGUsersTable::getTable()->upgrade(TBGUsersTable3dot2::getTable()); TBGIssuesTable::getTable()->upgrade(TBGIssuesTable3dot2::getTable()); TBGWorkflowsTable::getTable()->upgrade(TBGWorkflowsTable3dot2::getTable()); TBGIncomingEmailAccountTable::getTable()->upgrade(TBGIncomingEmailAccountTable3dot2::getTable()); TBGIssueSpentTimesTable::getTable()->upgrade(TBGIssueSpentTimesTable3dot2::getTable()); TBGCommentsTable::getTable()->upgrade(TBGCommentsTable3dot2::getTable()); TBGSavedSearchesTable::getTable()->upgrade(TBGSavedSearchesTable3dot2::getTable()); TBGSettingsTable::getTable()->upgrade(TBGSettingsTable3dot2::getTable()); TBGNotificationsTable::getTable()->upgrade(TBGNotificationsTable3dot2::getTable()); TBGPermissionsTable::getTable()->upgrade(TBGPermissionsTable3dot2::getTable()); TBGUserArticlesTable::getTable()->create(); TBGApplicationPasswordsTable::getTable()->create(); TBGUserNotificationSettingsTable::getTable()->create(); $transaction = \b2db\Core::startTransaction(); // Upgrade user passwords switch ($request['upgrade_passwords']) { case 'manual': $password = $request['manul_password']; foreach (TBGUsersTable::getTable()->selectAll() as $user) { $user->setPassword($password); $user->save(); } break; case 'auto': $field = $request['upgrade_passwords_pick'] == 'username' ? 'username' : 'email'; foreach (TBGUsersTable::getTable()->selectAll() as $user) { if ($field == 'username' && trim($user->getUsername())) { $user->setPassword(trim($user->getUsername())); $user->save(); } elseif ($field == 'email' && trim($user->getEmail())) { $user->setPassword(trim($user->getEmail())); $user->save(); } } break; } $adminuser = TBGUsersTable::getTable()->selectById(1); $adminuser->setPassword($request['admin_password']); $adminuser->save(); // Add new settings TBGSettings::saveSetting(TBGSettings::SETTING_SERVER_TIMEZONE, 'core', date_default_timezone_get(), 0, 1); foreach ($request->getParameter('status') as $scope_id => $status_id) { $scope = TBGScopesTable::getTable()->selectById((int) $scope_id); if ($scope instanceof TBGScope) { foreach (TBGWorkflowsTable::getTable()->getAll((int) $scope_id) as $workflow) { $transition = new TBGWorkflowTransition(); $steps = $workflow->getSteps(); $step = array_shift($steps); $step->setLinkedStatusID((int) $status_id); $step->save(); $transition->setOutgoingStep($step); $transition->setName('Issue created'); $transition->setWorkflow($workflow); $transition->setScope($scope); $transition->setDescription('This is the initial transition for issues using this workflow'); $transition->save(); $workflow->setInitialTransition($transition); $workflow->save(); } TBGActivityType::loadFixtures($scope); } } $transaction->commitAndEnd(); TBGContext::finishUpgrading(); TBGContext::getModule('mailing')->upgradeFrom3dot2(); $this->upgrade_complete = true; }
public function getAccessList() { $permissions = TBGPermissionsTable::getTable()->getByPermissionTargetIDAndModule('canviewissue', $this->getID()); return $permissions; }