diff --git a/src/applications/releeph/controller/ReleephProjectController.php b/src/applications/releeph/controller/ReleephProjectController.php index cc3fc54bcc..ca85781e69 100644 --- a/src/applications/releeph/controller/ReleephProjectController.php +++ b/src/applications/releeph/controller/ReleephProjectController.php @@ -11,13 +11,15 @@ abstract class ReleephProjectController extends ReleephController { * referenced in the URL. */ public function willProcessRequest(array $data) { + $viewer = $this->getRequest()->getUser(); + // Project $project = null; $project_id = idx($data, 'projectID'); $project_name = idx($data, 'projectName'); if ($project_id) { $project = id(new ReleephProjectQuery()) - ->setViewer($this->getRequest()->getUser()) + ->setViewer($viewer) ->withIDs(array($project_id)) ->executeOne(); if (!$project) { @@ -38,7 +40,10 @@ abstract class ReleephProjectController extends ReleephController { $branch_id = idx($data, 'branchID'); $branch_name = idx($data, 'branchName'); if ($branch_id) { - $branch = id(new ReleephBranch())->load($branch_id); + $branch = id(new ReleephBranchQuery()) + ->setViewer($viewer) + ->withIDs(array($branch_id)) + ->executeOne(); if (!$branch) { throw new Exception("Branch with id '{$branch_id}' not found!"); } @@ -57,6 +62,16 @@ abstract class ReleephProjectController extends ReleephController { "ReleephBranch with basename '{$branch_name}' not found ". "in project '{$project->getName()}'!"); } + // Do the branch query again, properly, to hit policies and load attached + // data. + // TODO: Clean this up with T3657. + $branch = id(new ReleephBranchQuery()) + ->setViewer($viewer) + ->withIDs(array($branch->getID())) + ->executeOne(); + if (!$branch) { + throw new Exception('404!'); + } } // Request diff --git a/src/applications/releeph/controller/branch/ReleephBranchAccessController.php b/src/applications/releeph/controller/branch/ReleephBranchAccessController.php index 8ad524aa4d..507c39e52d 100644 --- a/src/applications/releeph/controller/branch/ReleephBranchAccessController.php +++ b/src/applications/releeph/controller/branch/ReleephBranchAccessController.php @@ -13,7 +13,7 @@ final class ReleephBranchAccessController extends ReleephProjectController { $branch = $this->getReleephBranch(); $request = $this->getRequest(); - $done_uri = '/releeph/project/'.$branch->getReleephProjectID().'/'; + $done_uri = $branch->getURI(); switch ($this->action) { case 'close': diff --git a/src/applications/releeph/controller/branch/ReleephBranchEditController.php b/src/applications/releeph/controller/branch/ReleephBranchEditController.php index 4f8f5e50ce..c89848a5c8 100644 --- a/src/applications/releeph/controller/branch/ReleephBranchEditController.php +++ b/src/applications/releeph/controller/branch/ReleephBranchEditController.php @@ -34,7 +34,7 @@ final class ReleephBranchEditController extends ReleephProjectController { $releeph_branch->saveTransaction(); return id(new AphrontRedirectResponse()) - ->setURI('/releeph/project/'.$releeph_branch->getReleephProjectID()); + ->setURI($releeph_branch->getURI()); } $phids = array(); diff --git a/src/applications/releeph/controller/branch/ReleephBranchViewController.php b/src/applications/releeph/controller/branch/ReleephBranchViewController.php index 517ae7d50b..a82795a19a 100644 --- a/src/applications/releeph/controller/branch/ReleephBranchViewController.php +++ b/src/applications/releeph/controller/branch/ReleephBranchViewController.php @@ -19,6 +19,7 @@ final class ReleephBranchViewController extends ReleephProjectController $request = $this->getRequest(); $controller = id(new PhabricatorApplicationSearchController($request)) + ->setPreface($this->renderPreface()) ->setQueryKey($this->queryKey) ->setSearchEngine($this->getSearchEngine()) ->setNavigation($this->buildSideNavView()); @@ -91,5 +92,79 @@ final class ReleephBranchViewController extends ReleephProjectController return $crumbs; } + private function renderPreface() { + $branch = $this->getReleephBranch(); + $viewer = $this->getRequest()->getUser(); + + $id = $branch->getID(); + + $header = id(new PhabricatorHeaderView()) + ->setHeader($branch->getDisplayName()); + + if (!$branch->getIsActive()) { + $header->addTag( + id(new PhabricatorTagView()) + ->setType(PhabricatorTagView::TYPE_STATE) + ->setBackgroundColor(PhabricatorTagView::COLOR_BLACK) + ->setName(pht('Closed'))); + } + + $actions = id(new PhabricatorActionListView()) + ->setUser($viewer) + ->setObject($branch) + ->setObjectURI($this->getRequest()->getRequestURI()); + + $can_edit = PhabricatorPolicyFilter::hasCapability( + $viewer, + $branch, + PhabricatorPolicyCapability::CAN_EDIT); + + $edit_uri = $branch->getURI('edit/'); + $close_uri = $branch->getURI('close/'); + $reopen_uri = $branch->getURI('re-open/'); + + $actions->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Edit Branch')) + ->setHref($edit_uri) + ->setIcon('edit') + ->setDisabled(!$can_edit) + ->setWorkflow(!$can_edit)); + + if ($branch->getIsActive()) { + $actions->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Close Branch')) + ->setHref($close_uri) + ->setIcon('delete') + ->setDisabled(!$can_edit) + ->setWorkflow(true)); + } else { + $actions->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Reopen Branch')) + ->setHref($reopen_uri) + ->setIcon('new') + ->setUser($viewer) + ->setRenderAsForm(true) + ->setDisabled(!$can_edit) + ->setWorkflow(true)); + } + + + $properties = id(new PhabricatorPropertyListView()) + ->setUser($viewer) + ->setObject($branch); + + $properties->addProperty( + pht('Branch'), + $branch->getName()); + + return array( + $header, + $actions, + $properties, + ); + } } diff --git a/src/applications/releeph/controller/project/ReleephProjectViewController.php b/src/applications/releeph/controller/project/ReleephProjectViewController.php index 12db331632..8bab38551d 100644 --- a/src/applications/releeph/controller/project/ReleephProjectViewController.php +++ b/src/applications/releeph/controller/project/ReleephProjectViewController.php @@ -90,25 +90,8 @@ final class ReleephProjectViewController extends ReleephProjectController ->setHref($branch->getURI()) ->addAttribute($branch_link); - $item->addAction( - id(new PHUIListItemView()) - ->setIcon('edit') - ->setHref($branch->getURI('edit/'))); - - if ($branch->getIsActive()) { - $item->setBarColor('blue'); - $item->addAction( - id(new PHUIListItemView()) - ->setIcon('delete') - ->setWorkflow(true) - ->setHref($branch->getURI('close/'))); - } else { + if (!$branch->getIsActive()) { $item->setDisabled(true); - $item->addAction( - id(new PHUIListItemView()) - ->setIcon('enable') - ->setWorkflow(true) - ->setHref($branch->getURI('re-open/'))); } $commit = $branch->getCutPointCommit();