コード例 #1
0
 public function postConfigSettings(TBGRequest $request)
 {
     $settings = array('use_web_interface', 'vcs_passkey');
     foreach ($settings as $setting) {
         if ($request->hasParameter($setting)) {
             $this->saveSetting($setting, $request->getParameter($setting));
         }
     }
     foreach (TBGProject::getAll() as $aProduct) {
         if ($request->hasParameter('web_path_' . $aProduct->getID())) {
             // github is always at github.com
             if ($request->hasParameter('web_type_' . $aProduct->getID()) && $request->getParameter('web_type_' . $aProduct->getID()) == 'github') {
                 $this->saveSetting('web_path_' . $aProduct->getID(), 'http://github.com');
             } else {
                 $this->saveSetting('web_path_' . $aProduct->getID(), $request->getParameter('web_path_' . $aProduct->getID()));
             }
         }
         if ($request->hasParameter('web_type_' . $aProduct->getID())) {
             $this->saveSetting('web_type_' . $aProduct->getID(), $request->getParameter('web_type_' . $aProduct->getID()));
         }
         if ($request->hasParameter('web_repo_' . $aProduct->getID())) {
             $this->saveSetting('web_repo_' . $aProduct->getID(), $request->getParameter('web_repo_' . $aProduct->getID()));
         }
     }
 }
コード例 #2
0
 public function postConfigSettings(TBGRequest $request)
 {
     $settings = array('hostname', 'u_type', 'g_type', 'b_dn', 'groups', 'dn_attr', 'u_attr', 'g_attr', 'e_attr', 'f_attr', 'b_attr', 'g_dn', 'control_user', 'control_pass', 'integrated_auth', 'integrated_auth_header');
     foreach ($settings as $setting) {
         if (($setting == 'u_type' || $setting == 'g_type' || $setting == 'dn_attr') && $request->getParameter($setting) == '') {
             if ($setting == 'u_type') {
                 $this->saveSetting($setting, 'person');
             } elseif ($setting == 'g_type') {
                 $this->saveSetting($setting, 'group');
             } else {
                 $this->saveSetting($setting, 'entrydn');
             }
         } elseif ($setting == 'integrated_auth') {
             $this->saveSetting($setting, (int) $request->getParameter($setting, 0));
         } else {
             if ($request->hasParameter($setting)) {
                 $this->saveSetting($setting, $request->getParameter($setting));
             }
         }
     }
 }
コード例 #3
0
 public function runConfigureWorkflowTransition(TBGRequest $request)
 {
     $this->workflow = null;
     $this->transition = null;
     try {
         $this->workflow = TBGContext::factory()->TBGWorkflow($request->getParameter('workflow_id'));
         if ($request->hasParameter('transition_id')) {
             $mode = $request->getParameter('mode');
             $this->transition = TBGContext::factory()->TBGWorkflowTransition($request->getParameter('transition_id'));
             if ($request->isMethod(TBGRequest::POST)) {
                 if ($mode == 'delete') {
                     $this->transition->deleteTransition($request->getParameter('direction'));
                     return $this->renderJSON(array('failed' => false));
                 } elseif ($mode == 'delete_action') {
                     $this->action = TBGContext::factory()->TBGWorkflowTransitionAction($request->getParameter('action_id'));
                     $this->action->delete();
                     return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('The action has been deleted')));
                 } elseif ($mode == 'new_action') {
                     $action = new TBGWorkflowTransitionAction();
                     $action->setActionType($request->getParameter('action_type'));
                     $action->setTransition($this->transition);
                     $action->setWorkflow($this->workflow);
                     $action->setTargetValue('');
                     $action->save();
                     return $this->renderJSON(array('failed' => false, 'content' => $this->getComponentHTML('configuration/workflowtransitionaction', array('action' => $action))));
                 } elseif ($mode == 'update_action') {
                     $this->action = TBGContext::factory()->TBGWorkflowTransitionAction($request->getParameter('action_id'));
                     $this->action->setTargetValue($request->getParameter('target_value'));
                     $this->action->save();
                     $text = $request->getParameter('target_value');
                     switch ($this->action->getActionType()) {
                         case TBGWorkflowTransitionAction::ACTION_ASSIGN_ISSUE:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGUser((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('User specified during transition');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_RESOLUTION:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGResolution((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('Resolution specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_REPRODUCABILITY:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGReproducability((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('Reproducability specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_STATUS:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGStatus((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('Status specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_MILESTONE:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGMilestone((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('Milestone specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_PRIORITY:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGPriority((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('Priority specified by user');
                             break;
                     }
                     return $this->renderJSON(array('failed' => false, 'content' => $text));
                 } elseif ($mode == 'delete_validation_rule') {
                     $this->rule = TBGContext::factory()->TBGWorkflowTransitionValidationRule($request->getParameter('rule_id'));
                     $this->rule->delete();
                     return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('The validation rule has been deleted')));
                 } elseif ($mode == 'new_validation_rule') {
                     $rule = new TBGWorkflowTransitionValidationRule();
                     if ($request->getParameter('postorpre') == 'post') {
                         $exists = (bool) $this->transition->hasPostValidationRule($request->getParameter('rule'));
                         if (!$exists) {
                             $rule->setPost();
                         }
                     } elseif ($request->getParameter('postorpre') == 'pre') {
                         $exists = (bool) $this->transition->hasPreValidationRule($request->getParameter('rule'));
                         if (!$exists) {
                             $rule->setPre();
                         }
                     }
                     if ($exists) {
                         $this->getResponse()->setHttpStatus(400);
                         return $this->renderJSON(array('failed' => true, 'message' => TBGContext::getI18n()->__('This validation rule already exist')));
                     }
                     $rule->setRule($request->getParameter('rule'));
                     $rule->setRuleValue('');
                     $rule->setTransition($this->transition);
                     $rule->setWorkflow($this->workflow);
                     $rule->save();
                     return $this->renderJSON(array('failed' => false, 'content' => $this->getTemplateHTML('configuration/workflowtransitionvalidationrule', array('rule' => $rule))));
                 } elseif ($mode == 'update_validation_rule') {
                     $this->rule = TBGContext::factory()->TBGWorkflowTransitionValidationRule($request->getParameter('rule_id'));
                     $text = null;
                     switch ($this->rule->getRule()) {
                         case TBGWorkflowTransitionValidationRule::RULE_MAX_ASSIGNED_ISSUES:
                             $this->rule->setRuleValue($request->getParameter('rule_value'));
                             $text = $this->rule->getRuleValue() ? $this->rule->getRuleValue() : TBGContext::getI18n()->__('Unlimited');
                             break;
                         case TBGWorkflowTransitionValidationRule::RULE_PRIORITY_VALID:
                         case TBGWorkflowTransitionValidationRule::RULE_REPRODUCABILITY_VALID:
                         case TBGWorkflowTransitionValidationRule::RULE_RESOLUTION_VALID:
                         case TBGWorkflowTransitionValidationRule::RULE_STATUS_VALID:
                             $this->rule->setRuleValue(join(',', $request->getParameter('rule_value')));
                             $text = $this->rule->getRuleValue() ? $this->rule->getRuleValueAsJoinedString() : TBGContext::getI18n()->__('Any valid value');
                             break;
                             //case TBGWorkflowTransitionValidationRule::RULE_:
                             //	$text = ($this->rule->getRuleValue()) ? $this->rule->getRuleValue() : TBGContext::getI18n()->__('Unlimited');
                             //	break;
                     }
                     $this->rule->save();
                     return $this->renderJSON(array('failed' => false, 'content' => $text));
                 } elseif ($request->getParameter('transition_name') && $request->getParameter('outgoing_step_id') && $request->hasParameter('template')) {
                     $this->transition->setName($request->getParameter('transition_name'));
                     $this->transition->setDescription($request->getParameter('transition_description'));
                     if ($request->getParameter('template')) {
                         $this->transition->setTemplate($request->getParameter('template'));
                     } else {
                         $this->transition->setTemplate(null);
                     }
                     try {
                         $step = TBGContext::factory()->TBGWorkflowStep($request->getParameter('outgoing_step_id'));
                     } catch (Exception $e) {
                     }
                     $this->transition->setOutgoingStep($step);
                     $this->transition->save();
                     $transition = $this->transition;
                     $redirect_transition = true;
                 }
             }
         } elseif ($request->isMethod(TBGRequest::POST) && $request->hasParameter('step_id')) {
             $step = TBGContext::factory()->TBGWorkflowStep($request->getParameter('step_id'));
             /*if ($step->isCore() || $workflow->isCore())
             		{
             			throw new InvalidArgumentException("The default workflow cannot be edited");
             		}*/
             if ($request->getParameter('add_transition_type') == 'existing' && $request->hasParameter('existing_transition_id')) {
                 $transition = TBGContext::factory()->TBGWorkflowTransition($request->getParameter('existing_transition_id'));
                 $redirect_transition = false;
             } else {
                 if ($request->getParameter('transition_name') && $request->getParameter('outgoing_step_id') && $request->hasParameter('template')) {
                     if (($outgoing_step = TBGContext::factory()->TBGWorkflowStep((int) $request->getParameter('outgoing_step_id'))) && $step instanceof TBGWorkflowStep) {
                         if (array_key_exists($request->getParameter('template'), TBGWorkflowTransition::getTemplates())) {
                             $transition = new TBGWorkflowTransition();
                             $transition->setWorkflow($this->workflow);
                             $transition->setName($request->getParameter('transition_name'));
                             $transition->setDescription($request->getParameter('transition_description'));
                             $transition->setOutgoingStep($outgoing_step);
                             $transition->setTemplate($request->getParameter('template'));
                             $transition->save();
                             $step->addOutgoingTransition($transition);
                             $redirect_transition = true;
                         } else {
                             throw new InvalidArgumentException(TBGContext::getI18n()->__('Please select a valid template'));
                         }
                     } else {
                         throw new InvalidArgumentException(TBGContext::getI18n()->__('Please select a valid outgoing step'));
                     }
                 } else {
                     throw new InvalidArgumentException(TBGContext::getI18n()->__('Please fill in all required fields'));
                 }
             }
             $step->addOutgoingTransition($transition);
         } else {
             throw new InvalidArgumentException('Invalid action');
         }
     } catch (InvalidArgumentException $e) {
         //throw $e;
         $this->error = $e->getMessage();
     } catch (Exception $e) {
         throw $e;
         $this->error = TBGContext::getI18n()->__('This workflow / transition does not exist');
     }
     if (isset($redirect_transition) && $redirect_transition) {
         $this->forward(TBGContext::getRouting()->generate('configure_workflow_transition', array('workflow_id' => $this->workflow->getID(), 'transition_id' => $transition->getID())));
     } elseif (isset($redirect_transition)) {
         $this->forward(TBGContext::getRouting()->generate('configure_workflow_steps', array('workflow_id' => $this->workflow->getID())));
     }
 }
コード例 #4
0
 public function isValid(TBGRequest $request)
 {
     if ($this->_target_value) {
         return true;
     }
     switch ($this->_action_type) {
         case self::ACTION_ASSIGN_ISSUE:
             return (bool) $request['assignee_type'] && $request['assignee_id'];
             break;
         case self::ACTION_SET_MILESTONE:
             return (bool) $request->hasParameter('milestone_id');
             break;
         case self::ACTION_SET_PRIORITY:
             return (bool) $request->hasParameter('priority_id');
             break;
         case self::ACTION_SET_STATUS:
             return (bool) $request->hasParameter('status_id');
             break;
         case self::ACTION_SET_REPRODUCABILITY:
             return (bool) $request->hasParameter('reproducability_id');
             break;
         case self::ACTION_SET_RESOLUTION:
             return (bool) $request->hasParameter('resolution_id');
             break;
         default:
             return true;
     }
 }
コード例 #5
0
ファイル: actions.class.php プロジェクト: oparoz/thebuggenie
 public function runConfigureProjectEdition(TBGRequest $request)
 {
     if ($this->getUser()->canManageProject($this->selected_project) || $this->getUser()->canManageProjectReleases($this->selected_project)) {
         try {
             if ($edition_id = $request['edition_id']) {
                 $edition = TBGContext::factory()->TBGEdition($edition_id);
                 if ($request->isPost()) {
                     if ($request->hasParameter('release_month') && $request->hasParameter('release_day') && $request->hasParameter('release_year')) {
                         $release_date = mktime(0, 0, 1, $request['release_month'], $request['release_day'], $request['release_year']);
                         $edition->setReleaseDate($release_date);
                     }
                     if (($e_name = $request['edition_name']) && trim($e_name) != '') {
                         if ($e_name != $edition->getName()) {
                             if (in_array($e_name, $edition->getProject()->getEditions())) {
                                 throw new Exception(TBGContext::getI18n()->__('This edition already exists for this project'));
                             }
                             $edition->setName($e_name);
                         }
                     } else {
                         throw new Exception(TBGContext::getI18n()->__('You need to specify a name for this edition'));
                     }
                     $edition->setDescription($request->getParameter('description', null, false));
                     $edition->setDocumentationURL($request['doc_url']);
                     $edition->setReleased((int) $request['released']);
                     $edition->setLocked((bool) $request['locked']);
                     $edition->save();
                     return $this->renderJSON(array('edition_name' => $edition->getName(), 'message' => TBGContext::getI18n()->__('Edition details saved')));
                 } else {
                     switch ($request['mode']) {
                         case 'releases':
                         case 'components':
                             $this->selected_section = $request['mode'];
                             break;
                         default:
                             $this->selected_section = 'general';
                     }
                     $content = $this->getComponentHTML('project/projectedition', array('edition' => $edition, 'access_level' => $this->access_level, 'selected_section' => $this->selected_section));
                     return $this->renderJSON(array('content' => $content));
                 }
             } else {
                 throw new Exception(TBGContext::getI18n()->__('Invalid edition id'));
             }
         } catch (Exception $e) {
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => $e->getMessage()));
         }
     }
     $this->getResponse()->setHttpStatus(400);
     return $this->renderJSON(array("error" => $this->getI18n()->__("You don't have access to modify edition")));
 }
コード例 #6
0
 public function postConfigSettings(TBGRequest $request)
 {
     if ($request->hasParameter('import_articles')) {
         $cc = 0;
         foreach ($request->getParameter('import_article') as $article_name => $import) {
             $cc++;
             TBGArticlesTable::getTable()->deleteArticleByName(urldecode($article_name));
             $content = file_get_contents(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'fixtures' . DS . $article_name);
             TBGWikiArticle::createNew(urldecode($article_name), $content, true, null, array('overwrite' => true, 'noauthor' => true));
         }
         TBGContext::setMessage('module_message', TBGContext::getI18n()->__('%number_of_articles% articles imported successfully', array('%number_of_articles%' => $cc)));
     } else {
         $settings = array('allow_camelcase_links', 'menu_title', 'hide_wiki_links', 'free_edit');
         foreach ($settings as $setting) {
             if ($request->hasParameter($setting)) {
                 $this->saveSetting($setting, $request->getParameter($setting));
             }
         }
     }
 }
コード例 #7
0
 public function runGetMilestoneDetails(TBGRequest $request)
 {
     try {
         $i18n = TBGContext::getI18n();
         if ($request->hasParameter('milestone_id')) {
             $milestone = TBGContext::factory()->TBGMilestone($request->getParameter('milestone_id'));
             $milestone->updateStatus();
             $details = array('failed' => false);
             $details['percent'] = $milestone->getPercentComplete();
             $details['date_string'] = $milestone->getDateString();
             if ($milestone->isSprint()) {
                 $details['closed_points'] = $milestone->getPointsSpent();
                 $details['assigned_points'] = $milestone->getPointsEstimated();
             }
             $details['closed_issues'] = $milestone->countClosedIssues();
             $details['assigned_issues'] = $milestone->countIssues();
             return $this->renderJSON($details);
         } else {
             throw new Exception($i18n->__('Invalid milestone'));
         }
     } catch (Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage()));
     }
 }
コード例 #8
0
 protected function doSearch(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     if ($this->searchterm) {
         preg_replace_callback(TBGTextParser::getIssueRegex(), array($this, 'extractIssues'), $this->searchterm);
         if (!count($this->foundissues)) {
             $issue = TBGIssue::getIssueFromLink($this->searchterm);
             if ($issue instanceof TBGIssue) {
                 $this->foundissues = array($issue);
                 $this->resultcount = 1;
             }
         }
     }
     if (count($this->foundissues) == 0) {
         if ($request->hasParameter('predefined_search')) {
             switch ((int) $request->getParameter('predefined_search')) {
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_OPEN_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_CLOSED_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_CLOSED);
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_MILESTONE_TODO:
                     $this->groupby = 'milestone';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_PROJECT_MOST_VOTED:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->groupby = 'votes';
                     $this->grouporder = 'desc';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_MY_REPORTED_ISSUES:
                     $this->filters['posted_by'] = array('operator' => '=', 'value' => TBGContext::getUser()->getID());
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_MY_ASSIGNED_OPEN_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->filters['assigned_type'] = array('operator' => '=', 'value' => TBGIdentifiableClass::TYPE_USER);
                     $this->filters['assigned_to'] = array('operator' => '=', 'value' => TBGContext::getUser()->getID());
                     $this->groupby = 'issuetype';
                     break;
                 case TBGContext::PREDEFINED_SEARCH_TEAM_ASSIGNED_OPEN_ISSUES:
                     $this->filters['state'] = array('operator' => '=', 'value' => TBGIssue::STATE_OPEN);
                     $this->filters['assigned_type'] = array('operator' => '=', 'value' => TBGIdentifiableClass::TYPE_TEAM);
                     foreach (TBGContext::getUser()->getTeams() as $team_id => $team) {
                         $this->filters['assigned_to'][] = array('operator' => '=', 'value' => $team_id);
                     }
                     $this->groupby = 'issuetype';
                     break;
             }
         } elseif (in_array($this->templatename, array('results_userpain_singlepainthreshold', 'results_userpain_totalpainthreshold'))) {
             $this->searchtitle = $i18n->__('Showing "bug report" issues sorted by user pain, threshold set at %threshold%', array('%threshold%' => $this->template_parameter));
             $this->ipp = 0;
             $this->groupby = 'user_pain';
             $this->grouporder = 'desc';
             $ids = TBGIssueTypesTable::getTable()->getBugReportTypeIDs();
             $this->filters['issuetype'] = array();
             foreach ($ids as $id) {
                 $this->filters['issuetype'][] = array('operator' => '=', 'value' => $id);
             }
         } elseif ($this->templatename == 'results_votes') {
             $this->searchtitle = $i18n->__('Showing issues ordered by number of votes');
             $this->ipp = $request->getParameter('issues_per_page', 100);
             $this->groupby = 'votes';
             $this->grouporder = 'desc';
         }
         list($this->foundissues, $this->resultcount) = TBGIssue::findIssues($this->filters, $this->ipp, $this->offset, $this->groupby, $this->grouporder);
     } elseif (count($this->foundissues) == 1 && !$request->getParameter('quicksearch')) {
         $issue = array_shift($this->foundissues);
         $this->forward(TBGContext::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo())));
     } elseif ($request->hasParameter('sortby')) {
     } else {
         $this->resultcount = count($this->foundissues);
         if ($this->templatename == 'results_userpain_singlepainthreshold') {
             usort($this->foundissues, array('searchActions', 'userPainSort'));
         }
     }
     if ($request->hasParameter('predefined_search')) {
         switch ((int) $request->getParameter('predefined_search')) {
             case TBGContext::PREDEFINED_SEARCH_PROJECT_OPEN_ISSUES:
                 $this->searchtitle = TBGContext::isProjectContext() ? $i18n->__('Open issues for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName())) : $i18n->__('All open issues');
                 break;
             case TBGContext::PREDEFINED_SEARCH_PROJECT_CLOSED_ISSUES:
                 $this->searchtitle = TBGContext::isProjectContext() ? $i18n->__('Closed issues for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName())) : $i18n->__('All closed issues');
                 break;
             case TBGContext::PREDEFINED_SEARCH_PROJECT_MILESTONE_TODO:
                 $this->searchtitle = $i18n->__('Milestone todo-list for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName()));
                 $this->templatename = 'results_todo';
                 break;
             case TBGContext::PREDEFINED_SEARCH_PROJECT_MOST_VOTED:
                 $this->searchtitle = TBGContext::isProjectContext() ? $i18n->__('Most voted issues for %project_name%', array('%project_name%' => TBGContext::getCurrentProject()->getName())) : $i18n->__('Most voted issues');
                 $this->templatename = 'results_votes';
                 break;
             case TBGContext::PREDEFINED_SEARCH_MY_ASSIGNED_OPEN_ISSUES:
                 $this->searchtitle = $i18n->__('Open issues assigned to me');
                 break;
             case TBGContext::PREDEFINED_SEARCH_TEAM_ASSIGNED_OPEN_ISSUES:
                 $this->searchtitle = $i18n->__('Open issues assigned to my teams');
                 break;
             case TBGContext::PREDEFINED_SEARCH_MY_REPORTED_ISSUES:
                 $this->searchtitle = $i18n->__('Issues reported by me');
                 break;
         }
     }
 }
コード例 #9
0
 /**
  * Runs the action for the fifth step of the installation
  * where it enables modules on demand
  * 
  * @param TBGRequest $request The request object
  * 
  * @return null
  */
 public function runInstallStep5(TBGRequest $request)
 {
     $this->sample_data = false;
     try {
         if ($request->hasParameter('modules')) {
             foreach ($request->getParameter('modules', array()) as $module => $install) {
                 if ((bool) $install && file_exists(THEBUGGENIE_MODULES_PATH . $module . DS . 'module')) {
                     TBGModule::installModule($module);
                 }
             }
         } elseif ($request->hasParameter('sample_data')) {
             $this->sample_data = true;
         }
     } catch (Exception $e) {
         throw $e;
         $this->error = $e->getMessage();
     }
 }
コード例 #10
0
ファイル: actions.class.php プロジェクト: oparoz/thebuggenie
 /**
  * Reset user password
  * 
  * @param TBGRequest $request The request object
  * 
  */
 public function runReset(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     try {
         if ($request->hasParameter('user') && $request->hasParameter('reset_hash')) {
             $user = TBGUser::getByUsername(str_replace('%2E', '.', $request['user']));
             if ($user instanceof TBGUser) {
                 if ($request['reset_hash'] == $user->getActivationKey()) {
                     $this->error = false;
                     if ($request->isPost()) {
                         $p1 = trim($request['password_1']);
                         $p2 = trim($request['password_2']);
                         if ($p1 && $p2 && $p1 == $p2) {
                             $user->setPassword($p1);
                             $user->regenerateActivationKey();
                             $user->save();
                             TBGContext::setMessage('login_message', $i18n->__('Your password has been reset. Please log in.'));
                             TBGContext::setMessage('login_referer', $this->getRouting()->generate('home'));
                             return $this->forward(TBGContext::getRouting()->generate('login_page'));
                         } else {
                             $this->error = true;
                         }
                     } else {
                         $user->regenerateActivationKey();
                     }
                     $this->user = $user;
                 } else {
                     throw new Exception('Your password recovery token is either invalid or has expired');
                 }
             } else {
                 throw new Exception('User is invalid or does not exist');
             }
         } else {
             throw new Exception('An internal error has occured');
         }
     } catch (Exception $e) {
         TBGContext::setMessage('login_message_err', $i18n->__($e->getMessage()));
         return $this->forward(TBGContext::getRouting()->generate('login_page'));
     }
 }
コード例 #11
0
 /**
  * Show an article
  *
  * @param TBGRequest $request
  */
 public function runEditArticle(TBGRequest $request)
 {
     $article_name = $this->article instanceof TBGWikiArticle ? $this->article->getName() : $request->getParameter('article_name');
     if (!TBGContext::getModule('publish')->canUserEditArticle($article_name)) {
         TBGContext::setMessage('publish_article_error', TBGContext::getI18n()->__('You do not have permission to edit this article'));
         $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $article_name)));
     }
     if ($request->isMethod(TBGRequest::POST)) {
         if ($request->hasParameter('new_article_name') && $request->getParameter('new_article_name') != '') {
             if ($request->hasParameter('change_reason') && trim($request->getParameter('change_reason')) != '') {
                 try {
                     if ($request->getParameter('article_id')) {
                         if (($article = PublishFactory::article($request->getParameter('article_id'))) && $article instanceof TBGWikiArticle) {
                             if ($article->getLastUpdatedDate() != $request->getParameter('last_modified')) {
                                 $this->error = TBGContext::getI18n()->__('The file has been modified since you last opened it');
                             } else {
                                 try {
                                     $article->setName($request->getParameter('new_article_name'));
                                     $article->setContent($request->getRawParameter('new_article_content'));
                                     if ($request->getParameter('preview')) {
                                         $this->article = $article;
                                     } else {
                                         $article->doSave(array(), $request->getParameter('change_reason'));
                                         TBGContext::setMessage('publish_article_message', TBGContext::getI18n()->__('The article was saved'));
                                         $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $article->getName())));
                                     }
                                 } catch (Exception $e) {
                                     $this->error = $e->getMessage();
                                 }
                             }
                         }
                     }
                 } catch (Exception $e) {
                 }
                 if (($article = TBGWikiArticle::getByName($request->getParameter('new_article_name'))) && $article instanceof TBGWikiArticle && $article->getID() != $request->getParameter('article_id')) {
                     $this->error = TBGContext::getI18n()->__('An article with that name already exists. Please choose a different article name');
                 } elseif (!$article instanceof TBGWikiArticle) {
                     if ($request->getParameter('preview')) {
                         $article = new TBGWikiArticle();
                         $article->setContent($request->getRawParameter('new_article_content'));
                         $article->setName($request->getParameter('new_article_name'));
                         $this->article = $article;
                     } else {
                         $article_id = TBGWikiArticle::createNew($request->getParameter('new_article_name'), $request->getRawParameter('new_article_content', ''), true);
                         $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $request->getParameter('new_article_name'))));
                     }
                 }
             } else {
                 $this->error = TBGContext::getI18n()->__('You have to provide a reason for the changes');
             }
         } else {
             $this->error = TBGContext::getI18n()->__('You need to specify the article name');
         }
     }
     $this->preview = (bool) $request->getParameter('preview');
     $this->article_title = null;
     $this->article_content = null;
     $this->article_intro = null;
     $this->change_reason = null;
     if ($this->article instanceof TBGWikiArticle) {
         $this->article_title = $this->article->getTitle();
         $this->article_content = $this->article->getContent();
         if ($request->isMethod(TBGRequest::POST)) {
             if ($request->hasParameter('new_article_name')) {
                 $this->article_title = $request->getParameter('new_article_name');
             }
             if ($request->hasParameter('new_article_content')) {
                 $this->article_content = $request->getRawParameter('new_article_content');
             }
             if ($request->hasParameter('change_reason')) {
                 $this->change_reason = $request->getParameter('change_reason');
             }
         }
     } else {
         if ($request->hasParameter('new_article_content')) {
             $this->article_content = $request->getRawParameter('new_article_content');
         }
         TBGContext::loadLibrary('publish');
         $this->article_title = str_replace(array(':', '_'), array(' ', ' '), get_spaced_name($this->article_name));
     }
 }
コード例 #12
0
ファイル: actions.class.php プロジェクト: oparoz/thebuggenie
 /**
  * Show an article
  *
  * @param TBGRequest $request
  */
 public function runShowArticle(TBGRequest $request)
 {
     if ($this->special) {
         $this->redirect('specialArticle');
     }
     $this->message = TBGContext::getMessageAndClear('publish_article_message');
     $this->error = TBGContext::getMessageAndClear('publish_article_error');
     $this->redirected_from = TBGContext::getMessageAndClear('publish_redirected_article');
     if ($this->article instanceof TBGWikiArticle) {
         if (!$this->article->hasAccess()) {
             $this->error = TBGContext::getI18n()->__("You don't have access to read this article");
             $this->article = null;
         } else {
             $this->getUser()->markNotificationsRead('article', $this->article->getID());
             if (!$request->hasParameter('no_redirect') && $this->article->isRedirect()) {
                 if ($redirect_article = $this->article->getRedirectArticleName()) {
                     TBGContext::setMessage('publish_redirected_article', $this->article->getName());
                     $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $redirect_article)));
                 }
             }
             try {
                 if ($request->hasParameter('revision')) {
                     $this->revision = $request['revision'];
                     $this->article->setRevision($this->revision);
                 }
             } catch (Exception $e) {
                 $this->error = TBGContext::getI18n()->__('There was an error trying to show this revision');
             }
         }
     }
 }
コード例 #13
0
 public function setValuesFromRequest(TBGRequest $request)
 {
     if ($request->hasParameter('predefined_search')) {
         $this->setPredefinedVariables($request['predefined_search']);
     } else {
         $this->_templatename = $request->hasParameter('template') && self::isTemplateValid($request['template']) ? $request['template'] : 'results_normal';
         $this->_templateparameter = $request['template_parameter'];
         $this->_issues_per_page = $request->getParameter('issues_per_page', 50);
         $this->_offset = $request->getParameter('offset', 0);
         $this->_filters = TBGSearchFilter::getFromRequest($request, $this);
         $this->_applies_to_project = TBGContext::getCurrentProject();
         $this->_columns = $request->getParameter('columns');
         $this->_sortfields = $request->getParameter('sortfields');
         if ($request['quicksearch']) {
             $this->setSortFields(array(TBGIssuesTable::LAST_UPDATED => 'asc'));
         }
         $this->_groupby = $request['groupby'];
         $this->_grouporder = $request->getParameter('grouporder', 'asc');
         if (in_array($this->_templatename, array('results_userpain_singlepainthreshold', 'results_userpain_totalpainthreshold'))) {
             $this->_searchtitle = TBGContext::getI18n()->__('Showing "bug report" issues sorted by user pain, threshold set at %threshold', array('%threshold' => $this->_template_parameter));
             $this->_issues_per_page = 0;
             $this->_groupby = 'user_pain';
             $this->_grouporder = 'desc';
             $this->_filters['issuetype'] = TBGSearchFilter::createFilter('issuetype', join(',', TBGIssueTypesTable::getTable()->getBugReportTypeIDs()));
         } elseif ($this->_templatename == 'results_votes') {
             $this->_searchtitle = TBGContext::getI18n()->__('Showing issues ordered by number of votes');
             $this->_issues_per_page = $request->getParameter('issues_per_page', 100);
             $this->_groupby = 'votes';
             $this->_grouporder = 'desc';
         }
     }
     $this->_setupGenericFilters();
 }
コード例 #14
0
 /**
  * Reset user password
  * 
  * @param TBGRequest $request The request object
  * 
  */
 public function runReset(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     if ($request->hasParameter('user') && $request->hasParameter('id') && $request->hasParameter('forgot_password_mail')) {
         try {
             $user = TBGUser::getByUsername($request->getParameter('user'));
             if ($user instanceof TBGUser) {
                 if ($request->getParameter('id') == $user->getHashPassword()) {
                     if ($request->getParameter('forgot_password_mail') == $user->getEmail()) {
                         $password = $user->createPassword();
                         $user->changePassword($password);
                         $user->save();
                         $event = TBGEvent::createNew('core', 'password_reset', $user, array('password' => $password))->trigger();
                         return $this->renderJSON(array('message' => $i18n->__('An email has been sent to you with your new password.')));
                     } else {
                         throw new Exception('Invalid email address');
                     }
                 } else {
                     throw new Exception('Your password recovery token is either invalid or has expired');
                 }
             } else {
                 throw new Exception('User is invalid or does not exist');
             }
         } catch (Exception $e) {
             return $this->renderJSON(array('failed' => true, 'error' => $i18n->__($e->getMessage())));
         }
     } else {
         return $this->renderJSON(array('failed' => true, 'error' => 'An internal error has occured'));
     }
 }