Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14395207
D17694.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
D17694.id.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -4338,6 +4338,7 @@
'PhortuneAccountAddManagerController' => 'applications/phortune/controller/account/PhortuneAccountAddManagerController.php',
'PhortuneAccountBillingController' => 'applications/phortune/controller/account/PhortuneAccountBillingController.php',
'PhortuneAccountChargeListController' => 'applications/phortune/controller/account/PhortuneAccountChargeListController.php',
+ 'PhortuneAccountController' => 'applications/phortune/controller/account/PhortuneAccountController.php',
'PhortuneAccountEditController' => 'applications/phortune/controller/account/PhortuneAccountEditController.php',
'PhortuneAccountEditEngine' => 'applications/phortune/editor/PhortuneAccountEditEngine.php',
'PhortuneAccountEditor' => 'applications/phortune/editor/PhortuneAccountEditor.php',
@@ -9815,6 +9816,7 @@
'PhortuneAccountAddManagerController' => 'PhortuneController',
'PhortuneAccountBillingController' => 'PhortuneAccountProfileController',
'PhortuneAccountChargeListController' => 'PhortuneController',
+ 'PhortuneAccountController' => 'PhortuneController',
'PhortuneAccountEditController' => 'PhortuneController',
'PhortuneAccountEditEngine' => 'PhabricatorEditEngine',
'PhortuneAccountEditor' => 'PhabricatorApplicationTransactionEditor',
@@ -9823,7 +9825,7 @@
'PhortuneAccountManagerController' => 'PhortuneAccountProfileController',
'PhortuneAccountNameTransaction' => 'PhortuneAccountTransactionType',
'PhortuneAccountPHIDType' => 'PhabricatorPHIDType',
- 'PhortuneAccountProfileController' => 'PhortuneController',
+ 'PhortuneAccountProfileController' => 'PhortuneAccountController',
'PhortuneAccountQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhortuneAccountSubscriptionController' => 'PhortuneAccountProfileController',
'PhortuneAccountTransaction' => 'PhabricatorModularTransaction',
diff --git a/src/applications/phortune/controller/account/PhortuneAccountBillingController.php b/src/applications/phortune/controller/account/PhortuneAccountBillingController.php
--- a/src/applications/phortune/controller/account/PhortuneAccountBillingController.php
+++ b/src/applications/phortune/controller/account/PhortuneAccountBillingController.php
@@ -4,29 +4,12 @@
extends PhortuneAccountProfileController {
public function handleRequest(AphrontRequest $request) {
- $viewer = $this->getViewer();
-
- // 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($request->getURIData('id')))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->executeOne();
- if (!$account) {
- return new Aphront404Response();
+ $response = $this->loadAccount();
+ if ($response) {
+ return $response;
}
- $this->setAccount($account);
+ $account = $this->getAccount();
$title = $account->getName();
$crumbs = $this->buildApplicationCrumbs();
diff --git a/src/applications/phortune/controller/account/PhortuneAccountController.php b/src/applications/phortune/controller/account/PhortuneAccountController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phortune/controller/account/PhortuneAccountController.php
@@ -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;
+ }
+
+}
diff --git a/src/applications/phortune/controller/account/PhortuneAccountManagerController.php b/src/applications/phortune/controller/account/PhortuneAccountManagerController.php
--- a/src/applications/phortune/controller/account/PhortuneAccountManagerController.php
+++ b/src/applications/phortune/controller/account/PhortuneAccountManagerController.php
@@ -4,29 +4,12 @@
extends PhortuneAccountProfileController {
public function handleRequest(AphrontRequest $request) {
- $viewer = $this->getViewer();
-
- // 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($request->getURIData('id')))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->executeOne();
- if (!$account) {
- return new Aphront404Response();
+ $response = $this->loadAccount();
+ if ($response) {
+ return $response;
}
- $this->setAccount($account);
+ $account = $this->getAccount();
$title = $account->getName();
$crumbs = $this->buildApplicationCrumbs();
@@ -66,6 +49,7 @@
->setText(pht('New Manager'))
->setIcon('fa-plus')
->setWorkflow(true)
+ ->setDisabled(!$can_edit)
->setHref("/phortune/account/manager/add/{$id}/");
$header = id(new PHUIHeaderView())
diff --git a/src/applications/phortune/controller/account/PhortuneAccountProfileController.php b/src/applications/phortune/controller/account/PhortuneAccountProfileController.php
--- a/src/applications/phortune/controller/account/PhortuneAccountProfileController.php
+++ b/src/applications/phortune/controller/account/PhortuneAccountProfileController.php
@@ -1,18 +1,7 @@
<?php
abstract class PhortuneAccountProfileController
- extends PhortuneController {
-
- private $account;
-
- public function setAccount(PhortuneAccount $account) {
- $this->account = $account;
- return $this;
- }
-
- public function getAccount() {
- return $this->account;
- }
+ extends PhortuneAccountController {
public function buildApplicationMenu() {
return $this->buildSideNavView()->getMenu();
@@ -34,12 +23,6 @@
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$crumbs->setBorder(true);
-
- $account = $this->getAccount();
- if ($account) {
- $crumbs->addTextCrumb($account->getName(), $account->getURI());
- }
-
return $crumbs;
}
diff --git a/src/applications/phortune/controller/account/PhortuneAccountSubscriptionController.php b/src/applications/phortune/controller/account/PhortuneAccountSubscriptionController.php
--- a/src/applications/phortune/controller/account/PhortuneAccountSubscriptionController.php
+++ b/src/applications/phortune/controller/account/PhortuneAccountSubscriptionController.php
@@ -4,29 +4,12 @@
extends PhortuneAccountProfileController {
public function handleRequest(AphrontRequest $request) {
- $viewer = $this->getViewer();
-
- // 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($request->getURIData('id')))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->executeOne();
- if (!$account) {
- return new Aphront404Response();
+ $response = $this->loadAccount();
+ if ($response) {
+ return $response;
}
- $this->setAccount($account);
+ $account = $this->getAccount();
$title = $account->getName();
$crumbs = $this->buildApplicationCrumbs();
diff --git a/src/applications/phortune/controller/account/PhortuneAccountViewController.php b/src/applications/phortune/controller/account/PhortuneAccountViewController.php
--- a/src/applications/phortune/controller/account/PhortuneAccountViewController.php
+++ b/src/applications/phortune/controller/account/PhortuneAccountViewController.php
@@ -4,32 +4,16 @@
extends PhortuneAccountProfileController {
public function handleRequest(AphrontRequest $request) {
- $viewer = $this->getViewer();
- $id = $request->getURIData('accountID');
-
- // 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();
+ $response = $this->loadAccount();
+ if ($response) {
+ return $response;
}
- $this->setAccount($account);
+ $account = $this->getAccount();
$title = $account->getName();
+ $viewer = $this->getViewer();
+
$invoices = id(new PhortuneCartQuery())
->setViewer($viewer)
->withAccountPHIDs(array($account->getPHID()))
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 3:34 AM (16 h, 45 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6920463
Default Alt Text
D17694.id.diff (11 KB)
Attached To
Mode
D17694: Reduce code duplication in Phortune account controllers
Attached
Detach File
Event Timeline
Log In to Comment