@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.

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

+87 -104
+3 -1
src/__phutil_library_map__.php
··· 4338 4338 'PhortuneAccountAddManagerController' => 'applications/phortune/controller/account/PhortuneAccountAddManagerController.php', 4339 4339 'PhortuneAccountBillingController' => 'applications/phortune/controller/account/PhortuneAccountBillingController.php', 4340 4340 'PhortuneAccountChargeListController' => 'applications/phortune/controller/account/PhortuneAccountChargeListController.php', 4341 + 'PhortuneAccountController' => 'applications/phortune/controller/account/PhortuneAccountController.php', 4341 4342 'PhortuneAccountEditController' => 'applications/phortune/controller/account/PhortuneAccountEditController.php', 4342 4343 'PhortuneAccountEditEngine' => 'applications/phortune/editor/PhortuneAccountEditEngine.php', 4343 4344 'PhortuneAccountEditor' => 'applications/phortune/editor/PhortuneAccountEditor.php', ··· 9815 9816 'PhortuneAccountAddManagerController' => 'PhortuneController', 9816 9817 'PhortuneAccountBillingController' => 'PhortuneAccountProfileController', 9817 9818 'PhortuneAccountChargeListController' => 'PhortuneController', 9819 + 'PhortuneAccountController' => 'PhortuneController', 9818 9820 'PhortuneAccountEditController' => 'PhortuneController', 9819 9821 'PhortuneAccountEditEngine' => 'PhabricatorEditEngine', 9820 9822 'PhortuneAccountEditor' => 'PhabricatorApplicationTransactionEditor', ··· 9823 9825 'PhortuneAccountManagerController' => 'PhortuneAccountProfileController', 9824 9826 'PhortuneAccountNameTransaction' => 'PhortuneAccountTransactionType', 9825 9827 'PhortuneAccountPHIDType' => 'PhabricatorPHIDType', 9826 - 'PhortuneAccountProfileController' => 'PhortuneController', 9828 + 'PhortuneAccountProfileController' => 'PhortuneAccountController', 9827 9829 'PhortuneAccountQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 9828 9830 'PhortuneAccountSubscriptionController' => 'PhortuneAccountProfileController', 9829 9831 'PhortuneAccountTransaction' => 'PhabricatorModularTransaction',
+4 -21
src/applications/phortune/controller/account/PhortuneAccountBillingController.php
··· 4 4 extends PhortuneAccountProfileController { 5 5 6 6 public function handleRequest(AphrontRequest $request) { 7 - $viewer = $this->getViewer(); 8 - 9 - // TODO: Currently, you must be able to edit an account to view the detail 10 - // page, because the account must be broadly visible so merchants can 11 - // process orders but merchants should not be able to see all the details 12 - // of an account. Ideally this page should be visible to merchants, too, 13 - // just with less information. 14 - $can_edit = true; 15 - 16 - $account = id(new PhortuneAccountQuery()) 17 - ->setViewer($viewer) 18 - ->withIDs(array($request->getURIData('id'))) 19 - ->requireCapabilities( 20 - array( 21 - PhabricatorPolicyCapability::CAN_VIEW, 22 - PhabricatorPolicyCapability::CAN_EDIT, 23 - )) 24 - ->executeOne(); 25 - if (!$account) { 26 - return new Aphront404Response(); 7 + $response = $this->loadAccount(); 8 + if ($response) { 9 + return $response; 27 10 } 28 11 29 - $this->setAccount($account); 12 + $account = $this->getAccount(); 30 13 $title = $account->getName(); 31 14 32 15 $crumbs = $this->buildApplicationCrumbs();
+64
src/applications/phortune/controller/account/PhortuneAccountController.php
··· 1 + <?php 2 + 3 + abstract class PhortuneAccountController 4 + extends PhortuneController { 5 + 6 + private $account; 7 + 8 + protected function getAccount() { 9 + return $this->account; 10 + } 11 + 12 + protected function buildApplicationCrumbs() { 13 + $crumbs = parent::buildApplicationCrumbs(); 14 + 15 + $account = $this->getAccount(); 16 + if ($account) { 17 + $crumbs->addTextCrumb($account->getName(), $account->getURI()); 18 + } 19 + 20 + return $crumbs; 21 + } 22 + 23 + protected function loadAccount() { 24 + // TODO: Currently, you must be able to edit an account to view the detail 25 + // page, because the account must be broadly visible so merchants can 26 + // process orders but merchants should not be able to see all the details 27 + // of an account. Ideally the profile pages should be visible to merchants, 28 + // too, just with less information. 29 + return $this->loadAccountForEdit(); 30 + } 31 + 32 + 33 + protected function loadAccountForEdit() { 34 + $viewer = $this->getViewer(); 35 + $request = $this->getRequest(); 36 + 37 + $account_id = $request->getURIData('accountID'); 38 + if (!$account_id) { 39 + $account_id = $request->getURIData('id'); 40 + } 41 + 42 + if (!$account_id) { 43 + return new Aphront404Response(); 44 + } 45 + 46 + $account = id(new PhortuneAccountQuery()) 47 + ->setViewer($viewer) 48 + ->withIDs(array($account_id)) 49 + ->requireCapabilities( 50 + array( 51 + PhabricatorPolicyCapability::CAN_VIEW, 52 + PhabricatorPolicyCapability::CAN_EDIT, 53 + )) 54 + ->executeOne(); 55 + if (!$account) { 56 + return new Aphront404Response(); 57 + } 58 + 59 + $this->account = $account; 60 + 61 + return null; 62 + } 63 + 64 + }
+5 -21
src/applications/phortune/controller/account/PhortuneAccountManagerController.php
··· 4 4 extends PhortuneAccountProfileController { 5 5 6 6 public function handleRequest(AphrontRequest $request) { 7 - $viewer = $this->getViewer(); 8 - 9 - // TODO: Currently, you must be able to edit an account to view the detail 10 - // page, because the account must be broadly visible so merchants can 11 - // process orders but merchants should not be able to see all the details 12 - // of an account. Ideally this page should be visible to merchants, too, 13 - // just with less information. 14 - $can_edit = true; 15 - 16 - $account = id(new PhortuneAccountQuery()) 17 - ->setViewer($viewer) 18 - ->withIDs(array($request->getURIData('id'))) 19 - ->requireCapabilities( 20 - array( 21 - PhabricatorPolicyCapability::CAN_VIEW, 22 - PhabricatorPolicyCapability::CAN_EDIT, 23 - )) 24 - ->executeOne(); 25 - if (!$account) { 26 - return new Aphront404Response(); 7 + $response = $this->loadAccount(); 8 + if ($response) { 9 + return $response; 27 10 } 28 11 29 - $this->setAccount($account); 12 + $account = $this->getAccount(); 30 13 $title = $account->getName(); 31 14 32 15 $crumbs = $this->buildApplicationCrumbs(); ··· 66 49 ->setText(pht('New Manager')) 67 50 ->setIcon('fa-plus') 68 51 ->setWorkflow(true) 52 + ->setDisabled(!$can_edit) 69 53 ->setHref("/phortune/account/manager/add/{$id}/"); 70 54 71 55 $header = id(new PHUIHeaderView())
+1 -18
src/applications/phortune/controller/account/PhortuneAccountProfileController.php
··· 1 1 <?php 2 2 3 3 abstract class PhortuneAccountProfileController 4 - extends PhortuneController { 5 - 6 - private $account; 7 - 8 - public function setAccount(PhortuneAccount $account) { 9 - $this->account = $account; 10 - return $this; 11 - } 12 - 13 - public function getAccount() { 14 - return $this->account; 15 - } 4 + extends PhortuneAccountController { 16 5 17 6 public function buildApplicationMenu() { 18 7 return $this->buildSideNavView()->getMenu(); ··· 34 23 protected function buildApplicationCrumbs() { 35 24 $crumbs = parent::buildApplicationCrumbs(); 36 25 $crumbs->setBorder(true); 37 - 38 - $account = $this->getAccount(); 39 - if ($account) { 40 - $crumbs->addTextCrumb($account->getName(), $account->getURI()); 41 - } 42 - 43 26 return $crumbs; 44 27 } 45 28
+4 -21
src/applications/phortune/controller/account/PhortuneAccountSubscriptionController.php
··· 4 4 extends PhortuneAccountProfileController { 5 5 6 6 public function handleRequest(AphrontRequest $request) { 7 - $viewer = $this->getViewer(); 8 - 9 - // TODO: Currently, you must be able to edit an account to view the detail 10 - // page, because the account must be broadly visible so merchants can 11 - // process orders but merchants should not be able to see all the details 12 - // of an account. Ideally this page should be visible to merchants, too, 13 - // just with less information. 14 - $can_edit = true; 15 - 16 - $account = id(new PhortuneAccountQuery()) 17 - ->setViewer($viewer) 18 - ->withIDs(array($request->getURIData('id'))) 19 - ->requireCapabilities( 20 - array( 21 - PhabricatorPolicyCapability::CAN_VIEW, 22 - PhabricatorPolicyCapability::CAN_EDIT, 23 - )) 24 - ->executeOne(); 25 - if (!$account) { 26 - return new Aphront404Response(); 7 + $response = $this->loadAccount(); 8 + if ($response) { 9 + return $response; 27 10 } 28 11 29 - $this->setAccount($account); 12 + $account = $this->getAccount(); 30 13 $title = $account->getName(); 31 14 32 15 $crumbs = $this->buildApplicationCrumbs();
+6 -22
src/applications/phortune/controller/account/PhortuneAccountViewController.php
··· 4 4 extends PhortuneAccountProfileController { 5 5 6 6 public function handleRequest(AphrontRequest $request) { 7 - $viewer = $this->getViewer(); 8 - $id = $request->getURIData('accountID'); 9 - 10 - // TODO: Currently, you must be able to edit an account to view the detail 11 - // page, because the account must be broadly visible so merchants can 12 - // process orders but merchants should not be able to see all the details 13 - // of an account. Ideally this page should be visible to merchants, too, 14 - // just with less information. 15 - $can_edit = true; 16 - 17 - $account = id(new PhortuneAccountQuery()) 18 - ->setViewer($viewer) 19 - ->withIDs(array($id)) 20 - ->requireCapabilities( 21 - array( 22 - PhabricatorPolicyCapability::CAN_VIEW, 23 - PhabricatorPolicyCapability::CAN_EDIT, 24 - )) 25 - ->executeOne(); 26 - if (!$account) { 27 - return new Aphront404Response(); 7 + $response = $this->loadAccount(); 8 + if ($response) { 9 + return $response; 28 10 } 29 11 30 - $this->setAccount($account); 12 + $account = $this->getAccount(); 31 13 $title = $account->getName(); 14 + 15 + $viewer = $this->getViewer(); 32 16 33 17 $invoices = id(new PhortuneCartQuery()) 34 18 ->setViewer($viewer)