Skip to content

Commit 2712091

Browse files
author
epriestley
committed
Move Releeph branch controllers toward a modern/stable state
Summary: Ref T3644. Ref T3657. Ref T3549. Basically: - Move these controllers to modern query/policy infrastructure. - Move them to consistent, ID-based URIs. - Rename "Project" to "Product"; "Pick Request" to "Pull Request". - Clean up a few UI things here and there. Test Plan: - Created and edited branches. - Opened and closed branches. - Viewed branch history. - Searched within a branch. - Browsed to branches from products. Reviewers: chad, btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3644, T3549, T3657 Differential Revision: https://secure.phabricator.com/D8646
1 parent cbfa991 commit 2712091

12 files changed

+239
-128
lines changed

src/__phutil_library_map__.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,6 +2497,7 @@
24972497
'ReleephBranch' => 'applications/releeph/storage/ReleephBranch.php',
24982498
'ReleephBranchAccessController' => 'applications/releeph/controller/branch/ReleephBranchAccessController.php',
24992499
'ReleephBranchCommitFieldSpecification' => 'applications/releeph/field/specification/ReleephBranchCommitFieldSpecification.php',
2500+
'ReleephBranchController' => 'applications/releeph/controller/branch/ReleephBranchController.php',
25002501
'ReleephBranchCreateController' => 'applications/releeph/controller/branch/ReleephBranchCreateController.php',
25012502
'ReleephBranchEditController' => 'applications/releeph/controller/branch/ReleephBranchEditController.php',
25022503
'ReleephBranchEditor' => 'applications/releeph/editor/ReleephBranchEditor.php',
@@ -5479,12 +5480,13 @@
54795480
0 => 'ReleephDAO',
54805481
1 => 'PhabricatorPolicyInterface',
54815482
),
5482-
'ReleephBranchAccessController' => 'ReleephProjectController',
5483+
'ReleephBranchAccessController' => 'ReleephBranchController',
54835484
'ReleephBranchCommitFieldSpecification' => 'ReleephFieldSpecification',
5484-
'ReleephBranchCreateController' => 'ReleephProjectController',
5485-
'ReleephBranchEditController' => 'ReleephProjectController',
5485+
'ReleephBranchController' => 'ReleephController',
5486+
'ReleephBranchCreateController' => 'ReleephProductController',
5487+
'ReleephBranchEditController' => 'ReleephBranchController',
54865488
'ReleephBranchEditor' => 'PhabricatorEditor',
5487-
'ReleephBranchHistoryController' => 'ReleephProjectController',
5489+
'ReleephBranchHistoryController' => 'ReleephBranchController',
54885490
'ReleephBranchNamePreviewController' => 'ReleephController',
54895491
'ReleephBranchPreviewView' => 'AphrontFormControl',
54905492
'ReleephBranchQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
@@ -5493,7 +5495,7 @@
54935495
'ReleephBranchTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
54945496
'ReleephBranchViewController' =>
54955497
array(
5496-
0 => 'ReleephProjectController',
5498+
0 => 'ReleephBranchController',
54975499
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
54985500
),
54995501
'ReleephCommitFinderException' => 'Exception',

src/applications/releeph/controller/ReleephController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,13 @@ public function buildApplicationMenu() {
3838
return $this->buildSideNavView(true)->getMenu();
3939
}
4040

41+
42+
protected function getProductViewURI(ReleephProject $product) {
43+
return $this->getApplicationURI('project/'.$product->getID().'/');
44+
}
45+
46+
protected function getBranchViewURI(ReleephBranch $branch) {
47+
return $this->getApplicationURI('branch/'.$branch->getID().'/');
48+
}
49+
4150
}
Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,81 @@
11
<?php
22

3-
final class ReleephBranchAccessController extends ReleephProjectController {
3+
final class ReleephBranchAccessController extends ReleephBranchController {
44

55
private $action;
6+
private $branchID;
67

78
public function willProcessRequest(array $data) {
89
$this->action = $data['action'];
9-
parent::willProcessRequest($data);
10+
$this->branchID = $data['branchID'];
1011
}
1112

1213
public function processRequest() {
13-
$branch = $this->getReleephBranch();
1414
$request = $this->getRequest();
15+
$viewer = $request->getUser();
1516

16-
$done_uri = $branch->getURI();
17+
$branch = id(new ReleephBranchQuery())
18+
->setViewer($viewer)
19+
->withIDs(array($this->branchID))
20+
->requireCapabilities(
21+
array(
22+
PhabricatorPolicyCapability::CAN_VIEW,
23+
PhabricatorPolicyCapability::CAN_EDIT,
24+
))
25+
->executeOne();
26+
if (!$branch) {
27+
return new Aphront404Response();
28+
}
29+
$this->setBranch($branch);
1730

18-
switch ($this->action) {
31+
$action = $this->action;
32+
switch ($action) {
1933
case 'close':
20-
$is_active = false;
21-
$title_text = pht('Close Branch');
22-
$body_text = pht(
23-
'Really close the branch "%s"?',
24-
$branch->getBasename());
25-
$button_text = pht('Close Branch');
26-
break;
2734
case 're-open':
28-
$is_active = true;
29-
$title_text = pht('Reopen Branch');
30-
$body_text = pht(
31-
'Really reopen the branch "%s"?',
32-
$branch->getBasename());
33-
$button_text = pht('Reopen Branch');
3435
break;
3536
default:
36-
throw new Exception("Unknown action '{$this->action}'!");
37-
break;
37+
return new Aphront404Response();
3838
}
3939

40-
if ($request->isDialogFormPost()) {
40+
$branch_uri = $this->getBranchViewURI($branch);
41+
if ($request->isFormPost()) {
42+
43+
if ($action == 're-open') {
44+
$is_active = 1;
45+
} else {
46+
$is_active = 0;
47+
}
48+
4149
id(new ReleephBranchEditor())
4250
->setActor($request->getUser())
4351
->setReleephBranch($branch)
44-
->changeBranchAccess($is_active ? 1 : 0);
52+
->changeBranchAccess($is_active);
4553

46-
return id(new AphrontReloadResponse())->setURI($done_uri);
54+
return id(new AphrontReloadResponse())->setURI($branch_uri);
4755
}
4856

49-
$dialog = new AphrontDialogView();
50-
$dialog
51-
->setUser($request->getUser())
57+
if ($action == 'close') {
58+
$title_text = pht('Really Close Branch?');
59+
$short = pht('Close Branch');
60+
$body_text = pht(
61+
'Really close the branch "%s"?',
62+
phutil_tag('strong', array(), $branch->getBasename()));
63+
$button_text = pht('Close Branch');
64+
} else {
65+
$title_text = pht('Really Reopen Branch?');
66+
$short = pht('Reopen Branch');
67+
$body_text = pht(
68+
'Really reopen the branch "%s"?',
69+
phutil_tag('strong', array(), $branch->getBasename()));
70+
$button_text = pht('Reopen Branch');
71+
}
72+
73+
return $this->newDialog()
5274
->setTitle($title_text)
75+
->setShortTitle($short)
5376
->appendChild($body_text)
5477
->addSubmitButton($button_text)
55-
->addCancelButton($done_uri);
56-
57-
return id(new AphrontDialogResponse())->setDialog($dialog);
78+
->addCancelButton($branch_uri);
5879
}
80+
5981
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
abstract class ReleephBranchController extends ReleephController {
4+
5+
private $branch;
6+
7+
public function setBranch($branch) {
8+
$this->branch = $branch;
9+
return $this;
10+
}
11+
12+
public function getBranch() {
13+
return $this->branch;
14+
}
15+
16+
protected function buildApplicationCrumbs() {
17+
$crumbs = parent::buildApplicationCrumbs();
18+
19+
$branch = $this->getBranch();
20+
if ($branch) {
21+
$product = $branch->getProduct();
22+
23+
$crumbs->addTextCrumb(
24+
$product->getName(),
25+
$this->getProductViewURI($product));
26+
27+
$crumbs->addTextCrumb(
28+
$branch->getName(),
29+
$this->getBranchViewURI($branch));
30+
}
31+
32+
return $crumbs;
33+
}
34+
35+
}

src/applications/releeph/controller/branch/ReleephBranchCreateController.php

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
<?php
22

3-
final class ReleephBranchCreateController extends ReleephProjectController {
3+
final class ReleephBranchCreateController extends ReleephProductController {
44

5-
public function processRequest() {
6-
$releeph_project = $this->getReleephProject();
5+
private $productID;
6+
7+
public function willProcessRequest(array $data) {
8+
$this->productID = $data['projectID'];
9+
}
710

11+
public function processRequest() {
812
$request = $this->getRequest();
13+
$viewer = $request->getUser();
14+
15+
$product = id(new ReleephProjectQuery())
16+
->setViewer($viewer)
17+
->withIDs(array($this->productID))
18+
->requireCapabilities(
19+
array(
20+
PhabricatorPolicyCapability::CAN_VIEW,
21+
PhabricatorPolicyCapability::CAN_EDIT,
22+
))
23+
->executeOne();
24+
if (!$product) {
25+
return new Aphront404Response();
26+
}
27+
$this->setProduct($product);
28+
929

1030
$cut_point = $request->getStr('cutPoint');
1131
$symbolic_name = $request->getStr('symbolicName');
1232

1333
if (!$cut_point) {
14-
$repository = $releeph_project->loadPhabricatorRepository();
34+
$repository = $product->loadPhabricatorRepository();
1535
switch ($repository->getVersionControlSystem()) {
1636
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
1737
break;
1838

1939
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
20-
$cut_point = $releeph_project->getTrunkBranch();
40+
$cut_point = $product->getTrunkBranch();
2141
break;
2242
}
2343
}
@@ -42,7 +62,7 @@ public function processRequest() {
4262
try {
4363
$finder = id(new ReleephCommitFinder())
4464
->setUser($request->getUser())
45-
->setReleephProject($releeph_project);
65+
->setReleephProject($product);
4666
$cut_commit = $finder->fromPartial($cut_point);
4767
} catch (Exception $e) {
4868
$e_cut = pht('Invalid');
@@ -52,7 +72,7 @@ public function processRequest() {
5272

5373
if (!$errors) {
5474
$branch = id(new ReleephBranchEditor())
55-
->setReleephProject($releeph_project)
75+
->setReleephProject($product)
5676
->setActor($request->getUser())
5777
->newBranchFromCommit(
5878
$cut_commit,
@@ -64,14 +84,7 @@ public function processRequest() {
6484
}
6585
}
6686

67-
$error_view = array();
68-
if ($errors) {
69-
$error_view = new AphrontErrorView();
70-
$error_view->setErrors($errors);
71-
}
72-
73-
$project_id = $releeph_project->getID();
74-
$project_uri = $this->getApplicationURI("project/{$project_id}/");
87+
$product_uri = $this->getProductViewURI($product);
7588

7689
$form = id(new AphrontFormView())
7790
->setUser($request->getUser())
@@ -95,16 +108,20 @@ public function processRequest() {
95108
->appendChild(
96109
id(new AphrontFormSubmitControl())
97110
->setValue(pht('Cut Branch'))
98-
->addCancelButton($project_uri));
111+
->addCancelButton($product_uri));
112+
113+
$box = id(new PHUIObjectBoxView())
114+
->setHeaderText(pht('New Branch'))
115+
->setFormErrors($errors)
116+
->appendChild($form);
99117

100118
$crumbs = $this->buildApplicationCrumbs();
101119
$crumbs->addTextCrumb(pht('New Branch'));
102120

103121
return $this->buildApplicationPage(
104122
array(
105123
$crumbs,
106-
$error_view,
107-
$form,
124+
$box,
108125
),
109126
array(
110127
'title' => pht('New Branch'),

0 commit comments

Comments
 (0)