mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-03 11:21:01 +01:00
Reduce code duplication in Phortune account controllers
Summary: Ref T12451. This is a GREAT comment (A++) but we only need one copy of it. This uses a pattern similar to Projects, which is a little weird but works well enough. Test Plan: - Viewed all four tabs of an account. - Viewed a page with a bad account ID which 404'd properly. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12451 Differential Revision: https://secure.phabricator.com/D17694
This commit is contained in:
parent
7fbb5f2d92
commit
aec19d2acf
7 changed files with 87 additions and 104 deletions
|
@ -4338,6 +4338,7 @@ phutil_register_library_map(array(
|
||||||
'PhortuneAccountAddManagerController' => 'applications/phortune/controller/account/PhortuneAccountAddManagerController.php',
|
'PhortuneAccountAddManagerController' => 'applications/phortune/controller/account/PhortuneAccountAddManagerController.php',
|
||||||
'PhortuneAccountBillingController' => 'applications/phortune/controller/account/PhortuneAccountBillingController.php',
|
'PhortuneAccountBillingController' => 'applications/phortune/controller/account/PhortuneAccountBillingController.php',
|
||||||
'PhortuneAccountChargeListController' => 'applications/phortune/controller/account/PhortuneAccountChargeListController.php',
|
'PhortuneAccountChargeListController' => 'applications/phortune/controller/account/PhortuneAccountChargeListController.php',
|
||||||
|
'PhortuneAccountController' => 'applications/phortune/controller/account/PhortuneAccountController.php',
|
||||||
'PhortuneAccountEditController' => 'applications/phortune/controller/account/PhortuneAccountEditController.php',
|
'PhortuneAccountEditController' => 'applications/phortune/controller/account/PhortuneAccountEditController.php',
|
||||||
'PhortuneAccountEditEngine' => 'applications/phortune/editor/PhortuneAccountEditEngine.php',
|
'PhortuneAccountEditEngine' => 'applications/phortune/editor/PhortuneAccountEditEngine.php',
|
||||||
'PhortuneAccountEditor' => 'applications/phortune/editor/PhortuneAccountEditor.php',
|
'PhortuneAccountEditor' => 'applications/phortune/editor/PhortuneAccountEditor.php',
|
||||||
|
@ -9815,6 +9816,7 @@ phutil_register_library_map(array(
|
||||||
'PhortuneAccountAddManagerController' => 'PhortuneController',
|
'PhortuneAccountAddManagerController' => 'PhortuneController',
|
||||||
'PhortuneAccountBillingController' => 'PhortuneAccountProfileController',
|
'PhortuneAccountBillingController' => 'PhortuneAccountProfileController',
|
||||||
'PhortuneAccountChargeListController' => 'PhortuneController',
|
'PhortuneAccountChargeListController' => 'PhortuneController',
|
||||||
|
'PhortuneAccountController' => 'PhortuneController',
|
||||||
'PhortuneAccountEditController' => 'PhortuneController',
|
'PhortuneAccountEditController' => 'PhortuneController',
|
||||||
'PhortuneAccountEditEngine' => 'PhabricatorEditEngine',
|
'PhortuneAccountEditEngine' => 'PhabricatorEditEngine',
|
||||||
'PhortuneAccountEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PhortuneAccountEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
|
@ -9823,7 +9825,7 @@ phutil_register_library_map(array(
|
||||||
'PhortuneAccountManagerController' => 'PhortuneAccountProfileController',
|
'PhortuneAccountManagerController' => 'PhortuneAccountProfileController',
|
||||||
'PhortuneAccountNameTransaction' => 'PhortuneAccountTransactionType',
|
'PhortuneAccountNameTransaction' => 'PhortuneAccountTransactionType',
|
||||||
'PhortuneAccountPHIDType' => 'PhabricatorPHIDType',
|
'PhortuneAccountPHIDType' => 'PhabricatorPHIDType',
|
||||||
'PhortuneAccountProfileController' => 'PhortuneController',
|
'PhortuneAccountProfileController' => 'PhortuneAccountController',
|
||||||
'PhortuneAccountQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhortuneAccountQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhortuneAccountSubscriptionController' => 'PhortuneAccountProfileController',
|
'PhortuneAccountSubscriptionController' => 'PhortuneAccountProfileController',
|
||||||
'PhortuneAccountTransaction' => 'PhabricatorModularTransaction',
|
'PhortuneAccountTransaction' => 'PhabricatorModularTransaction',
|
||||||
|
|
|
@ -4,29 +4,12 @@ final class PhortuneAccountBillingController
|
||||||
extends PhortuneAccountProfileController {
|
extends PhortuneAccountProfileController {
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$viewer = $this->getViewer();
|
$response = $this->loadAccount();
|
||||||
|
if ($response) {
|
||||||
// TODO: Currently, you must be able to edit an account to view the detail
|
return $response;
|
||||||
// page, because the account must be broadly visible so merchants can
|
|
||||||
// process orders but merchants should not be able to see all the details
|
|
||||||
// of an account. Ideally this page should be visible to merchants, too,
|
|
||||||
// just with less information.
|
|
||||||
$can_edit = true;
|
|
||||||
|
|
||||||
$account = id(new PhortuneAccountQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withIDs(array($request->getURIData('id')))
|
|
||||||
->requireCapabilities(
|
|
||||||
array(
|
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
|
||||||
))
|
|
||||||
->executeOne();
|
|
||||||
if (!$account) {
|
|
||||||
return new Aphront404Response();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setAccount($account);
|
$account = $this->getAccount();
|
||||||
$title = $account->getName();
|
$title = $account->getName();
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class PhortuneAccountController
|
||||||
|
extends PhortuneController {
|
||||||
|
|
||||||
|
private $account;
|
||||||
|
|
||||||
|
protected function getAccount() {
|
||||||
|
return $this->account;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildApplicationCrumbs() {
|
||||||
|
$crumbs = parent::buildApplicationCrumbs();
|
||||||
|
|
||||||
|
$account = $this->getAccount();
|
||||||
|
if ($account) {
|
||||||
|
$crumbs->addTextCrumb($account->getName(), $account->getURI());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $crumbs;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function loadAccount() {
|
||||||
|
// TODO: Currently, you must be able to edit an account to view the detail
|
||||||
|
// page, because the account must be broadly visible so merchants can
|
||||||
|
// process orders but merchants should not be able to see all the details
|
||||||
|
// of an account. Ideally the profile pages should be visible to merchants,
|
||||||
|
// too, just with less information.
|
||||||
|
return $this->loadAccountForEdit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function loadAccountForEdit() {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
$request = $this->getRequest();
|
||||||
|
|
||||||
|
$account_id = $request->getURIData('accountID');
|
||||||
|
if (!$account_id) {
|
||||||
|
$account_id = $request->getURIData('id');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$account_id) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
$account = id(new PhortuneAccountQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withIDs(array($account_id))
|
||||||
|
->requireCapabilities(
|
||||||
|
array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
))
|
||||||
|
->executeOne();
|
||||||
|
if (!$account) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->account = $account;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,29 +4,12 @@ final class PhortuneAccountManagerController
|
||||||
extends PhortuneAccountProfileController {
|
extends PhortuneAccountProfileController {
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$viewer = $this->getViewer();
|
$response = $this->loadAccount();
|
||||||
|
if ($response) {
|
||||||
// TODO: Currently, you must be able to edit an account to view the detail
|
return $response;
|
||||||
// page, because the account must be broadly visible so merchants can
|
|
||||||
// process orders but merchants should not be able to see all the details
|
|
||||||
// of an account. Ideally this page should be visible to merchants, too,
|
|
||||||
// just with less information.
|
|
||||||
$can_edit = true;
|
|
||||||
|
|
||||||
$account = id(new PhortuneAccountQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withIDs(array($request->getURIData('id')))
|
|
||||||
->requireCapabilities(
|
|
||||||
array(
|
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
|
||||||
))
|
|
||||||
->executeOne();
|
|
||||||
if (!$account) {
|
|
||||||
return new Aphront404Response();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setAccount($account);
|
$account = $this->getAccount();
|
||||||
$title = $account->getName();
|
$title = $account->getName();
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
|
@ -66,6 +49,7 @@ final class PhortuneAccountManagerController
|
||||||
->setText(pht('New Manager'))
|
->setText(pht('New Manager'))
|
||||||
->setIcon('fa-plus')
|
->setIcon('fa-plus')
|
||||||
->setWorkflow(true)
|
->setWorkflow(true)
|
||||||
|
->setDisabled(!$can_edit)
|
||||||
->setHref("/phortune/account/manager/add/{$id}/");
|
->setHref("/phortune/account/manager/add/{$id}/");
|
||||||
|
|
||||||
$header = id(new PHUIHeaderView())
|
$header = id(new PHUIHeaderView())
|
||||||
|
|
|
@ -1,18 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
abstract class PhortuneAccountProfileController
|
abstract class PhortuneAccountProfileController
|
||||||
extends PhortuneController {
|
extends PhortuneAccountController {
|
||||||
|
|
||||||
private $account;
|
|
||||||
|
|
||||||
public function setAccount(PhortuneAccount $account) {
|
|
||||||
$this->account = $account;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAccount() {
|
|
||||||
return $this->account;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function buildApplicationMenu() {
|
public function buildApplicationMenu() {
|
||||||
return $this->buildSideNavView()->getMenu();
|
return $this->buildSideNavView()->getMenu();
|
||||||
|
@ -34,12 +23,6 @@ abstract class PhortuneAccountProfileController
|
||||||
protected function buildApplicationCrumbs() {
|
protected function buildApplicationCrumbs() {
|
||||||
$crumbs = parent::buildApplicationCrumbs();
|
$crumbs = parent::buildApplicationCrumbs();
|
||||||
$crumbs->setBorder(true);
|
$crumbs->setBorder(true);
|
||||||
|
|
||||||
$account = $this->getAccount();
|
|
||||||
if ($account) {
|
|
||||||
$crumbs->addTextCrumb($account->getName(), $account->getURI());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $crumbs;
|
return $crumbs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,29 +4,12 @@ final class PhortuneAccountSubscriptionController
|
||||||
extends PhortuneAccountProfileController {
|
extends PhortuneAccountProfileController {
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$viewer = $this->getViewer();
|
$response = $this->loadAccount();
|
||||||
|
if ($response) {
|
||||||
// TODO: Currently, you must be able to edit an account to view the detail
|
return $response;
|
||||||
// page, because the account must be broadly visible so merchants can
|
|
||||||
// process orders but merchants should not be able to see all the details
|
|
||||||
// of an account. Ideally this page should be visible to merchants, too,
|
|
||||||
// just with less information.
|
|
||||||
$can_edit = true;
|
|
||||||
|
|
||||||
$account = id(new PhortuneAccountQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withIDs(array($request->getURIData('id')))
|
|
||||||
->requireCapabilities(
|
|
||||||
array(
|
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
|
||||||
))
|
|
||||||
->executeOne();
|
|
||||||
if (!$account) {
|
|
||||||
return new Aphront404Response();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setAccount($account);
|
$account = $this->getAccount();
|
||||||
$title = $account->getName();
|
$title = $account->getName();
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
|
|
|
@ -4,32 +4,16 @@ final class PhortuneAccountViewController
|
||||||
extends PhortuneAccountProfileController {
|
extends PhortuneAccountProfileController {
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$viewer = $this->getViewer();
|
$response = $this->loadAccount();
|
||||||
$id = $request->getURIData('accountID');
|
if ($response) {
|
||||||
|
return $response;
|
||||||
// TODO: Currently, you must be able to edit an account to view the detail
|
|
||||||
// page, because the account must be broadly visible so merchants can
|
|
||||||
// process orders but merchants should not be able to see all the details
|
|
||||||
// of an account. Ideally this page should be visible to merchants, too,
|
|
||||||
// just with less information.
|
|
||||||
$can_edit = true;
|
|
||||||
|
|
||||||
$account = id(new PhortuneAccountQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withIDs(array($id))
|
|
||||||
->requireCapabilities(
|
|
||||||
array(
|
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
|
||||||
))
|
|
||||||
->executeOne();
|
|
||||||
if (!$account) {
|
|
||||||
return new Aphront404Response();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setAccount($account);
|
$account = $this->getAccount();
|
||||||
$title = $account->getName();
|
$title = $account->getName();
|
||||||
|
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$invoices = id(new PhortuneCartQuery())
|
$invoices = id(new PhortuneCartQuery())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withAccountPHIDs(array($account->getPHID()))
|
->withAccountPHIDs(array($account->getPHID()))
|
||||||
|
|
Loading…
Reference in a new issue