mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42:41 +01:00
In Phortune, write relationships between payment accounts and merchants they interact with
Summary: Depends on D20713. Ref T13366. When a payment account establishes a relationship with a merchant by creating a cart or subscription, create an edge to give the merchant access to view the payment account. Also, migrate all existing subscriptions and carts to write these edges. This aims at straightening out Phortune permissions, which are currently a bit wonky on a couple of dimensions. See T13366 for detailed discussion. Test Plan: - Created and edited carts/subscriptions, saw edges write. - Ran migrations, saw edges write. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13366 Differential Revision: https://secure.phabricator.com/D20715
This commit is contained in:
parent
e3ba53078e
commit
277bce5638
11 changed files with 136 additions and 7 deletions
10
resources/sql/autopatches/20190815.account.01.carts.php
Normal file
10
resources/sql/autopatches/20190815.account.01.carts.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$edge_type = PhortuneAccountHasMerchantEdgeType::EDGECONST;
|
||||||
|
|
||||||
|
$table = new PhortuneCart();
|
||||||
|
foreach (new LiskMigrationIterator($table) as $cart) {
|
||||||
|
id(new PhabricatorEdgeEditor())
|
||||||
|
->addEdge($cart->getAccountPHID(), $edge_type, $cart->getMerchantPHID())
|
||||||
|
->save();
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$edge_type = PhortuneAccountHasMerchantEdgeType::EDGECONST;
|
||||||
|
|
||||||
|
$table = new PhortuneSubscription();
|
||||||
|
foreach (new LiskMigrationIterator($table) as $sub) {
|
||||||
|
id(new PhabricatorEdgeEditor())
|
||||||
|
->addEdge($sub->getAccountPHID(), $edge_type, $sub->getMerchantPHID())
|
||||||
|
->save();
|
||||||
|
}
|
|
@ -5243,6 +5243,7 @@ phutil_register_library_map(array(
|
||||||
'PhortuneAccountEmailTransactionType' => 'applications/phortune/xaction/PhortuneAccountEmailTransactionType.php',
|
'PhortuneAccountEmailTransactionType' => 'applications/phortune/xaction/PhortuneAccountEmailTransactionType.php',
|
||||||
'PhortuneAccountEmailViewController' => 'applications/phortune/controller/account/PhortuneAccountEmailViewController.php',
|
'PhortuneAccountEmailViewController' => 'applications/phortune/controller/account/PhortuneAccountEmailViewController.php',
|
||||||
'PhortuneAccountHasMemberEdgeType' => 'applications/phortune/edge/PhortuneAccountHasMemberEdgeType.php',
|
'PhortuneAccountHasMemberEdgeType' => 'applications/phortune/edge/PhortuneAccountHasMemberEdgeType.php',
|
||||||
|
'PhortuneAccountHasMerchantEdgeType' => 'applications/phortune/edge/PhortuneAccountHasMerchantEdgeType.php',
|
||||||
'PhortuneAccountListController' => 'applications/phortune/controller/account/PhortuneAccountListController.php',
|
'PhortuneAccountListController' => 'applications/phortune/controller/account/PhortuneAccountListController.php',
|
||||||
'PhortuneAccountManagersController' => 'applications/phortune/controller/account/PhortuneAccountManagersController.php',
|
'PhortuneAccountManagersController' => 'applications/phortune/controller/account/PhortuneAccountManagersController.php',
|
||||||
'PhortuneAccountNameTransaction' => 'applications/phortune/xaction/PhortuneAccountNameTransaction.php',
|
'PhortuneAccountNameTransaction' => 'applications/phortune/xaction/PhortuneAccountNameTransaction.php',
|
||||||
|
@ -5302,6 +5303,7 @@ phutil_register_library_map(array(
|
||||||
'PhortuneMerchantEditController' => 'applications/phortune/controller/merchant/PhortuneMerchantEditController.php',
|
'PhortuneMerchantEditController' => 'applications/phortune/controller/merchant/PhortuneMerchantEditController.php',
|
||||||
'PhortuneMerchantEditEngine' => 'applications/phortune/editor/PhortuneMerchantEditEngine.php',
|
'PhortuneMerchantEditEngine' => 'applications/phortune/editor/PhortuneMerchantEditEngine.php',
|
||||||
'PhortuneMerchantEditor' => 'applications/phortune/editor/PhortuneMerchantEditor.php',
|
'PhortuneMerchantEditor' => 'applications/phortune/editor/PhortuneMerchantEditor.php',
|
||||||
|
'PhortuneMerchantHasAccountEdgeType' => 'applications/phortune/edge/PhortuneMerchantHasAccountEdgeType.php',
|
||||||
'PhortuneMerchantHasMemberEdgeType' => 'applications/phortune/edge/PhortuneMerchantHasMemberEdgeType.php',
|
'PhortuneMerchantHasMemberEdgeType' => 'applications/phortune/edge/PhortuneMerchantHasMemberEdgeType.php',
|
||||||
'PhortuneMerchantInvoiceCreateController' => 'applications/phortune/controller/merchant/PhortuneMerchantInvoiceCreateController.php',
|
'PhortuneMerchantInvoiceCreateController' => 'applications/phortune/controller/merchant/PhortuneMerchantInvoiceCreateController.php',
|
||||||
'PhortuneMerchantInvoiceEmailTransaction' => 'applications/phortune/xaction/PhortuneMerchantInvoiceEmailTransaction.php',
|
'PhortuneMerchantInvoiceEmailTransaction' => 'applications/phortune/xaction/PhortuneMerchantInvoiceEmailTransaction.php',
|
||||||
|
@ -11796,6 +11798,7 @@ phutil_register_library_map(array(
|
||||||
'PhortuneAccountEmailTransactionType' => 'PhabricatorModularTransactionType',
|
'PhortuneAccountEmailTransactionType' => 'PhabricatorModularTransactionType',
|
||||||
'PhortuneAccountEmailViewController' => 'PhortuneAccountController',
|
'PhortuneAccountEmailViewController' => 'PhortuneAccountController',
|
||||||
'PhortuneAccountHasMemberEdgeType' => 'PhabricatorEdgeType',
|
'PhortuneAccountHasMemberEdgeType' => 'PhabricatorEdgeType',
|
||||||
|
'PhortuneAccountHasMerchantEdgeType' => 'PhabricatorEdgeType',
|
||||||
'PhortuneAccountListController' => 'PhortuneController',
|
'PhortuneAccountListController' => 'PhortuneController',
|
||||||
'PhortuneAccountManagersController' => 'PhortuneAccountProfileController',
|
'PhortuneAccountManagersController' => 'PhortuneAccountProfileController',
|
||||||
'PhortuneAccountNameTransaction' => 'PhortuneAccountTransactionType',
|
'PhortuneAccountNameTransaction' => 'PhortuneAccountTransactionType',
|
||||||
|
@ -11866,6 +11869,7 @@ phutil_register_library_map(array(
|
||||||
'PhortuneMerchantEditController' => 'PhortuneMerchantController',
|
'PhortuneMerchantEditController' => 'PhortuneMerchantController',
|
||||||
'PhortuneMerchantEditEngine' => 'PhabricatorEditEngine',
|
'PhortuneMerchantEditEngine' => 'PhabricatorEditEngine',
|
||||||
'PhortuneMerchantEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PhortuneMerchantEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
|
'PhortuneMerchantHasAccountEdgeType' => 'PhabricatorEdgeType',
|
||||||
'PhortuneMerchantHasMemberEdgeType' => 'PhabricatorEdgeType',
|
'PhortuneMerchantHasMemberEdgeType' => 'PhabricatorEdgeType',
|
||||||
'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantProfileController',
|
'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantProfileController',
|
||||||
'PhortuneMerchantInvoiceEmailTransaction' => 'PhortuneMerchantTransactionType',
|
'PhortuneMerchantInvoiceEmailTransaction' => 'PhortuneMerchantTransactionType',
|
||||||
|
|
|
@ -97,6 +97,28 @@ final class PhortuneAccountDetailsController
|
||||||
->setHeaderText(pht('Managers'))
|
->setHeaderText(pht('Managers'))
|
||||||
->appendChild($member_list);
|
->appendChild($member_list);
|
||||||
|
|
||||||
|
$merchant_list = id(new PHUIObjectItemListView())
|
||||||
|
->setSimple(true)
|
||||||
|
->setNoDataString(pht('No purchase history.'));
|
||||||
|
|
||||||
|
$merchant_phids = $account->getMerchantPHIDs();
|
||||||
|
$handles = $viewer->loadHandles($merchant_phids);
|
||||||
|
|
||||||
|
foreach ($merchant_phids as $merchant_phid) {
|
||||||
|
$handle = $handles[$merchant_phid];
|
||||||
|
|
||||||
|
$merchant = id(new PHUIObjectItemView())
|
||||||
|
->setImageURI($handle->getImageURI())
|
||||||
|
->setHref($handle->getURI())
|
||||||
|
->setHeader($handle->getFullName());
|
||||||
|
|
||||||
|
$merchant_list->addItem($merchant);
|
||||||
|
}
|
||||||
|
|
||||||
|
$curtain->newPanel()
|
||||||
|
->setHeaderText(pht('Merchants'))
|
||||||
|
->appendChild($merchant_list);
|
||||||
|
|
||||||
return $curtain;
|
return $curtain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhortuneAccountHasMerchantEdgeType
|
||||||
|
extends PhabricatorEdgeType {
|
||||||
|
|
||||||
|
const EDGECONST = 73;
|
||||||
|
|
||||||
|
public function getInverseEdgeConstant() {
|
||||||
|
return PhortuneMerchantHasAccountEdgeType::EDGECONST;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhortuneMerchantHasAccountEdgeType
|
||||||
|
extends PhabricatorEdgeType {
|
||||||
|
|
||||||
|
const EDGECONST = 74;
|
||||||
|
|
||||||
|
public function getInverseEdgeConstant() {
|
||||||
|
return PhortuneAccountHasMerchantEdgeType::EDGECONST;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -235,4 +235,16 @@ final class PhortuneCartEditor
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function applyFinalEffects(
|
||||||
|
PhabricatorLiskDAO $object,
|
||||||
|
array $xactions) {
|
||||||
|
|
||||||
|
$account = $object->getAccount();
|
||||||
|
$merchant = $object->getMerchant();
|
||||||
|
$account->writeMerchantEdge($merchant);
|
||||||
|
|
||||||
|
return $xactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,8 @@ final class PhortuneMerchantPHIDType extends PhabricatorPHIDType {
|
||||||
array $phids) {
|
array $phids) {
|
||||||
|
|
||||||
return id(new PhortuneMerchantQuery())
|
return id(new PhortuneMerchantQuery())
|
||||||
->withPHIDs($phids);
|
->withPHIDs($phids)
|
||||||
|
->needProfileImage(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadHandles(
|
public function loadHandles(
|
||||||
|
@ -32,10 +33,10 @@ final class PhortuneMerchantPHIDType extends PhabricatorPHIDType {
|
||||||
foreach ($handles as $phid => $handle) {
|
foreach ($handles as $phid => $handle) {
|
||||||
$merchant = $objects[$phid];
|
$merchant = $objects[$phid];
|
||||||
|
|
||||||
$id = $merchant->getID();
|
$handle
|
||||||
|
->setName($merchant->getName())
|
||||||
$handle->setName($merchant->getName());
|
->setURI($merchant->getURI())
|
||||||
$handle->setURI("/phortune/merchant/{$id}/");
|
->setImageURI($merchant->getProfileImageURI());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,13 +53,34 @@ final class PhortuneAccountQuery
|
||||||
protected function willFilterPage(array $accounts) {
|
protected function willFilterPage(array $accounts) {
|
||||||
$query = id(new PhabricatorEdgeQuery())
|
$query = id(new PhabricatorEdgeQuery())
|
||||||
->withSourcePHIDs(mpull($accounts, 'getPHID'))
|
->withSourcePHIDs(mpull($accounts, 'getPHID'))
|
||||||
->withEdgeTypes(array(PhortuneAccountHasMemberEdgeType::EDGECONST));
|
->withEdgeTypes(
|
||||||
|
array(
|
||||||
|
PhortuneAccountHasMemberEdgeType::EDGECONST,
|
||||||
|
PhortuneAccountHasMerchantEdgeType::EDGECONST,
|
||||||
|
));
|
||||||
|
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$member_phids = $query->getDestinationPHIDs(array($account->getPHID()));
|
$member_phids = $query->getDestinationPHIDs(
|
||||||
|
array(
|
||||||
|
$account->getPHID(),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
PhortuneAccountHasMemberEdgeType::EDGECONST,
|
||||||
|
));
|
||||||
$member_phids = array_reverse($member_phids);
|
$member_phids = array_reverse($member_phids);
|
||||||
$account->attachMemberPHIDs($member_phids);
|
$account->attachMemberPHIDs($member_phids);
|
||||||
|
|
||||||
|
$merchant_phids = $query->getDestinationPHIDs(
|
||||||
|
array(
|
||||||
|
$account->getPHID(),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
PhortuneAccountHasMerchantEdgeType::EDGECONST,
|
||||||
|
));
|
||||||
|
$merchant_phids = array_reverse($merchant_phids);
|
||||||
|
$account->attachMerchantPHIDs($merchant_phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $accounts;
|
return $accounts;
|
||||||
|
|
|
@ -16,11 +16,13 @@ final class PhortuneAccount extends PhortuneDAO
|
||||||
protected $billingAddress;
|
protected $billingAddress;
|
||||||
|
|
||||||
private $memberPHIDs = self::ATTACHABLE;
|
private $memberPHIDs = self::ATTACHABLE;
|
||||||
|
private $merchantPHIDs = self::ATTACHABLE;
|
||||||
|
|
||||||
public static function initializeNewAccount(PhabricatorUser $actor) {
|
public static function initializeNewAccount(PhabricatorUser $actor) {
|
||||||
return id(new self())
|
return id(new self())
|
||||||
->setBillingName('')
|
->setBillingName('')
|
||||||
->setBillingAddress('')
|
->setBillingAddress('')
|
||||||
|
->attachMerchantPHIDs(array())
|
||||||
->attachMemberPHIDs(array());
|
->attachMemberPHIDs(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +117,26 @@ final class PhortuneAccount extends PhortuneDAO
|
||||||
$this->getID());
|
$this->getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function attachMerchantPHIDs(array $merchant_phids) {
|
||||||
|
$this->merchantPHIDs = $merchant_phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMerchantPHIDs() {
|
||||||
|
return $this->assertAttached($this->merchantPHIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function writeMerchantEdge(PhortuneMerchant $merchant) {
|
||||||
|
$edge_src = $this->getPHID();
|
||||||
|
$edge_type = PhortuneAccountHasMerchantEdgeType::EDGECONST;
|
||||||
|
$edge_dst = $merchant->getPHID();
|
||||||
|
|
||||||
|
id(new PhabricatorEdgeEditor())
|
||||||
|
->addEdge($edge_src, $edge_type, $edge_dst)
|
||||||
|
->save();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -161,6 +161,10 @@ final class PhortuneSubscription extends PhortuneDAO
|
||||||
}
|
}
|
||||||
$this->saveTransaction();
|
$this->saveTransaction();
|
||||||
|
|
||||||
|
$account = $this->getAccount();
|
||||||
|
$merchant = $this->getMerchant();
|
||||||
|
$account->writeMerchantEdge($merchant);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue