Skip to content

Commit a5ad923

Browse files
author
epriestley
committed
Modernize Releeph "Product Activate" controller
Summary: Ref T3549. A few things here: - Releeph has an object called a "Project". We'd like to call this a "Product" instead. See T3549. Rename easy instances that don't break URIs. - Releeph has a "ProjectController" which tries to be smart about loading objects. However, it's big and messy and doesn't have the finesse to do policies or `needX(...)` correctly. It also generates URIs which collide with one another. Introduce "ProductController" to start to move away from it. - Some small modernizations to this controller to take advantage of newer infrastructure (like easier dialog rendering). Test Plan: Deactivated and reactivated products. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3549 Differential Revision: https://secure.phabricator.com/D8632
1 parent 6c8cef3 commit a5ad923

File tree

6 files changed

+127
-84
lines changed

6 files changed

+127
-84
lines changed

src/__phutil_library_map__.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,8 +2514,9 @@
25142514
'ReleephPHIDTypeBranch' => 'applications/releeph/phid/ReleephPHIDTypeBranch.php',
25152515
'ReleephPHIDTypeProject' => 'applications/releeph/phid/ReleephPHIDTypeProject.php',
25162516
'ReleephPHIDTypeRequest' => 'applications/releeph/phid/ReleephPHIDTypeRequest.php',
2517+
'ReleephProductActionController' => 'applications/releeph/controller/project/ReleephProductActionController.php',
2518+
'ReleephProductController' => 'applications/releeph/controller/project/ReleephProductController.php',
25172519
'ReleephProject' => 'applications/releeph/storage/ReleephProject.php',
2518-
'ReleephProjectActionController' => 'applications/releeph/controller/project/ReleephProjectActionController.php',
25192520
'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php',
25202521
'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php',
25212522
'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php',
@@ -5487,12 +5488,13 @@
54875488
'ReleephPHIDTypeBranch' => 'PhabricatorPHIDType',
54885489
'ReleephPHIDTypeProject' => 'PhabricatorPHIDType',
54895490
'ReleephPHIDTypeRequest' => 'PhabricatorPHIDType',
5491+
'ReleephProductActionController' => 'ReleephProductController',
5492+
'ReleephProductController' => 'ReleephController',
54905493
'ReleephProject' =>
54915494
array(
54925495
0 => 'ReleephDAO',
54935496
1 => 'PhabricatorPolicyInterface',
54945497
),
5495-
'ReleephProjectActionController' => 'ReleephProjectController',
54965498
'ReleephProjectController' => 'ReleephController',
54975499
'ReleephProjectCreateController' => 'ReleephProjectController',
54985500
'ReleephProjectEditController' => 'ReleephProjectController',

src/applications/releeph/application/PhabricatorApplicationReleeph.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getRoutes() {
4141
'(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephProjectViewController',
4242
'edit/' => 'ReleephProjectEditController',
4343
'cutbranch/' => 'ReleephBranchCreateController',
44-
'action/(?P<action>.+)/' => 'ReleephProjectActionController',
44+
'action/(?P<action>.+)/' => 'ReleephProductActionController',
4545
'history/' => 'ReleephProjectHistoryController',
4646
),
4747
),
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
final class ReleephProductActionController extends ReleephProductController {
4+
5+
private $id;
6+
private $action;
7+
8+
public function willProcessRequest(array $data) {
9+
$this->id = $data['projectID'];
10+
$this->action = $data['action'];
11+
}
12+
13+
public function processRequest() {
14+
$request = $this->getRequest();
15+
$viewer = $request->getUser();
16+
17+
$product = id(new ReleephProjectQuery())
18+
->withIDs(array($this->id))
19+
->requireCapabilities(
20+
array(
21+
PhabricatorPolicyCapability::CAN_VIEW,
22+
PhabricatorPolicyCapability::CAN_EDIT,
23+
))
24+
->setViewer($viewer)
25+
->executeOne();
26+
if (!$product) {
27+
return new Aphront404Response();
28+
}
29+
30+
$this->setProduct($product);
31+
32+
$product_id = $product->getID();
33+
$product_uri = $this->getProductViewURI($product);
34+
35+
$action = $this->action;
36+
switch ($action) {
37+
case 'deactivate':
38+
case 'activate':
39+
break;
40+
default:
41+
throw new Aphront404Response();
42+
}
43+
44+
if ($request->isFormPost()) {
45+
if ($action == 'activate') {
46+
$product->setIsActive(1)->save();
47+
} else {
48+
$product->deactivate($viewer)->save();
49+
}
50+
51+
return id(new AphrontRedirectResponse())->setURI($product_uri);
52+
}
53+
54+
if ($action == 'activate') {
55+
$title = pht('Activate Product?');
56+
$body = pht(
57+
'Reactivate the product %s?',
58+
phutil_tag('strong', array(), $product->getName()));
59+
$submit = pht('Reactivate Product');
60+
$short = pht('Deactivate');
61+
} else {
62+
$title = pht('Really Deactivate Product?');
63+
$body = pht(
64+
'Really deactivate the product %s?',
65+
phutil_tag('strong', array(), $product->getName()));
66+
$submit = pht('Deactivate Product');
67+
$short = pht('Activate');
68+
}
69+
70+
return $this->newDialog()
71+
->setTitle($title)
72+
->setShortTitle($short)
73+
->appendParagraph($body)
74+
->addSubmitButton($submit)
75+
->addCancelButton($product_uri);
76+
}
77+
78+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
abstract class ReleephProductController extends ReleephController {
4+
5+
private $product;
6+
7+
protected function setProduct(ReleephProject $product) {
8+
$this->product = $product;
9+
return $this;
10+
}
11+
12+
protected function getProductViewURI(ReleephProject $product) {
13+
return $this->getApplicationURI('project/'.$product->getID().'/');
14+
}
15+
16+
protected function buildApplicationCrumbs() {
17+
$crumbs = parent::buildApplicationCrumbs();
18+
19+
$product = $this->product;
20+
if ($product) {
21+
$crumbs->addTextCrumb(
22+
$product->getName(),
23+
$this->getProductViewURI($product));
24+
}
25+
26+
return $crumbs;
27+
}
28+
29+
30+
}

src/applications/releeph/controller/project/ReleephProjectActionController.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/applications/releeph/controller/project/ReleephProjectViewController.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,6 @@ private function renderPreface() {
177177
PhabricatorPolicyCapability::CAN_EDIT);
178178

179179
$edit_uri = $this->getApplicationURI("project/{$id}/edit/");
180-
181-
$deactivate_uri = "project/{$id}/action/deactivate/";
182-
$deactivate_uri = $this->getApplicationURI($deactivate_uri);
183-
184-
$reactivate_uri = "project/{$id}/action/activate/";
185-
$reactivate_uri = $this->getApplicationURI($reactivate_uri);
186-
187180
$history_uri = $this->getApplicationURI("project/{$id}/history/");
188181

189182
$actions->addAction(
@@ -195,25 +188,23 @@ private function renderPreface() {
195188
->setWorkflow(!$can_edit));
196189

197190
if ($project->getIsActive()) {
198-
$actions->addAction(
199-
id(new PhabricatorActionView())
200-
->setName(pht('Deactivate Project'))
201-
->setHref($deactivate_uri)
202-
->setIcon('delete')
203-
->setDisabled(!$can_edit)
204-
->setWorkflow(true));
191+
$status_name = pht('Deactivate Product');
192+
$status_href = "project/{$id}/action/deactivate/";
193+
$status_icon = 'delete';
205194
} else {
206-
$actions->addAction(
207-
id(new PhabricatorActionView())
208-
->setName(pht('Reactivate Project'))
209-
->setHref($reactivate_uri)
210-
->setIcon('new')
211-
->setUser($viewer)
212-
->setRenderAsForm(true)
213-
->setDisabled(!$can_edit)
214-
->setWorkflow(true));
195+
$status_name = pht('Reactivate Product');
196+
$status_href = "project/{$id}/action/activate/";
197+
$status_icon = 'new';
215198
}
216199

200+
$actions->addAction(
201+
id(new PhabricatorActionView())
202+
->setName($status_name)
203+
->setHref($this->getApplicationURI($status_href))
204+
->setIcon($status_icon)
205+
->setDisabled(!$can_edit)
206+
->setWorkflow(true));
207+
217208
$actions->addAction(
218209
id(new PhabricatorActionView())
219210
->setName(pht('View History'))

0 commit comments

Comments
 (0)