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
|
@ -2514,8 +2514,9 @@ phutil_register_library_map(array(
|
||||||
'ReleephPHIDTypeBranch' => 'applications/releeph/phid/ReleephPHIDTypeBranch.php',
|
'ReleephPHIDTypeBranch' => 'applications/releeph/phid/ReleephPHIDTypeBranch.php',
|
||||||
'ReleephPHIDTypeProject' => 'applications/releeph/phid/ReleephPHIDTypeProject.php',
|
'ReleephPHIDTypeProject' => 'applications/releeph/phid/ReleephPHIDTypeProject.php',
|
||||||
'ReleephPHIDTypeRequest' => 'applications/releeph/phid/ReleephPHIDTypeRequest.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',
|
'ReleephProject' => 'applications/releeph/storage/ReleephProject.php',
|
||||||
'ReleephProjectActionController' => 'applications/releeph/controller/project/ReleephProjectActionController.php',
|
|
||||||
'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php',
|
'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php',
|
||||||
'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php',
|
'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php',
|
||||||
'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php',
|
'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php',
|
||||||
|
@ -5487,12 +5488,13 @@ phutil_register_library_map(array(
|
||||||
'ReleephPHIDTypeBranch' => 'PhabricatorPHIDType',
|
'ReleephPHIDTypeBranch' => 'PhabricatorPHIDType',
|
||||||
'ReleephPHIDTypeProject' => 'PhabricatorPHIDType',
|
'ReleephPHIDTypeProject' => 'PhabricatorPHIDType',
|
||||||
'ReleephPHIDTypeRequest' => 'PhabricatorPHIDType',
|
'ReleephPHIDTypeRequest' => 'PhabricatorPHIDType',
|
||||||
|
'ReleephProductActionController' => 'ReleephProductController',
|
||||||
|
'ReleephProductController' => 'ReleephController',
|
||||||
'ReleephProject' =>
|
'ReleephProject' =>
|
||||||
array(
|
array(
|
||||||
0 => 'ReleephDAO',
|
0 => 'ReleephDAO',
|
||||||
1 => 'PhabricatorPolicyInterface',
|
1 => 'PhabricatorPolicyInterface',
|
||||||
),
|
),
|
||||||
'ReleephProjectActionController' => 'ReleephProjectController',
|
|
||||||
'ReleephProjectController' => 'ReleephController',
|
'ReleephProjectController' => 'ReleephController',
|
||||||
'ReleephProjectCreateController' => 'ReleephProjectController',
|
'ReleephProjectCreateController' => 'ReleephProjectController',
|
||||||
'ReleephProjectEditController' => 'ReleephProjectController',
|
'ReleephProjectEditController' => 'ReleephProjectController',
|
||||||
|
|
|
@ -41,7 +41,7 @@ final class PhabricatorApplicationReleeph extends PhabricatorApplication {
|
||||||
'(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephProjectViewController',
|
'(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephProjectViewController',
|
||||||
'edit/' => 'ReleephProjectEditController',
|
'edit/' => 'ReleephProjectEditController',
|
||||||
'cutbranch/' => 'ReleephBranchCreateController',
|
'cutbranch/' => 'ReleephBranchCreateController',
|
||||||
'action/(?P<action>.+)/' => 'ReleephProjectActionController',
|
'action/(?P<action>.+)/' => 'ReleephProductActionController',
|
||||||
'history/' => 'ReleephProjectHistoryController',
|
'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);
|
PhabricatorPolicyCapability::CAN_EDIT);
|
||||||
|
|
||||||
$edit_uri = $this->getApplicationURI("project/{$id}/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/");
|
$history_uri = $this->getApplicationURI("project/{$id}/history/");
|
||||||
|
|
||||||
$actions->addAction(
|
$actions->addAction(
|
||||||
|
@ -195,25 +188,23 @@ final class ReleephProjectViewController extends ReleephProjectController
|
||||||
->setWorkflow(!$can_edit));
|
->setWorkflow(!$can_edit));
|
||||||
|
|
||||||
if ($project->getIsActive()) {
|
if ($project->getIsActive()) {
|
||||||
$actions->addAction(
|
$status_name = pht('Deactivate Product');
|
||||||
id(new PhabricatorActionView())
|
$status_href = "project/{$id}/action/deactivate/";
|
||||||
->setName(pht('Deactivate Project'))
|
$status_icon = 'delete';
|
||||||
->setHref($deactivate_uri)
|
|
||||||
->setIcon('delete')
|
|
||||||
->setDisabled(!$can_edit)
|
|
||||||
->setWorkflow(true));
|
|
||||||
} else {
|
} else {
|
||||||
$actions->addAction(
|
$status_name = pht('Reactivate Product');
|
||||||
id(new PhabricatorActionView())
|
$status_href = "project/{$id}/action/activate/";
|
||||||
->setName(pht('Reactivate Project'))
|
$status_icon = 'new';
|
||||||
->setHref($reactivate_uri)
|
|
||||||
->setIcon('new')
|
|
||||||
->setUser($viewer)
|
|
||||||
->setRenderAsForm(true)
|
|
||||||
->setDisabled(!$can_edit)
|
|
||||||
->setWorkflow(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$actions->addAction(
|
||||||
|
id(new PhabricatorActionView())
|
||||||
|
->setName($status_name)
|
||||||
|
->setHref($this->getApplicationURI($status_href))
|
||||||
|
->setIcon($status_icon)
|
||||||
|
->setDisabled(!$can_edit)
|
||||||
|
->setWorkflow(true));
|
||||||
|
|
||||||
$actions->addAction(
|
$actions->addAction(
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
->setName(pht('View History'))
|
->setName(pht('View History'))
|
||||||
|
|
Loading…
Reference in a new issue