mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
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
This commit is contained in:
parent
6c8cef3bee
commit
a5ad923573
6 changed files with 127 additions and 84 deletions
|
@ -2514,8 +2514,9 @@ phutil_register_library_map(array(
|
|||
'ReleephPHIDTypeBranch' => 'applications/releeph/phid/ReleephPHIDTypeBranch.php',
|
||||
'ReleephPHIDTypeProject' => 'applications/releeph/phid/ReleephPHIDTypeProject.php',
|
||||
'ReleephPHIDTypeRequest' => 'applications/releeph/phid/ReleephPHIDTypeRequest.php',
|
||||
'ReleephProductActionController' => 'applications/releeph/controller/project/ReleephProductActionController.php',
|
||||
'ReleephProductController' => 'applications/releeph/controller/project/ReleephProductController.php',
|
||||
'ReleephProject' => 'applications/releeph/storage/ReleephProject.php',
|
||||
'ReleephProjectActionController' => 'applications/releeph/controller/project/ReleephProjectActionController.php',
|
||||
'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php',
|
||||
'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php',
|
||||
'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php',
|
||||
|
@ -5487,12 +5488,13 @@ phutil_register_library_map(array(
|
|||
'ReleephPHIDTypeBranch' => 'PhabricatorPHIDType',
|
||||
'ReleephPHIDTypeProject' => 'PhabricatorPHIDType',
|
||||
'ReleephPHIDTypeRequest' => 'PhabricatorPHIDType',
|
||||
'ReleephProductActionController' => 'ReleephProductController',
|
||||
'ReleephProductController' => 'ReleephController',
|
||||
'ReleephProject' =>
|
||||
array(
|
||||
0 => 'ReleephDAO',
|
||||
1 => 'PhabricatorPolicyInterface',
|
||||
),
|
||||
'ReleephProjectActionController' => 'ReleephProjectController',
|
||||
'ReleephProjectController' => 'ReleephController',
|
||||
'ReleephProjectCreateController' => 'ReleephProjectController',
|
||||
'ReleephProjectEditController' => 'ReleephProjectController',
|
||||
|
|
|
@ -41,7 +41,7 @@ final class PhabricatorApplicationReleeph extends PhabricatorApplication {
|
|||
'(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephProjectViewController',
|
||||
'edit/' => 'ReleephProjectEditController',
|
||||
'cutbranch/' => 'ReleephBranchCreateController',
|
||||
'action/(?P<action>.+)/' => 'ReleephProjectActionController',
|
||||
'action/(?P<action>.+)/' => 'ReleephProductActionController',
|
||||
'history/' => 'ReleephProjectHistoryController',
|
||||
),
|
||||
),
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
final class ReleephProductActionController extends ReleephProductController {
|
||||
|
||||
private $id;
|
||||
private $action;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['projectID'];
|
||||
$this->action = $data['action'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getUser();
|
||||
|
||||
$product = id(new ReleephProjectQuery())
|
||||
->withIDs(array($this->id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->setViewer($viewer)
|
||||
->executeOne();
|
||||
if (!$product) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$this->setProduct($product);
|
||||
|
||||
$product_id = $product->getID();
|
||||
$product_uri = $this->getProductViewURI($product);
|
||||
|
||||
$action = $this->action;
|
||||
switch ($action) {
|
||||
case 'deactivate':
|
||||
case 'activate':
|
||||
break;
|
||||
default:
|
||||
throw new Aphront404Response();
|
||||
}
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
if ($action == 'activate') {
|
||||
$product->setIsActive(1)->save();
|
||||
} else {
|
||||
$product->deactivate($viewer)->save();
|
||||
}
|
||||
|
||||
return id(new AphrontRedirectResponse())->setURI($product_uri);
|
||||
}
|
||||
|
||||
if ($action == 'activate') {
|
||||
$title = pht('Activate Product?');
|
||||
$body = pht(
|
||||
'Reactivate the product %s?',
|
||||
phutil_tag('strong', array(), $product->getName()));
|
||||
$submit = pht('Reactivate Product');
|
||||
$short = pht('Deactivate');
|
||||
} else {
|
||||
$title = pht('Really Deactivate Product?');
|
||||
$body = pht(
|
||||
'Really deactivate the product %s?',
|
||||
phutil_tag('strong', array(), $product->getName()));
|
||||
$submit = pht('Deactivate Product');
|
||||
$short = pht('Activate');
|
||||
}
|
||||
|
||||
return $this->newDialog()
|
||||
->setTitle($title)
|
||||
->setShortTitle($short)
|
||||
->appendParagraph($body)
|
||||
->addSubmitButton($submit)
|
||||
->addCancelButton($product_uri);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
abstract class ReleephProductController extends ReleephController {
|
||||
|
||||
private $product;
|
||||
|
||||
protected function setProduct(ReleephProject $product) {
|
||||
$this->product = $product;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getProductViewURI(ReleephProject $product) {
|
||||
return $this->getApplicationURI('project/'.$product->getID().'/');
|
||||
}
|
||||
|
||||
protected function buildApplicationCrumbs() {
|
||||
$crumbs = parent::buildApplicationCrumbs();
|
||||
|
||||
$product = $this->product;
|
||||
if ($product) {
|
||||
$crumbs->addTextCrumb(
|
||||
$product->getName(),
|
||||
$this->getProductViewURI($product));
|
||||
}
|
||||
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class ReleephProjectActionController extends ReleephProjectController {
|
||||
|
||||
private $action;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
parent::willProcessRequest($data);
|
||||
$this->action = $data['action'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getUser();
|
||||
|
||||
$action = $this->action;
|
||||
|
||||
$project = id(new ReleephProjectQuery())
|
||||
->withIDs(array($this->getReleephProject()->getID()))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->setViewer($viewer)
|
||||
->executeOne();
|
||||
if (!$project) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$project_id = $project->getID();
|
||||
$project_uri = $this->getApplicationURI("project/{$project_id}/");
|
||||
|
||||
switch ($action) {
|
||||
case 'deactivate':
|
||||
if ($request->isDialogFormPost()) {
|
||||
$project->deactivate($viewer)->save();
|
||||
return id(new AphrontRedirectResponse())->setURI($project_uri);
|
||||
}
|
||||
|
||||
$dialog = id(new AphrontDialogView())
|
||||
->setUser($request->getUser())
|
||||
->setTitle(pht('Really deactivate Releeph Project?'))
|
||||
->appendChild(phutil_tag(
|
||||
'p',
|
||||
array(),
|
||||
pht('Really deactivate the Releeph project: %s?',
|
||||
$project->getName())))
|
||||
->addSubmitButton(pht('Deactivate Project'))
|
||||
->addCancelButton($project_uri);
|
||||
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
case 'activate':
|
||||
$project->setIsActive(1)->save();
|
||||
return id(new AphrontRedirectResponse())->setURI($project_uri);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -177,13 +177,6 @@ final class ReleephProjectViewController extends ReleephProjectController
|
|||
PhabricatorPolicyCapability::CAN_EDIT);
|
||||
|
||||
$edit_uri = $this->getApplicationURI("project/{$id}/edit/");
|
||||
|
||||
$deactivate_uri = "project/{$id}/action/deactivate/";
|
||||
$deactivate_uri = $this->getApplicationURI($deactivate_uri);
|
||||
|
||||
$reactivate_uri = "project/{$id}/action/activate/";
|
||||
$reactivate_uri = $this->getApplicationURI($reactivate_uri);
|
||||
|
||||
$history_uri = $this->getApplicationURI("project/{$id}/history/");
|
||||
|
||||
$actions->addAction(
|
||||
|
@ -195,25 +188,23 @@ final class ReleephProjectViewController extends ReleephProjectController
|
|||
->setWorkflow(!$can_edit));
|
||||
|
||||
if ($project->getIsActive()) {
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('Deactivate Project'))
|
||||
->setHref($deactivate_uri)
|
||||
->setIcon('delete')
|
||||
->setDisabled(!$can_edit)
|
||||
->setWorkflow(true));
|
||||
$status_name = pht('Deactivate Product');
|
||||
$status_href = "project/{$id}/action/deactivate/";
|
||||
$status_icon = 'delete';
|
||||
} else {
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('Reactivate Project'))
|
||||
->setHref($reactivate_uri)
|
||||
->setIcon('new')
|
||||
->setUser($viewer)
|
||||
->setRenderAsForm(true)
|
||||
->setDisabled(!$can_edit)
|
||||
->setWorkflow(true));
|
||||
$status_name = pht('Reactivate Product');
|
||||
$status_href = "project/{$id}/action/activate/";
|
||||
$status_icon = 'new';
|
||||
}
|
||||
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName($status_name)
|
||||
->setHref($this->getApplicationURI($status_href))
|
||||
->setIcon($status_icon)
|
||||
->setDisabled(!$can_edit)
|
||||
->setWorkflow(true));
|
||||
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('View History'))
|
||||
|
|
Loading…
Reference in a new issue