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

Update Phortune Merchant to EditEngine

Summary: Converts PhortuneMerchant to EditEngine.

Test Plan: Edits existing merchants fine, same issue as Conpherence when making new ones with permissions.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D16750

+128 -191
+2
src/__phutil_library_map__.php
··· 4180 4180 'PhortuneMerchantCapability' => 'applications/phortune/capability/PhortuneMerchantCapability.php', 4181 4181 'PhortuneMerchantController' => 'applications/phortune/controller/PhortuneMerchantController.php', 4182 4182 'PhortuneMerchantEditController' => 'applications/phortune/controller/PhortuneMerchantEditController.php', 4183 + 'PhortuneMerchantEditEngine' => 'applications/phortune/editor/PhortuneMerchantEditEngine.php', 4183 4184 'PhortuneMerchantEditor' => 'applications/phortune/editor/PhortuneMerchantEditor.php', 4184 4185 'PhortuneMerchantHasMemberEdgeType' => 'applications/phortune/edge/PhortuneMerchantHasMemberEdgeType.php', 4185 4186 'PhortuneMerchantInvoiceCreateController' => 'applications/phortune/controller/PhortuneMerchantInvoiceCreateController.php', ··· 9430 9431 'PhortuneMerchantCapability' => 'PhabricatorPolicyCapability', 9431 9432 'PhortuneMerchantController' => 'PhortuneController', 9432 9433 'PhortuneMerchantEditController' => 'PhortuneMerchantController', 9434 + 'PhortuneMerchantEditEngine' => 'PhabricatorEditEngine', 9433 9435 'PhortuneMerchantEditor' => 'PhabricatorApplicationTransactionEditor', 9434 9436 'PhortuneMerchantHasMemberEdgeType' => 'PhabricatorEdgeType', 9435 9437 'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantController',
+2 -1
src/applications/phortune/application/PhabricatorPhortuneApplication.php
··· 82 82 'merchant/' => array( 83 83 '(?:query/(?P<queryKey>[^/]+)/)?' => 'PhortuneMerchantListController', 84 84 'picture/(?:(?P<id>\d+)/)?' => 'PhortuneMerchantPictureController', 85 - 'edit/(?:(?P<id>\d+)/)?' => 'PhortuneMerchantEditController', 85 + $this->getEditRoutePattern('edit/') 86 + => 'PhortuneMerchantEditController', 86 87 'orders/(?P<merchantID>\d+)/(?:query/(?P<queryKey>[^/]+)/)?' 87 88 => 'PhortuneCartListController', 88 89 '(?P<merchantID>\d+)/' => array(
+4 -189
src/applications/phortune/controller/PhortuneMerchantEditController.php
··· 4 4 extends PhortuneMerchantController { 5 5 6 6 public function handleRequest(AphrontRequest $request) { 7 - $viewer = $request->getViewer(); 8 - $id = $request->getURIData('id'); 9 - 10 - if ($id) { 11 - $merchant = id(new PhortuneMerchantQuery()) 12 - ->setViewer($viewer) 13 - ->withIDs(array($id)) 14 - ->requireCapabilities( 15 - array( 16 - PhabricatorPolicyCapability::CAN_VIEW, 17 - PhabricatorPolicyCapability::CAN_EDIT, 18 - )) 19 - ->executeOne(); 20 - if (!$merchant) { 21 - return new Aphront404Response(); 22 - } 23 - $is_new = false; 24 - } else { 25 - $this->requireApplicationCapability( 26 - PhortuneMerchantCapability::CAPABILITY); 27 - 28 - $merchant = PhortuneMerchant::initializeNewMerchant($viewer); 29 - $merchant->attachMemberPHIDs(array($viewer->getPHID())); 30 - $is_new = true; 31 - } 32 - 33 - if ($is_new) { 34 - $title = pht('Create Merchant'); 35 - $button_text = pht('Create Merchant'); 36 - $cancel_uri = $this->getApplicationURI('merchant/'); 37 - } else { 38 - $title = pht( 39 - 'Edit Merchant %d %s', 40 - $merchant->getID(), 41 - $merchant->getName()); 42 - $button_text = pht('Save Changes'); 43 - $cancel_uri = $this->getApplicationURI( 44 - '/merchant/'.$merchant->getID().'/'); 45 - } 46 - 47 - $e_name = true; 48 - $v_name = $merchant->getName(); 49 - $v_desc = $merchant->getDescription(); 50 - $v_cont = $merchant->getContactInfo(); 51 - $v_members = $merchant->getMemberPHIDs(); 52 - $e_members = null; 53 - 54 - $validation_exception = null; 55 - if ($request->isFormPost()) { 56 - $v_name = $request->getStr('name'); 57 - $v_desc = $request->getStr('desc'); 58 - $v_cont = $request->getStr('cont'); 59 - $v_view = $request->getStr('viewPolicy'); 60 - $v_edit = $request->getStr('editPolicy'); 61 - $v_members = $request->getArr('memberPHIDs'); 62 - 63 - $type_name = PhortuneMerchantTransaction::TYPE_NAME; 64 - $type_desc = PhortuneMerchantTransaction::TYPE_DESCRIPTION; 65 - $type_cont = PhortuneMerchantTransaction::TYPE_CONTACTINFO; 66 - $type_edge = PhabricatorTransactions::TYPE_EDGE; 67 - $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; 68 - 69 - $edge_members = PhortuneMerchantHasMemberEdgeType::EDGECONST; 70 - 71 - $xactions = array(); 72 - 73 - $xactions[] = id(new PhortuneMerchantTransaction()) 74 - ->setTransactionType($type_name) 75 - ->setNewValue($v_name); 76 - 77 - $xactions[] = id(new PhortuneMerchantTransaction()) 78 - ->setTransactionType($type_desc) 79 - ->setNewValue($v_desc); 80 - 81 - $xactions[] = id(new PhortuneMerchantTransaction()) 82 - ->setTransactionType($type_cont) 83 - ->setNewValue($v_cont); 84 - 85 - $xactions[] = id(new PhortuneMerchantTransaction()) 86 - ->setTransactionType($type_view) 87 - ->setNewValue($v_view); 88 - 89 - $xactions[] = id(new PhortuneMerchantTransaction()) 90 - ->setTransactionType($type_edge) 91 - ->setMetadataValue('edge:type', $edge_members) 92 - ->setNewValue( 93 - array( 94 - '=' => array_fuse($v_members), 95 - )); 96 - 97 - $editor = id(new PhortuneMerchantEditor()) 98 - ->setActor($viewer) 99 - ->setContentSourceFromRequest($request) 100 - ->setContinueOnNoEffect(true); 101 - 102 - try { 103 - $editor->applyTransactions($merchant, $xactions); 104 - 105 - $id = $merchant->getID(); 106 - $merchant_uri = $this->getApplicationURI("merchant/{$id}/"); 107 - return id(new AphrontRedirectResponse())->setURI($merchant_uri); 108 - } catch (PhabricatorApplicationTransactionValidationException $ex) { 109 - $validation_exception = $ex; 110 - 111 - $e_name = $ex->getShortMessage($type_name); 112 - $e_mbmers = $ex->getShortMessage($type_edge); 113 - 114 - $merchant->setViewPolicy($v_view); 115 - } 116 - } 117 - 118 - $policies = id(new PhabricatorPolicyQuery()) 119 - ->setViewer($viewer) 120 - ->setObject($merchant) 121 - ->execute(); 122 - 123 - $form = id(new AphrontFormView()) 124 - ->setUser($viewer) 125 - ->appendChild( 126 - id(new AphrontFormTextControl()) 127 - ->setName('name') 128 - ->setLabel(pht('Name')) 129 - ->setValue($v_name) 130 - ->setError($e_name)) 131 - ->appendChild( 132 - id(new PhabricatorRemarkupControl()) 133 - ->setUser($viewer) 134 - ->setName('desc') 135 - ->setLabel(pht('Description')) 136 - ->setValue($v_desc)) 137 - ->appendChild( 138 - id(new PhabricatorRemarkupControl()) 139 - ->setUser($viewer) 140 - ->setName('cont') 141 - ->setLabel(pht('Contact Info')) 142 - ->setValue($v_cont)) 143 - ->appendControl( 144 - id(new AphrontFormTokenizerControl()) 145 - ->setDatasource(new PhabricatorPeopleDatasource()) 146 - ->setLabel(pht('Members')) 147 - ->setName('memberPHIDs') 148 - ->setValue($v_members) 149 - ->setError($e_members)) 150 - ->appendChild( 151 - id(new AphrontFormPolicyControl()) 152 - ->setName('viewPolicy') 153 - ->setPolicyObject($merchant) 154 - ->setCapability(PhabricatorPolicyCapability::CAN_VIEW) 155 - ->setPolicies($policies)) 156 - ->appendChild( 157 - id(new AphrontFormSubmitControl()) 158 - ->setValue($button_text) 159 - ->addCancelButton($cancel_uri)); 160 - 161 - $header = id(new PHUIHeaderView()) 162 - ->setHeader($title); 163 - 164 - $crumbs = $this->buildApplicationCrumbs(); 165 - if ($is_new) { 166 - $crumbs->addTextCrumb(pht('Create Merchant')); 167 - $header->setHeaderIcon('fa-plus-square'); 168 - } else { 169 - $crumbs->addTextCrumb( 170 - pht('Merchant %d', $merchant->getID()), 171 - $this->getApplicationURI('/merchant/'.$merchant->getID().'/')); 172 - $crumbs->addTextCrumb(pht('Edit')); 173 - $header->setHeaderIcon('fa-pencil'); 174 - } 175 - $crumbs->setBorder(true); 176 - 177 - $box = id(new PHUIObjectBoxView()) 178 - ->setHeaderText(pht('Merchant')) 179 - ->setValidationException($validation_exception) 180 - ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 181 - ->setForm($form); 182 - 183 - $view = id(new PHUITwoColumnView()) 184 - ->setHeader($header) 185 - ->setFooter(array( 186 - $box, 187 - )); 188 - 189 - return $this->newPage() 190 - ->setTitle($title) 191 - ->setCrumbs($crumbs) 192 - ->appendChild($view); 193 - 194 - } 195 - 7 + return id(new PhortuneMerchantEditEngine()) 8 + ->setController($this) 9 + ->buildResponse(); 10 + } 196 11 }
+120
src/applications/phortune/editor/PhortuneMerchantEditEngine.php
··· 1 + <?php 2 + 3 + final class PhortuneMerchantEditEngine 4 + extends PhabricatorEditEngine { 5 + 6 + const ENGINECONST = 'phortune.merchant'; 7 + 8 + public function getEngineName() { 9 + return pht('Phortune'); 10 + } 11 + 12 + public function getEngineApplicationClass() { 13 + return 'PhabricatorPhortuneApplication'; 14 + } 15 + 16 + public function getSummaryHeader() { 17 + return pht('Configure Phortune Merchant Forms'); 18 + } 19 + 20 + public function getSummaryText() { 21 + return pht('Configure creation and editing forms for Phortune Merchants.'); 22 + } 23 + 24 + protected function newEditableObject() { 25 + return PhortuneMerchant::initializeNewMerchant($this->getViewer()); 26 + } 27 + 28 + protected function newObjectQuery() { 29 + return new PhortuneMerchantQuery(); 30 + } 31 + 32 + protected function getObjectCreateTitleText($object) { 33 + return pht('Create New Merchant'); 34 + } 35 + 36 + protected function getObjectEditTitleText($object) { 37 + return pht('Edit Merchant: %s', $object->getName()); 38 + } 39 + 40 + protected function getObjectEditShortText($object) { 41 + return $object->getName(); 42 + } 43 + 44 + protected function getObjectCreateShortText() { 45 + return pht('Create Merchant'); 46 + } 47 + 48 + protected function getObjectName() { 49 + return pht('Merchant'); 50 + } 51 + 52 + protected function getObjectCreateCancelURI($object) { 53 + return $this->getApplication()->getApplicationURI('/'); 54 + } 55 + 56 + protected function getEditorURI() { 57 + return $this->getApplication()->getApplicationURI('edit/'); 58 + } 59 + 60 + protected function getObjectViewURI($object) { 61 + return $object->getViewURI(); 62 + } 63 + 64 + public function isEngineConfigurable() { 65 + return false; 66 + } 67 + 68 + protected function buildCustomEditFields($object) { 69 + $viewer = $this->getViewer(); 70 + 71 + if ($this->getIsCreate()) { 72 + $member_phids = array($viewer->getPHID()); 73 + } else { 74 + $member_phids = $object->getMemberPHIDs(); 75 + } 76 + 77 + return array( 78 + id(new PhabricatorTextEditField()) 79 + ->setKey('name') 80 + ->setLabel(pht('Name')) 81 + ->setDescription(pht('Merchant name.')) 82 + ->setConduitTypeDescription(pht('New Merchant name.')) 83 + ->setIsRequired(true) 84 + ->setTransactionType(PhortuneMerchantTransaction::TYPE_NAME) 85 + ->setValue($object->getName()), 86 + 87 + id(new PhabricatorRemarkupEditField()) 88 + ->setKey('description') 89 + ->setLabel(pht('Description')) 90 + ->setDescription(pht('Merchant description.')) 91 + ->setConduitTypeDescription(pht('New merchant description.')) 92 + ->setTransactionType(PhortuneMerchantTransaction::TYPE_DESCRIPTION) 93 + ->setValue($object->getDescription()), 94 + 95 + id(new PhabricatorRemarkupEditField()) 96 + ->setKey('contactInfo') 97 + ->setLabel(pht('Contact Info')) 98 + ->setDescription(pht('Merchant contact information.')) 99 + ->setConduitTypeDescription(pht('Merchant contact information.')) 100 + ->setTransactionType(PhortuneMerchantTransaction::TYPE_CONTACTINFO) 101 + ->setValue($object->getContactInfo()), 102 + 103 + id(new PhabricatorUsersEditField()) 104 + ->setKey('members') 105 + ->setAliases(array('memberPHIDs')) 106 + ->setLabel(pht('Members')) 107 + ->setUseEdgeTransactions(true) 108 + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 109 + ->setMetadataValue( 110 + 'edge:type', 111 + PhortuneMerchantHasMemberEdgeType::EDGECONST) 112 + ->setDescription(pht('Initial merchant members.')) 113 + ->setConduitDescription(pht('Set merchant members.')) 114 + ->setConduitTypeDescription(pht('New list of members.')) 115 + ->setValue($member_phids), 116 + 117 + ); 118 + } 119 + 120 + }
-1
src/applications/phortune/storage/PhortuneMerchant.php
··· 63 63 return $this->assertAttached($this->profileImageFile); 64 64 } 65 65 66 - 67 66 /* -( PhabricatorApplicationTransactionInterface )------------------------- */ 68 67 69 68