@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+127 -84
+4 -2
src/__phutil_library_map__.php
··· 2514 2514 'ReleephPHIDTypeBranch' => 'applications/releeph/phid/ReleephPHIDTypeBranch.php', 2515 2515 'ReleephPHIDTypeProject' => 'applications/releeph/phid/ReleephPHIDTypeProject.php', 2516 2516 'ReleephPHIDTypeRequest' => 'applications/releeph/phid/ReleephPHIDTypeRequest.php', 2517 + 'ReleephProductActionController' => 'applications/releeph/controller/project/ReleephProductActionController.php', 2518 + 'ReleephProductController' => 'applications/releeph/controller/project/ReleephProductController.php', 2517 2519 'ReleephProject' => 'applications/releeph/storage/ReleephProject.php', 2518 - 'ReleephProjectActionController' => 'applications/releeph/controller/project/ReleephProjectActionController.php', 2519 2520 'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php', 2520 2521 'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php', 2521 2522 'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php', ··· 5487 5488 'ReleephPHIDTypeBranch' => 'PhabricatorPHIDType', 5488 5489 'ReleephPHIDTypeProject' => 'PhabricatorPHIDType', 5489 5490 'ReleephPHIDTypeRequest' => 'PhabricatorPHIDType', 5491 + 'ReleephProductActionController' => 'ReleephProductController', 5492 + 'ReleephProductController' => 'ReleephController', 5490 5493 'ReleephProject' => 5491 5494 array( 5492 5495 0 => 'ReleephDAO', 5493 5496 1 => 'PhabricatorPolicyInterface', 5494 5497 ), 5495 - 'ReleephProjectActionController' => 'ReleephProjectController', 5496 5498 'ReleephProjectController' => 'ReleephController', 5497 5499 'ReleephProjectCreateController' => 'ReleephProjectController', 5498 5500 'ReleephProjectEditController' => 'ReleephProjectController',
+1 -1
src/applications/releeph/application/PhabricatorApplicationReleeph.php
··· 41 41 '(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephProjectViewController', 42 42 'edit/' => 'ReleephProjectEditController', 43 43 'cutbranch/' => 'ReleephBranchCreateController', 44 - 'action/(?P<action>.+)/' => 'ReleephProjectActionController', 44 + 'action/(?P<action>.+)/' => 'ReleephProductActionController', 45 45 'history/' => 'ReleephProjectHistoryController', 46 46 ), 47 47 ),
+78
src/applications/releeph/controller/project/ReleephProductActionController.php
··· 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 + }
+30
src/applications/releeph/controller/project/ReleephProductController.php
··· 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 + }
-58
src/applications/releeph/controller/project/ReleephProjectActionController.php
··· 1 - <?php 2 - 3 - final class ReleephProjectActionController extends ReleephProjectController { 4 - 5 - private $action; 6 - 7 - public function willProcessRequest(array $data) { 8 - parent::willProcessRequest($data); 9 - $this->action = $data['action']; 10 - } 11 - 12 - public function processRequest() { 13 - $request = $this->getRequest(); 14 - $viewer = $request->getUser(); 15 - 16 - $action = $this->action; 17 - 18 - $project = id(new ReleephProjectQuery()) 19 - ->withIDs(array($this->getReleephProject()->getID())) 20 - ->requireCapabilities( 21 - array( 22 - PhabricatorPolicyCapability::CAN_VIEW, 23 - PhabricatorPolicyCapability::CAN_EDIT, 24 - )) 25 - ->setViewer($viewer) 26 - ->executeOne(); 27 - if (!$project) { 28 - return new Aphront404Response(); 29 - } 30 - 31 - $project_id = $project->getID(); 32 - $project_uri = $this->getApplicationURI("project/{$project_id}/"); 33 - 34 - switch ($action) { 35 - case 'deactivate': 36 - if ($request->isDialogFormPost()) { 37 - $project->deactivate($viewer)->save(); 38 - return id(new AphrontRedirectResponse())->setURI($project_uri); 39 - } 40 - 41 - $dialog = id(new AphrontDialogView()) 42 - ->setUser($request->getUser()) 43 - ->setTitle(pht('Really deactivate Releeph Project?')) 44 - ->appendChild(phutil_tag( 45 - 'p', 46 - array(), 47 - pht('Really deactivate the Releeph project: %s?', 48 - $project->getName()))) 49 - ->addSubmitButton(pht('Deactivate Project')) 50 - ->addCancelButton($project_uri); 51 - 52 - return id(new AphrontDialogResponse())->setDialog($dialog); 53 - case 'activate': 54 - $project->setIsActive(1)->save(); 55 - return id(new AphrontRedirectResponse())->setURI($project_uri); 56 - } 57 - } 58 - }
+14 -23
src/applications/releeph/controller/project/ReleephProjectViewController.php
··· 177 177 PhabricatorPolicyCapability::CAN_EDIT); 178 178 179 179 $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 - 187 180 $history_uri = $this->getApplicationURI("project/{$id}/history/"); 188 181 189 182 $actions->addAction( ··· 195 188 ->setWorkflow(!$can_edit)); 196 189 197 190 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'; 205 194 } 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'; 215 198 } 199 + 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)); 216 207 217 208 $actions->addAction( 218 209 id(new PhabricatorActionView())