1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-28 00:10:57 +01:00

Use hybrid properties + search for Releeph branches, too

Summary: Ref T3092. Same deal as D6771, but for branches rather than projects.

Test Plan: {F54855}

Reviewers: btrahan, chad

Reviewed By: chad

CC: chad, aran

Maniphest Tasks: T3092

Differential Revision: https://secure.phabricator.com/D6775
This commit is contained in:
epriestley 2013-08-20 07:35:31 -07:00
parent dcec8e60cc
commit 43b35a02ce
5 changed files with 95 additions and 22 deletions

View file

@ -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

View file

@ -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':

View file

@ -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();

View file

@ -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,
);
}
}

View file

@ -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();