mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +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',
|
||||
'PhortuneAccountEmailViewController' => 'applications/phortune/controller/account/PhortuneAccountEmailViewController.php',
|
||||
'PhortuneAccountHasMemberEdgeType' => 'applications/phortune/edge/PhortuneAccountHasMemberEdgeType.php',
|
||||
'PhortuneAccountHasMerchantEdgeType' => 'applications/phortune/edge/PhortuneAccountHasMerchantEdgeType.php',
|
||||
'PhortuneAccountListController' => 'applications/phortune/controller/account/PhortuneAccountListController.php',
|
||||
'PhortuneAccountManagersController' => 'applications/phortune/controller/account/PhortuneAccountManagersController.php',
|
||||
'PhortuneAccountNameTransaction' => 'applications/phortune/xaction/PhortuneAccountNameTransaction.php',
|
||||
|
@ -5302,6 +5303,7 @@ phutil_register_library_map(array(
|
|||
'PhortuneMerchantEditController' => 'applications/phortune/controller/merchant/PhortuneMerchantEditController.php',
|
||||
'PhortuneMerchantEditEngine' => 'applications/phortune/editor/PhortuneMerchantEditEngine.php',
|
||||
'PhortuneMerchantEditor' => 'applications/phortune/editor/PhortuneMerchantEditor.php',
|
||||
'PhortuneMerchantHasAccountEdgeType' => 'applications/phortune/edge/PhortuneMerchantHasAccountEdgeType.php',
|
||||
'PhortuneMerchantHasMemberEdgeType' => 'applications/phortune/edge/PhortuneMerchantHasMemberEdgeType.php',
|
||||
'PhortuneMerchantInvoiceCreateController' => 'applications/phortune/controller/merchant/PhortuneMerchantInvoiceCreateController.php',
|
||||
'PhortuneMerchantInvoiceEmailTransaction' => 'applications/phortune/xaction/PhortuneMerchantInvoiceEmailTransaction.php',
|
||||
|
@ -11796,6 +11798,7 @@ phutil_register_library_map(array(
|
|||
'PhortuneAccountEmailTransactionType' => 'PhabricatorModularTransactionType',
|
||||
'PhortuneAccountEmailViewController' => 'PhortuneAccountController',
|
||||
'PhortuneAccountHasMemberEdgeType' => 'PhabricatorEdgeType',
|
||||
'PhortuneAccountHasMerchantEdgeType' => 'PhabricatorEdgeType',
|
||||
'PhortuneAccountListController' => 'PhortuneController',
|
||||
'PhortuneAccountManagersController' => 'PhortuneAccountProfileController',
|
||||
'PhortuneAccountNameTransaction' => 'PhortuneAccountTransactionType',
|
||||
|
@ -11866,6 +11869,7 @@ phutil_register_library_map(array(
|
|||
'PhortuneMerchantEditController' => 'PhortuneMerchantController',
|
||||
'PhortuneMerchantEditEngine' => 'PhabricatorEditEngine',
|
||||
'PhortuneMerchantEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'PhortuneMerchantHasAccountEdgeType' => 'PhabricatorEdgeType',
|
||||
'PhortuneMerchantHasMemberEdgeType' => 'PhabricatorEdgeType',
|
||||
'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantProfileController',
|
||||
'PhortuneMerchantInvoiceEmailTransaction' => 'PhortuneMerchantTransactionType',
|
||||
|
|
|
@ -97,6 +97,28 @@ final class PhortuneAccountDetailsController
|
|||
->setHeaderText(pht('Managers'))
|
||||
->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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
return id(new PhortuneMerchantQuery())
|
||||
->withPHIDs($phids);
|
||||
->withPHIDs($phids)
|
||||
->needProfileImage(true);
|
||||
}
|
||||
|
||||
public function loadHandles(
|
||||
|
@ -32,10 +33,10 @@ final class PhortuneMerchantPHIDType extends PhabricatorPHIDType {
|
|||
foreach ($handles as $phid => $handle) {
|
||||
$merchant = $objects[$phid];
|
||||
|
||||
$id = $merchant->getID();
|
||||
|
||||
$handle->setName($merchant->getName());
|
||||
$handle->setURI("/phortune/merchant/{$id}/");
|
||||
$handle
|
||||
->setName($merchant->getName())
|
||||
->setURI($merchant->getURI())
|
||||
->setImageURI($merchant->getProfileImageURI());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,13 +53,34 @@ final class PhortuneAccountQuery
|
|||
protected function willFilterPage(array $accounts) {
|
||||
$query = id(new PhabricatorEdgeQuery())
|
||||
->withSourcePHIDs(mpull($accounts, 'getPHID'))
|
||||
->withEdgeTypes(array(PhortuneAccountHasMemberEdgeType::EDGECONST));
|
||||
->withEdgeTypes(
|
||||
array(
|
||||
PhortuneAccountHasMemberEdgeType::EDGECONST,
|
||||
PhortuneAccountHasMerchantEdgeType::EDGECONST,
|
||||
));
|
||||
|
||||
$query->execute();
|
||||
|
||||
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);
|
||||
$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;
|
||||
|
|
|
@ -16,11 +16,13 @@ final class PhortuneAccount extends PhortuneDAO
|
|||
protected $billingAddress;
|
||||
|
||||
private $memberPHIDs = self::ATTACHABLE;
|
||||
private $merchantPHIDs = self::ATTACHABLE;
|
||||
|
||||
public static function initializeNewAccount(PhabricatorUser $actor) {
|
||||
return id(new self())
|
||||
->setBillingName('')
|
||||
->setBillingAddress('')
|
||||
->attachMerchantPHIDs(array())
|
||||
->attachMemberPHIDs(array());
|
||||
}
|
||||
|
||||
|
@ -115,6 +117,26 @@ final class PhortuneAccount extends PhortuneDAO
|
|||
$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 )------------------------- */
|
||||
|
||||
|
|
|
@ -161,6 +161,10 @@ final class PhortuneSubscription extends PhortuneDAO
|
|||
}
|
||||
$this->saveTransaction();
|
||||
|
||||
$account = $this->getAccount();
|
||||
$merchant = $this->getMerchant();
|
||||
$account->writeMerchantEdge($merchant);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue