예제 #1
0
 /**
  * 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();
 }
예제 #2
0
 /**
  * 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();
 }
예제 #3
0
 /**
  * Initialize the controller.
  *
  * This will set up default model and view classes.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function initialize()
 {
     parent::initialize();
     $this->getContainer()->get('app')->getUser()->authorize('admin');
     $this->view->setAlias($this->getContainer()->get('app')->input->get('project_alias'));
     return $this;
 }
예제 #4
0
 /**
  * Initialize the controller.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function initialize()
 {
     parent::initialize();
     $this->getContainer()->get('app')->getUser()->authorize('admin');
     $this->view->setProject($this->getContainer()->get('app')->getProject());
     return $this;
 }
예제 #5
0
 /**
  * Initialize the controller.
  *
  * This will set up default model and view classes.
  *
  * @throws \Exception
  * @throws AuthenticationException
  *
  * @return  $this  Method supports chaining
  *
  * @since   1.0
  */
 public function initialize()
 {
     parent::initialize();
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $project = $application->getProject();
     $user = $application->getUser();
     $this->model->setProject($project);
     $item = $this->model->getItem($application->input->getUint('id'));
     $item->categoryids = array();
     foreach ($item->categories as $category) {
         $item->categoryids[] = $category->id;
     }
     try {
         // Check if the user has full "edit" permission
         $user->authorize('edit');
     } catch (AuthenticationException $e) {
         // Check if the user has "edit own" permission
         if (false == $user->canEditOwn($item->opened_by)) {
             throw $e;
         }
     }
     $this->view->setItem($item)->setProject($project);
     return $this;
 }
예제 #6
0
파일: Refresh.php 프로젝트: joomlla/jissues
 /**
  * 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();
 }
예제 #7
0
 /**
  * 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();
 }
예제 #8
0
 /**
  * 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();
 }
예제 #9
0
 /**
  * Initialize the controller.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  */
 public function initialize()
 {
     parent::initialize();
     $this->getContainer()->get('app')->getUser()->authorize('admin');
     $this->view->setLogType($this->getContainer()->get('app')->input->get('log_type'));
     $this->view->setDebugger(new TrackerDebugger($this->getContainer()));
     return $this;
 }
예제 #10
0
 /**
  * Initialize the controller.
  *
  * This will set up default model and view classes.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function initialize()
 {
     // Reload the project.
     $this->getContainer()->get('app')->getProject(true);
     parent::initialize();
     $this->view->setAlias($this->getContainer()->get('app')->input->get('project_alias'));
     return $this;
 }
예제 #11
0
 /**
  * Initialize the controller.
  *
  * This will set up default model and view classes.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function initialize()
 {
     parent::initialize();
     $this->getContainer()->get('app')->getUser()->authorize('manage');
     $this->model->setProject($this->getContainer()->get('app')->getProject());
     $this->model->setGroupId($this->getContainer()->get('app')->input->getInt('group_id'));
     $this->view->setProject($this->getContainer()->get('app')->getProject());
     return $this;
 }
예제 #12
0
 /**
  * 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();
 }
예제 #13
0
 /**
  * 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();
 }
예제 #14
0
 /**
  * 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();
 }
예제 #15
0
 /**
  * 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();
 }
예제 #16
0
 /**
  * Initialize the controller.
  *
  * @return  $this  Method supports chaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function initialize()
 {
     parent::initialize();
     /* @type $input \Joomla\Input\Input */
     $input = $this->getContainer()->get('app')->input;
     $path = $input->getPath('path');
     $page = $input->getCmd('page');
     if ($page) {
         $fullPath = 'page=' . $page . ($path ? '&path=' . $path : '');
         $this->view->setFullPath($fullPath);
     }
 }
예제 #17
0
 /**
  * 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();
 }
예제 #18
0
 /**
  * Initialize the controller.
  *
  * This will set up default model and view classes.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function initialize()
 {
     parent::initialize();
     $id = $this->getContainer()->get('app')->input->getUint('id');
     if (!$id) {
         // If no ID is given, use the ID of the current user.
         $id = $this->getContainer()->get('app')->getUser()->id;
         if (!$id) {
             throw new \UnexpectedValueException('No logged in user.');
         }
     }
     $this->view->id = (int) $id;
     $this->model->setProject($this->getContainer()->get('app')->getProject());
 }
예제 #19
0
 /**
  * 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();
 }
예제 #20
0
 /**
  * Initialize the controller.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function initialize()
 {
     parent::initialize();
     $alias = $this->getContainer()->get('app')->input->get('project_alias');
     if ($alias) {
         $project = (new ProjectModel($this->getContainer()->get('db')))->getByAlias($alias);
     } else {
         $project = $this->getContainer()->get('app')->getProject();
     }
     $data = (new Github())->repositories->statistics->getListContributors($project->gh_user, $project->gh_project);
     $data = array_reverse($data);
     $this->view->setProject($project);
     $this->view->setData($data);
     return $this;
 }
 /**
  * Initialize the controller.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  */
 public function initialize()
 {
     parent::initialize();
     /* @type Application $application */
     $application = $this->getContainer()->get('app');
     $limit = $application->getUserStateFromRequest('list.limit', 'list_limit', 20, 'int');
     $page = $application->input->getInt('page');
     $value = $page ? ($page - 1) * $limit : 0;
     $limitStart = $limit != 0 ? floor($value / $limit) * $limit : 0;
     $state = $this->model->getState();
     $state->set('list.start', $limitStart);
     $state->set('list.limit', $limit);
     $this->model->setState($state);
     $this->model->setPagination(new TrackerPagination(new Uri($this->getContainer()->get('app')->get('uri.request'))));
     return $this;
 }
예제 #22
0
 /**
  * Initialize the controller.
  *
  * This will set up default model and view classes.
  *
  * @return  $this  Method supports chaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function initialize()
 {
     parent::initialize();
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $project = $application->getProject();
     $user = $application->getUser();
     $user->authorize('view');
     $this->model->setProject($project);
     $item = $this->model->getItem($application->input->getUint('id'));
     $item->userTest = $this->model->getUserTest($item->id, $user->username);
     $this->view->setItem($item);
     $this->view->setEditOwn($user->canEditOwn($item->opened_by));
     $this->view->setProject($project);
     return $this;
 }
예제 #23
0
 /**
  * Initialize the controller.
  *
  * This will set up default model and view classes.
  *
  * @return  $this  Method supports chaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function initialize()
 {
     parent::initialize();
     $this->getContainer()->get('app')->getUser()->authorize('create');
     // New item
     $path = JPATH_ROOT . '/src/App/Tracker/tpl/new-issue-template.md';
     if (!file_exists($path)) {
         throw new \RuntimeException('New issue template not found.');
     }
     // Set some defaults
     $item = new \stdClass();
     $item->issue_number = 0;
     $item->priority = 3;
     $item->description_raw = file_get_contents($path);
     $this->view->setProject($this->getContainer()->get('app')->getProject());
     $this->view->setItem($item);
 }
예제 #24
0
 /**
  * Initialize the controller.
  *
  * This will set up default model and view classes.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  * @throws  \UnexpectedValueException
  */
 public function initialize()
 {
     parent::initialize();
     /* @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 edit this user.'), 'error');
             $application->redirect($application->get('uri.base.path') . 'users');
         }
     }
     $this->view->id = $id;
     $this->model->setProject($this->getContainer()->get('app')->getProject());
 }
예제 #25
0
 /**
  * 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();
 }
예제 #26
0
파일: Item.php 프로젝트: shamsbd71/jissues
 /**
  * Initialize the controller.
  *
  * This will set up default model and view classes.
  *
  * @return  $this  Method supports chaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function initialize()
 {
     parent::initialize();
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $project = $application->getProject();
     $user = $application->getUser();
     $user->authorize('view');
     $this->model->setProject($project);
     $item = $this->model->getItem($application->input->getUint('id'));
     if ($item->commits) {
         $commits = json_decode($item->commits);
         $lastCommit = end($commits);
         $sha = $lastCommit->sha;
     } else {
         $sha = false;
     }
     $item->userTest = $this->model->getUserTest($item->id, $user->username, $sha);
     $this->view->setItem($item);
     $this->view->setEditOwn($user->canEditOwn($item->opened_by));
     $this->view->setProject($project);
     return $this;
 }
예제 #27
0
 /**
  * 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();
 }
예제 #28
0
파일: Save.php 프로젝트: shamsbd71/jissues
 /**
  * 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();
 }
예제 #29
0
 /**
  * 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();
 }
예제 #30
0
 /**
  * Execute the controller.
  *
  * @return  string  The rendered view.
  *
  * @since   1.0
  */
 public function execute()
 {
     $this->getContainer()->get('app')->getUser()->authorize('admin');
     return parent::execute();
 }