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

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

+136 -7
+10
resources/sql/autopatches/20190815.account.01.carts.php
··· 1 + <?php 2 + 3 + $edge_type = PhortuneAccountHasMerchantEdgeType::EDGECONST; 4 + 5 + $table = new PhortuneCart(); 6 + foreach (new LiskMigrationIterator($table) as $cart) { 7 + id(new PhabricatorEdgeEditor()) 8 + ->addEdge($cart->getAccountPHID(), $edge_type, $cart->getMerchantPHID()) 9 + ->save(); 10 + }
+10
resources/sql/autopatches/20190815.account.02.subscriptions.php
··· 1 + <?php 2 + 3 + $edge_type = PhortuneAccountHasMerchantEdgeType::EDGECONST; 4 + 5 + $table = new PhortuneSubscription(); 6 + foreach (new LiskMigrationIterator($table) as $sub) { 7 + id(new PhabricatorEdgeEditor()) 8 + ->addEdge($sub->getAccountPHID(), $edge_type, $sub->getMerchantPHID()) 9 + ->save(); 10 + }
+4
src/__phutil_library_map__.php
··· 5243 5243 'PhortuneAccountEmailTransactionType' => 'applications/phortune/xaction/PhortuneAccountEmailTransactionType.php', 5244 5244 'PhortuneAccountEmailViewController' => 'applications/phortune/controller/account/PhortuneAccountEmailViewController.php', 5245 5245 'PhortuneAccountHasMemberEdgeType' => 'applications/phortune/edge/PhortuneAccountHasMemberEdgeType.php', 5246 + 'PhortuneAccountHasMerchantEdgeType' => 'applications/phortune/edge/PhortuneAccountHasMerchantEdgeType.php', 5246 5247 'PhortuneAccountListController' => 'applications/phortune/controller/account/PhortuneAccountListController.php', 5247 5248 'PhortuneAccountManagersController' => 'applications/phortune/controller/account/PhortuneAccountManagersController.php', 5248 5249 'PhortuneAccountNameTransaction' => 'applications/phortune/xaction/PhortuneAccountNameTransaction.php', ··· 5302 5303 'PhortuneMerchantEditController' => 'applications/phortune/controller/merchant/PhortuneMerchantEditController.php', 5303 5304 'PhortuneMerchantEditEngine' => 'applications/phortune/editor/PhortuneMerchantEditEngine.php', 5304 5305 'PhortuneMerchantEditor' => 'applications/phortune/editor/PhortuneMerchantEditor.php', 5306 + 'PhortuneMerchantHasAccountEdgeType' => 'applications/phortune/edge/PhortuneMerchantHasAccountEdgeType.php', 5305 5307 'PhortuneMerchantHasMemberEdgeType' => 'applications/phortune/edge/PhortuneMerchantHasMemberEdgeType.php', 5306 5308 'PhortuneMerchantInvoiceCreateController' => 'applications/phortune/controller/merchant/PhortuneMerchantInvoiceCreateController.php', 5307 5309 'PhortuneMerchantInvoiceEmailTransaction' => 'applications/phortune/xaction/PhortuneMerchantInvoiceEmailTransaction.php', ··· 11796 11798 'PhortuneAccountEmailTransactionType' => 'PhabricatorModularTransactionType', 11797 11799 'PhortuneAccountEmailViewController' => 'PhortuneAccountController', 11798 11800 'PhortuneAccountHasMemberEdgeType' => 'PhabricatorEdgeType', 11801 + 'PhortuneAccountHasMerchantEdgeType' => 'PhabricatorEdgeType', 11799 11802 'PhortuneAccountListController' => 'PhortuneController', 11800 11803 'PhortuneAccountManagersController' => 'PhortuneAccountProfileController', 11801 11804 'PhortuneAccountNameTransaction' => 'PhortuneAccountTransactionType', ··· 11866 11869 'PhortuneMerchantEditController' => 'PhortuneMerchantController', 11867 11870 'PhortuneMerchantEditEngine' => 'PhabricatorEditEngine', 11868 11871 'PhortuneMerchantEditor' => 'PhabricatorApplicationTransactionEditor', 11872 + 'PhortuneMerchantHasAccountEdgeType' => 'PhabricatorEdgeType', 11869 11873 'PhortuneMerchantHasMemberEdgeType' => 'PhabricatorEdgeType', 11870 11874 'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantProfileController', 11871 11875 'PhortuneMerchantInvoiceEmailTransaction' => 'PhortuneMerchantTransactionType',
+22
src/applications/phortune/controller/account/PhortuneAccountDetailsController.php
··· 97 97 ->setHeaderText(pht('Managers')) 98 98 ->appendChild($member_list); 99 99 100 + $merchant_list = id(new PHUIObjectItemListView()) 101 + ->setSimple(true) 102 + ->setNoDataString(pht('No purchase history.')); 103 + 104 + $merchant_phids = $account->getMerchantPHIDs(); 105 + $handles = $viewer->loadHandles($merchant_phids); 106 + 107 + foreach ($merchant_phids as $merchant_phid) { 108 + $handle = $handles[$merchant_phid]; 109 + 110 + $merchant = id(new PHUIObjectItemView()) 111 + ->setImageURI($handle->getImageURI()) 112 + ->setHref($handle->getURI()) 113 + ->setHeader($handle->getFullName()); 114 + 115 + $merchant_list->addItem($merchant); 116 + } 117 + 118 + $curtain->newPanel() 119 + ->setHeaderText(pht('Merchants')) 120 + ->appendChild($merchant_list); 121 + 100 122 return $curtain; 101 123 } 102 124
+11
src/applications/phortune/edge/PhortuneAccountHasMerchantEdgeType.php
··· 1 + <?php 2 + 3 + final class PhortuneAccountHasMerchantEdgeType 4 + extends PhabricatorEdgeType { 5 + 6 + const EDGECONST = 73; 7 + 8 + public function getInverseEdgeConstant() { 9 + return PhortuneMerchantHasAccountEdgeType::EDGECONST; 10 + } 11 + }
+12
src/applications/phortune/edge/PhortuneMerchantHasAccountEdgeType.php
··· 1 + <?php 2 + 3 + final class PhortuneMerchantHasAccountEdgeType 4 + extends PhabricatorEdgeType { 5 + 6 + const EDGECONST = 74; 7 + 8 + public function getInverseEdgeConstant() { 9 + return PhortuneAccountHasMerchantEdgeType::EDGECONST; 10 + } 11 + 12 + }
+12
src/applications/phortune/editor/PhortuneCartEditor.php
··· 235 235 return $this; 236 236 } 237 237 238 + protected function applyFinalEffects( 239 + PhabricatorLiskDAO $object, 240 + array $xactions) { 241 + 242 + $account = $object->getAccount(); 243 + $merchant = $object->getMerchant(); 244 + $account->writeMerchantEdge($merchant); 245 + 246 + return $xactions; 247 + } 248 + 249 + 238 250 }
+6 -5
src/applications/phortune/phid/PhortuneMerchantPHIDType.php
··· 21 21 array $phids) { 22 22 23 23 return id(new PhortuneMerchantQuery()) 24 - ->withPHIDs($phids); 24 + ->withPHIDs($phids) 25 + ->needProfileImage(true); 25 26 } 26 27 27 28 public function loadHandles( ··· 32 33 foreach ($handles as $phid => $handle) { 33 34 $merchant = $objects[$phid]; 34 35 35 - $id = $merchant->getID(); 36 - 37 - $handle->setName($merchant->getName()); 38 - $handle->setURI("/phortune/merchant/{$id}/"); 36 + $handle 37 + ->setName($merchant->getName()) 38 + ->setURI($merchant->getURI()) 39 + ->setImageURI($merchant->getProfileImageURI()); 39 40 } 40 41 } 41 42
+23 -2
src/applications/phortune/query/PhortuneAccountQuery.php
··· 53 53 protected function willFilterPage(array $accounts) { 54 54 $query = id(new PhabricatorEdgeQuery()) 55 55 ->withSourcePHIDs(mpull($accounts, 'getPHID')) 56 - ->withEdgeTypes(array(PhortuneAccountHasMemberEdgeType::EDGECONST)); 56 + ->withEdgeTypes( 57 + array( 58 + PhortuneAccountHasMemberEdgeType::EDGECONST, 59 + PhortuneAccountHasMerchantEdgeType::EDGECONST, 60 + )); 61 + 57 62 $query->execute(); 58 63 59 64 foreach ($accounts as $account) { 60 - $member_phids = $query->getDestinationPHIDs(array($account->getPHID())); 65 + $member_phids = $query->getDestinationPHIDs( 66 + array( 67 + $account->getPHID(), 68 + ), 69 + array( 70 + PhortuneAccountHasMemberEdgeType::EDGECONST, 71 + )); 61 72 $member_phids = array_reverse($member_phids); 62 73 $account->attachMemberPHIDs($member_phids); 74 + 75 + $merchant_phids = $query->getDestinationPHIDs( 76 + array( 77 + $account->getPHID(), 78 + ), 79 + array( 80 + PhortuneAccountHasMerchantEdgeType::EDGECONST, 81 + )); 82 + $merchant_phids = array_reverse($merchant_phids); 83 + $account->attachMerchantPHIDs($merchant_phids); 63 84 } 64 85 65 86 return $accounts;
+22
src/applications/phortune/storage/PhortuneAccount.php
··· 16 16 protected $billingAddress; 17 17 18 18 private $memberPHIDs = self::ATTACHABLE; 19 + private $merchantPHIDs = self::ATTACHABLE; 19 20 20 21 public static function initializeNewAccount(PhabricatorUser $actor) { 21 22 return id(new self()) 22 23 ->setBillingName('') 23 24 ->setBillingAddress('') 25 + ->attachMerchantPHIDs(array()) 24 26 ->attachMemberPHIDs(array()); 25 27 } 26 28 ··· 115 117 $this->getID()); 116 118 } 117 119 120 + public function attachMerchantPHIDs(array $merchant_phids) { 121 + $this->merchantPHIDs = $merchant_phids; 122 + return $this; 123 + } 124 + 125 + public function getMerchantPHIDs() { 126 + return $this->assertAttached($this->merchantPHIDs); 127 + } 128 + 129 + public function writeMerchantEdge(PhortuneMerchant $merchant) { 130 + $edge_src = $this->getPHID(); 131 + $edge_type = PhortuneAccountHasMerchantEdgeType::EDGECONST; 132 + $edge_dst = $merchant->getPHID(); 133 + 134 + id(new PhabricatorEdgeEditor()) 135 + ->addEdge($edge_src, $edge_type, $edge_dst) 136 + ->save(); 137 + 138 + return $this; 139 + } 118 140 119 141 /* -( PhabricatorApplicationTransactionInterface )------------------------- */ 120 142
+4
src/applications/phortune/storage/PhortuneSubscription.php
··· 161 161 } 162 162 $this->saveTransaction(); 163 163 164 + $account = $this->getAccount(); 165 + $merchant = $this->getMerchant(); 166 + $account->writeMerchantEdge($merchant); 167 + 164 168 return $result; 165 169 } 166 170