diff --git a/src/applications/releeph/controller/ReleephProjectController.php b/src/applications/releeph/controller/ReleephProjectController.php index c7530e1d79..cc3fc54bcc 100644 --- a/src/applications/releeph/controller/ReleephProjectController.php +++ b/src/applications/releeph/controller/ReleephProjectController.php @@ -16,7 +16,10 @@ abstract class ReleephProjectController extends ReleephController { $project_id = idx($data, 'projectID'); $project_name = idx($data, 'projectName'); if ($project_id) { - $project = id(new ReleephProject())->load($project_id); + $project = id(new ReleephProjectQuery()) + ->setViewer($this->getRequest()->getUser()) + ->withIDs(array($project_id)) + ->executeOne(); if (!$project) { throw new Exception( "ReleephProject with id '{$project_id}' not found!"); diff --git a/src/applications/releeph/controller/project/ReleephProjectActionController.php b/src/applications/releeph/controller/project/ReleephProjectActionController.php index dfe20763f2..40e47f4b4b 100644 --- a/src/applications/releeph/controller/project/ReleephProjectActionController.php +++ b/src/applications/releeph/controller/project/ReleephProjectActionController.php @@ -11,15 +11,31 @@ final class ReleephProjectActionController extends ReleephProjectController { public function processRequest() { $request = $this->getRequest(); + $viewer = $request->getUser(); $action = $this->action; - $rph_project = $this->getReleephProject(); + + $project = id(new ReleephProjectQuery()) + ->withIDs(array($this->getReleephProject()->getID())) + ->requireCapabilities( + array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + )) + ->setViewer($viewer) + ->executeOne(); + if (!$project) { + return new Aphront404Response(); + } + + $project_id = $project->getID(); + $project_uri = $this->getApplicationURI("project/{$project_id}/"); switch ($action) { case 'deactivate': if ($request->isDialogFormPost()) { - $rph_project->deactivate($request->getUser())->save(); - return id(new AphrontRedirectResponse())->setURI('/releeph'); + $project->deactivate($viewer)->save(); + return id(new AphrontRedirectResponse())->setURI($project_uri); } $dialog = id(new AphrontDialogView()) @@ -29,42 +45,14 @@ final class ReleephProjectActionController extends ReleephProjectController { 'p', array(), pht('Really deactivate the Releeph project: %s?', - $rph_project->getName()))) - ->appendChild(phutil_tag( - 'p', - array(), - pht('It will still exist, but '. - 'will be hidden from the list of active projects.'))) - ->addSubmitButton(pht('Deactivate Releeph Project')) - ->addCancelButton($request->getRequestURI()); + $project->getName()))) + ->addSubmitButton(pht('Deactivate Project')) + ->addCancelButton($project_uri); return id(new AphrontDialogResponse())->setDialog($dialog); - case 'activate': - $rph_project->setIsActive(1)->save(); - return id(new AphrontRedirectResponse())->setURI('/releeph'); - - case 'delete': - if ($request->isDialogFormPost()) { - $rph_project->delete(); - return id(new AphrontRedirectResponse()) - ->setURI('/releeph/project/inactive'); - } - - $dialog = id(new AphrontDialogView()) - ->setUser($request->getUser()) - ->setTitle(pht('Really delete Releeph Project?')) - ->appendChild(phutil_tag( - 'p', - array(), - pht('Really delete the Releeph project: %s? '. - 'This cannot be undone!'), - $rph_project->getName())) - ->setHeaderColor(PhabricatorActionHeaderView::HEADER_RED) - ->addSubmitButton(pht('Delete')) - ->addCancelButton($request->getRequestURI()); - return id(new AphrontDialogResponse())->setDialog($dialog); - + $project->setIsActive(1)->save(); + return id(new AphrontRedirectResponse())->setURI($project_uri); } } } diff --git a/src/applications/releeph/controller/project/ReleephProjectListController.php b/src/applications/releeph/controller/project/ReleephProjectListController.php index 93a491a1f8..a8caf83401 100644 --- a/src/applications/releeph/controller/project/ReleephProjectListController.php +++ b/src/applications/releeph/controller/project/ReleephProjectListController.php @@ -39,34 +39,9 @@ final class ReleephProjectListController extends ReleephController ->setHeader($project->getName()) ->setHref($this->getApplicationURI("project/{$id}/")); - $edit_uri = $this->getApplicationURI("project/{$id}/edit/"); - $item->addAction( - id(new PHUIListItemView()) - ->setIcon('edit') - ->setHref($edit_uri)); - - if ($project->getIsActive()) { - $disable_uri = $this->getApplicationURI( - "project/{$id}/action/deactivate/"); - - $item->addAction( - id(new PHUIListItemView()) - ->setIcon('delete') - ->setName(pht('Deactivate')) - ->setWorkflow(true) - ->setHref($disable_uri)); - } else { - $enable_uri = $this->getApplicationURI( - "project/{$id}/action/activate/"); - + if (!$project->getIsActive()) { $item->setDisabled(true); $item->addIcon('none', pht('Inactive')); - $item->addAction( - id(new PHUIListItemView()) - ->setIcon('new') - ->setName(pht('Reactivate')) - ->setWorkflow(true) - ->setHref($enable_uri)); } $repo = $project->getRepository(); diff --git a/src/applications/releeph/controller/project/ReleephProjectViewController.php b/src/applications/releeph/controller/project/ReleephProjectViewController.php index 5941c7400c..12db331632 100644 --- a/src/applications/releeph/controller/project/ReleephProjectViewController.php +++ b/src/applications/releeph/controller/project/ReleephProjectViewController.php @@ -18,6 +18,7 @@ final class ReleephProjectViewController extends ReleephProjectController $request = $this->getRequest(); $controller = id(new PhabricatorApplicationSearchController($request)) ->setQueryKey($this->queryKey) + ->setPreface($this->renderPreface()) ->setSearchEngine( id(new ReleephBranchSearchEngine()) ->setProjectID($this->getReleephProject()->getID())) @@ -165,4 +166,92 @@ final class ReleephProjectViewController extends ReleephProjectController return $crumbs; } + private function renderPreface() { + $project = $this->getReleephProject(); + $viewer = $this->getRequest()->getUser(); + + $id = $project->getID(); + + $header = id(new PhabricatorHeaderView()) + ->setHeader($project->getName()); + + if (!$project->getIsActive()) { + $header->addTag( + id(new PhabricatorTagView()) + ->setType(PhabricatorTagView::TYPE_STATE) + ->setBackgroundColor(PhabricatorTagView::COLOR_BLACK) + ->setName(pht('Deactivated'))); + } + + $actions = id(new PhabricatorActionListView()) + ->setUser($viewer) + ->setObject($project) + ->setObjectURI($this->getRequest()->getRequestURI()); + + $can_edit = PhabricatorPolicyFilter::hasCapability( + $viewer, + $project, + PhabricatorPolicyCapability::CAN_EDIT); + + $edit_uri = $this->getApplicationURI("project/{$id}/edit/"); + + $deactivate_uri = "project/{$id}/action/deactivate/"; + $deactivate_uri = $this->getApplicationURI($deactivate_uri); + + $reactivate_uri = "project/{$id}/action/activate/"; + $reactivate_uri = $this->getApplicationURI($reactivate_uri); + + $actions->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Edit Project')) + ->setHref($edit_uri) + ->setIcon('edit') + ->setDisabled(!$can_edit) + ->setWorkflow(!$can_edit)); + + if ($project->getIsActive()) { + $actions->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Deactivate Project')) + ->setHref($deactivate_uri) + ->setIcon('delete') + ->setDisabled(!$can_edit) + ->setWorkflow(true)); + } else { + $actions->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Reactivate Project')) + ->setHref($reactivate_uri) + ->setIcon('new') + ->setUser($viewer) + ->setRenderAsForm(true) + ->setDisabled(!$can_edit) + ->setWorkflow(true)); + } + + + $properties = id(new PhabricatorPropertyListView()) + ->setUser($viewer) + ->setObject($project); + + $properties->addProperty( + pht('Repository'), + $project->getRepository()->getName()); + + $pushers = $project->getPushers(); + if ($pushers) { + $this->loadHandles($pushers); + $properties->addProperty( + pht('Pushers'), + $this->renderHandlesForPHIDs($pushers)); + } + + return array( + $header, + $actions, + $properties, + ); + + } + } diff --git a/src/applications/releeph/storage/ReleephProject.php b/src/applications/releeph/storage/ReleephProject.php index 668aef79c0..8f31a038a4 100644 --- a/src/applications/releeph/storage/ReleephProject.php +++ b/src/applications/releeph/storage/ReleephProject.php @@ -181,6 +181,7 @@ final class ReleephProject extends ReleephDAO public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, ); } diff --git a/src/applications/search/controller/PhabricatorApplicationSearchController.php b/src/applications/search/controller/PhabricatorApplicationSearchController.php index e79c14afef..969bb7c244 100644 --- a/src/applications/search/controller/PhabricatorApplicationSearchController.php +++ b/src/applications/search/controller/PhabricatorApplicationSearchController.php @@ -6,6 +6,16 @@ final class PhabricatorApplicationSearchController private $searchEngine; private $navigation; private $queryKey; + private $preface; + + public function setPreface($preface) { + $this->preface = $preface; + return $this; + } + + public function getPreface() { + return $this->preface; + } public function setQueryKey($query_key) { $this->queryKey = $query_key; @@ -166,6 +176,10 @@ final class PhabricatorApplicationSearchController $this->getApplicationURI('query/advanced/?query='.$query_key)); } + if ($this->getPreface()) { + $nav->appendChild($this->getPreface()); + } + $nav->appendChild($filter_view); if ($run_query) {