/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { /* @type \JTracker\Application $app */ $app = $this->getContainer()->get('app'); $app->getUser()->authorize('manage'); $project = $app->getProject(); try { $this->model->setProject($project); $data = $app->input->get('category', array(), 'array'); if (isset($data['id'])) { $this->model->save($data); } else { $this->model->add($data); } // Reload the project. $this->model->setProject($project); $app->enqueueMessage('The changes have been saved.', 'success'); $app->redirect($app->get('uri.base.path') . 'category/' . $project->alias); } catch (\Exception $exception) { $app->enqueueMessage($exception->getMessage(), 'error'); if ($app->input->get('id')) { $app->redirect($app->get('uri.base.path') . 'category/' . $project->alias . '/' . $app->input->get('id') . '/edit'); } else { $app->redirect($app->get('uri.base.path') . 'category/' . $project->alias . '/add'); } } parent::execute(); }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { $table = new GroupsTable($this->getContainer()->get('db')); $table->load($this->getContainer()->get('app')->input->getInt('group_id'))->delete(); $this->getContainer()->get('app')->enqueueMessage(g11n3t('The group has been deleted.'), 'success'); return parent::execute(); }
/** * Execute the controller. * * @return string The rendered view. * * @since 1.0 * @throws \UnexpectedValueException */ public function execute() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $id = $application->input->getUint('id'); if (!$id) { throw new \UnexpectedValueException('No id given'); } if (!$application->getUser()->check('admin')) { if ($application->getUser()->id != $id) { $application->enqueueMessage(g11n3t('You are not authorized to refresh this user.'), 'error')->redirect($application->get('uri.base.path') . 'user/' . $id); } } /* @type \Joomla\Github\Github $github */ $gitHub = $this->getContainer()->get('gitHub'); $loginHelper = new GitHubLoginHelper($this->getContainer()); $gitHubUser = $gitHub->users->getAuthenticatedUser(); $user = new GithubUser($application->getProject(), $this->getContainer()->get('db')); $user->loadGitHubData($gitHubUser)->loadByUserName($user->username); // Refresh the avatar $loginHelper->refreshAvatar($user->username); try { $loginHelper->setEmail($user->id, $gitHubUser->email); } catch (\RuntimeException $e) { $application->enqueueMessage(g11n3t('An error has occurred during email refresh.'), 'error'); } $application->enqueueMessage(g11n3t('The profile has been refreshed.'), 'success')->redirect($application->get('uri.base.path') . 'user/' . $id); return parent::execute(); }
/** * Execute the controller. * * @return string The rendered view. * * @since 1.0 */ public function execute() { $group = $this->getContainer()->get('app')->input->get('group', array(), 'array'); $table = new GroupsTable($this->getContainer()->get('db')); $table->save($group); return parent::execute(); }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { $model = new ProjectModel($this->getContainer()->get('db')); $model->delete($this->getContainer()->get('app')->input->get('project_alias')); // Reload the project $this->getContainer()->get('app')->getProject(true); return parent::execute(); }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $application->getUser()->authorize('manage'); $this->view->setProject($application->getProject()); $item = new \stdClass(); $this->view->setItem($item); return parent::execute(); }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { $app = $this->getContainer()->get('app'); $app->getUser()->authorize('admin'); $table = new ProjectsTable($this->getContainer()->get('db')); $table->save($app->input->get('project', array(), 'array')); // Reload the project. $app->getProject(true); return parent::execute(); }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { $app = $this->getContainer()->get('app'); $app->getUser()->authorize('admin'); $table = new ArticlesTable($this->getContainer()->get('db')); $table->delete($app->input->getInt('id')); $app->enqueueMessage(g11n3t('The article has been deleted.'), 'success'); $this->getContainer()->get('app')->input->set('view', 'articles'); return parent::execute(); }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { $app = $this->getContainer()->get('app'); $app->getUser()->authorize('admin'); $table = new ArticlesTable($this->getContainer()->get('db')); /* @type \Joomla\Github\Github $gitHub */ $table->setGitHub($this->getContainer()->get('gitHub')); $table->save($app->input->get('article', array(), 'array')); $app->enqueueMessage(g11n3t('The article has been saved.'), 'success'); return parent::execute(); }
/** * Execute the controller. * * @return string The rendered view. * * @since 1.0 * @throws \RuntimeException */ public function execute() { $application = $this->getContainer()->get('app'); $application->getUser()->authorize('view'); try { $randomNumber = (new IssueModel($this->getContainer()->get('db')))->setProject($this->getContainer()->get('app')->getProject())->getRandomNumber(); $application->redirect($application->get('uri.base.path') . '/tracker/' . $application->input->get('project_alias') . '/' . $randomNumber); } catch (\Exception $e) { $application->enqueueMessage($e->getMessage(), 'error'); $application->redirect($application->get('uri.base.path') . 'tracker/' . $application->input->get('project_alias')); } parent::execute(); }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $model = new CategoryModel($this->getContainer()->get('db')); try { $model->delete($application->input->get('id')); $application->enqueueMessage(g11n3t('The category has been deleted'), 'success'); } catch (\Exception $exception) { $application->enqueueMessage($exception->getMessage(), 'error'); } $application->redirect($application->get('uri.base.path') . 'category/' . $application->getProject()->alias); return parent::execute(); }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { $this->getContainer()->get('app')->getUser()->authorize('admin'); $routes = []; // Search for App specific routes /* @type \DirectoryIterator $fileInfo */ foreach (new \DirectoryIterator(JPATH_ROOT . '/src/App') as $fileInfo) { if ($fileInfo->isDot()) { continue; } $path = realpath(JPATH_ROOT . '/src/App/' . $fileInfo->getFilename() . '/routes.json'); if ($path) { $maps = json_decode(file_get_contents($path), true); if (!$maps) { throw new \RuntimeException('Invalid router file. ' . $path, 500); } $routes[$fileInfo->getFilename()] = $maps; } } $this->view->setRoutes($routes); return parent::execute(); }
/** * Execute the controller. * * @return string The rendered view. * * @since 1.0 * @throws \UnexpectedValueException */ public function execute() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $src = $application->input->get('item', array(), 'array'); if (!$src['id']) { throw new \UnexpectedValueException('No id given'); } if (!$application->getUser()->check('admin')) { if ($application->getUser()->id != $src['id']) { $application->enqueueMessage(g11n3t('You are not authorized to edit this user.'), 'error'); $application->redirect($application->get('uri.base.path') . 'user/' . $src['id']); } } try { // Save the record. (new UserModel($this->getContainer()->get('db')))->save($src); $application->enqueueMessage(g11n3t('The changes have been saved.'), 'success'); } catch (\Exception $e) { $application->enqueueMessage($e->getMessage(), 'error'); } $application->redirect($application->get('uri.base.path') . 'user/' . $src['id'] . '/edit'); parent::execute(); }
/** * Execute the controller. * * @throws \Exception * @throws \JTracker\Authentication\Exception\AuthenticationException * * @return string The rendered view. * * @since 1.0 */ public function execute() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $src = $application->input->get('item', array(), 'array'); $user = $application->getUser(); $project = $application->getProject(); $model = new IssueModel($this->getContainer()->get('db')); $model->setProject($project); $issueNumber = isset($src['issue_number']) ? (int) $src['issue_number'] : 0; if (!$issueNumber) { throw new \UnexpectedValueException('No issue number received.'); } $item = $model->getItem($issueNumber); $data = array(); if ($user->check('edit')) { // The user has full "edit" permission. $data = $src; } elseif ($user->canEditOwn($item->opened_by)) { // The user has "edit own" permission. $data['id'] = (int) $src['id']; $data['issue_number'] = (int) $src['issue_number']; $data['title'] = $src['title']; $data['description_raw'] = $src['description_raw']; // Take the remaining values from the stored item $data['status'] = $item->status; $data['priority'] = $item->priority; $data['build'] = $item->build; $data['rel_number'] = $item->rel_number; $data['rel_type'] = $item->rel_type; $data['easy'] = $item->easy; } else { // The user has no "edit" permission. throw new AuthenticationException($user, 'edit'); } $gitHub = GithubFactory::getInstance($application); if ($project->gh_user && $project->gh_project) { // Project is managed on GitHub // Check if the state has changed (e.g. open/closed) $oldState = $model->getOpenClosed($item->status); $state = $model->getOpenClosed($data['status']); try { $this->updateGitHub($item->issue_number, $data, $state, $oldState); } catch (GithubException $exception) { // DEBUG - @todo remove in stable $dump = ['exception' => $exception->getCode() . ' ' . $exception->getMessage(), 'user' => $project->gh_user, 'project' => $project->gh_project, 'issueNo' => $item->issue_number, 'state' => $state, 'old_state' => $oldState, 'data' => $data]; var_dump($dump); die('Unrecoverable GitHub error - sry ;('); } // Render the description text using GitHub's markdown renderer. $data['description'] = $gitHub->markdown->render($data['description_raw'], 'gfm', $project->gh_user . '/' . $project->gh_project); } else { // Project is managed by JTracker only // Render the description text using GitHub's markdown renderer. $data['description'] = $gitHub->markdown->render($src['description_raw'], 'markdown'); } try { $data['modified_by'] = $user->username; $categoryModel = new CategoryModel($this->getContainer()->get('db')); $category['issue_id'] = $data['id']; $category['categories'] = $application->input->get('categories', null, 'array'); $category['modified_by'] = $user->username; $category['issue_number'] = $data['issue_number']; $category['project_id'] = $project->project_id; $categoryModel->updateCategory($category); // Save the record. $model->save($data); $application->enqueueMessage(g11n3t('The changes have been saved.'), 'success')->redirect('/tracker/' . $application->input->get('project_alias') . '/' . $issueNumber); } catch (\Exception $exception) { $application->enqueueMessage($exception->getMessage(), 'error'); // @todo preserve data when returning to edit view on failure. $application->redirect($application->get('uri.base.path') . 'tracker/' . $application->input->get('project_alias') . '/' . $issueNumber . '/edit'); } return parent::execute(); }
/** * Execute the controller. * * @return string The rendered view. * * @since 1.0 */ public function execute() { $this->getContainer()->get('app')->getUser()->authorize('admin'); return parent::execute(); }
/** * Execute the controller. * * @return string The rendered view. * * @since 1.0 * @throws \JTracker\Authentication\Exception\AuthenticationException * @throws \RuntimeException * @throws \UnexpectedValueException */ public function execute() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $src = $application->input->get('item', array(), 'array'); $user = $application->getUser(); $project = $application->getProject(); $model = new IssueModel($this->getContainer()->get('db')); $model->setProject($project); $issueNumber = isset($src['issue_number']) ? (int) $src['issue_number'] : 0; if (!$issueNumber) { throw new \UnexpectedValueException('No issue number received.'); } $item = $model->getItem($issueNumber); $data = array(); if ($user->check('edit')) { // The user has full "edit" permission. $data = $src; // Allow admins to update labels and milestones if (!$user->check('manage')) { if (!empty($item->labels)) { $data['labels'] = explode(',', $item->labels); } $data['milestone_id'] = $item->milestone_id; } } elseif ($user->canEditOwn($item->opened_by)) { // The user has "edit own" permission. $data['id'] = (int) $src['id']; $data['issue_number'] = (int) $src['issue_number']; $data['title'] = $src['title']; $data['description_raw'] = $src['description_raw']; // Take the remaining values from the stored item if (!empty($item->labels)) { $data['labels'] = explode(',', $item->labels); } $data['status'] = $item->status; $data['priority'] = $item->priority; $data['build'] = $item->build; $data['rel_number'] = $item->rel_number; $data['rel_type'] = $item->rel_type; $data['easy'] = $item->easy; $data['milestone_id'] = $item->milestone_id; } else { // The user has no "edit" permission. throw new AuthenticationException($user, 'edit'); } $gitHub = GithubFactory::getInstance($application); // Check if the state has changed (e.g. open/closed) $oldState = $model->getOpenClosed($item->status); $state = $model->getOpenClosed($data['status']); // Project is managed on GitHub if ($project->gh_user && $project->gh_project) { // @todo assignee $assignee = null; // Prepare labels $ghLabels = []; if (!empty($data['labels'])) { foreach ($project->getLabels() as $id => $label) { if (in_array($id, $data['labels'])) { $ghLabels[] = $label->name; } } } // Prepare milestone $ghMilestone = null; if (!empty($data['milestone_id'])) { foreach ($project->getMilestones() as $milestone) { if ($milestone->milestone_id == $data['milestone_id']) { $ghMilestone = $milestone->milestone_number; } } } try { $gitHubResponse = $this->updateGitHub($item->issue_number, $data, $state, $oldState, $assignee, $ghMilestone, $ghLabels); // Set the modified_date from GitHub (important!) $data['modified_date'] = $gitHubResponse->updated_at; } catch (GithubException $exception) { $this->getContainer()->get('app')->getLogger()->error(sprintf('Error code %1$s received from GitHub when editing an issue with the following data:' . ' GitHub User: %2$s; GitHub Repo: %3$s; Issue Number: %4$s; State: %5$s, Old state: %6$s' . ' The error message returned was: %7$s', $exception->getCode(), $project->gh_user, $project->gh_project, $item->issue_number, $state, $oldState, $exception->getMessage())); throw new \RuntimeException('Invalid response from GitHub'); } // Render the description text using GitHub's markdown renderer. $data['description'] = $gitHub->markdown->render($data['description_raw'], 'gfm', $project->gh_user . '/' . $project->gh_project); } else { // Project is managed by JTracker only // Render the description text using GitHub's markdown renderer. $data['description'] = $gitHub->markdown->render($src['description_raw'], 'markdown'); $data['modified_date'] = (new Date())->format($this->getContainer()->get('db')->getDateFormat()); } try { $data['modified_by'] = $user->username; // If the user have edit permission, let him / her modify the categories. if ($user->check('edit')) { $categoryModel = new CategoryModel($this->getContainer()->get('db')); $category['issue_id'] = $data['id']; $category['modified_by'] = $user->username; $category['categories'] = $application->input->get('categories', null, 'array'); $category['issue_number'] = $data['issue_number']; $category['project_id'] = $project->project_id; $categoryModel->updateCategory($category); } // Pass the old and new states into the save method $data['old_state'] = $oldState; $data['new_state'] = $state; // Values that are not supposed to change. $data['commits'] = $item->commits; $data['pr_head_sha'] = $item->pr_head_sha; // Save the record. $model->save($data); $comment = $application->input->get('comment', '', 'raw'); // Save the comment. if ($comment) { /* @type \JTracker\Github\Github $github */ $github = $this->getContainer()->get('gitHub'); $project = $application->getProject(); $gitHubHelper = new GitHubHelper($github); $comment .= $gitHubHelper->getApplicationComment($application, $project, $issueNumber); $data = new \stdClass(); $db = $this->getContainer()->get('db'); if ($project->gh_user && $project->gh_project) { $gitHubResponse = $github->issues->comments->create($project->gh_user, $project->gh_project, $issueNumber, $comment); if (!isset($gitHubResponse->id)) { throw new \RuntimeException('Invalid response from GitHub'); } $data->created_at = $gitHubResponse->created_at; $data->opened_by = $gitHubResponse->user->login; $data->comment_id = $gitHubResponse->id; $data->text_raw = $gitHubResponse->body; $data->text = $github->markdown->render($comment, 'gfm', $project->gh_user . '/' . $project->gh_project); } else { $date = new Date(); $data->created_at = $date->format($db->getDateFormat()); $data->opened_by = $application->getUser()->username; $data->comment_id = '???'; $data->text_raw = $comment; $data->text = $github->markdown->render($comment, 'markdown'); } $table = new ActivitiesTable($db); $table->event = 'comment'; $table->created_date = $data->created_at; $table->project_id = $project->project_id; $table->issue_number = $issueNumber; $table->gh_comment_id = $data->comment_id; $table->user = $data->opened_by; $table->text = $data->text; $table->text_raw = $data->text_raw; $table->store(); } $application->enqueueMessage('The changes have been saved.', 'success')->redirect('/tracker/' . $application->input->get('project_alias') . '/' . $issueNumber); } catch (\RuntimeException $exception) { $application->enqueueMessage($exception->getMessage(), 'error'); // @todo preserve data when returning to edit view on failure. $application->redirect($application->get('uri.base.path') . 'tracker/' . $application->input->get('project_alias') . '/' . $issueNumber . '/edit'); } return parent::execute(); }