mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 12:52:42 +01:00
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
This commit is contained in:
parent
c3809b0d59
commit
0c9ecf8351
5 changed files with 128 additions and 191 deletions
|
@ -4180,6 +4180,7 @@ phutil_register_library_map(array(
|
|||
'PhortuneMerchantCapability' => 'applications/phortune/capability/PhortuneMerchantCapability.php',
|
||||
'PhortuneMerchantController' => 'applications/phortune/controller/PhortuneMerchantController.php',
|
||||
'PhortuneMerchantEditController' => 'applications/phortune/controller/PhortuneMerchantEditController.php',
|
||||
'PhortuneMerchantEditEngine' => 'applications/phortune/editor/PhortuneMerchantEditEngine.php',
|
||||
'PhortuneMerchantEditor' => 'applications/phortune/editor/PhortuneMerchantEditor.php',
|
||||
'PhortuneMerchantHasMemberEdgeType' => 'applications/phortune/edge/PhortuneMerchantHasMemberEdgeType.php',
|
||||
'PhortuneMerchantInvoiceCreateController' => 'applications/phortune/controller/PhortuneMerchantInvoiceCreateController.php',
|
||||
|
@ -9430,6 +9431,7 @@ phutil_register_library_map(array(
|
|||
'PhortuneMerchantCapability' => 'PhabricatorPolicyCapability',
|
||||
'PhortuneMerchantController' => 'PhortuneController',
|
||||
'PhortuneMerchantEditController' => 'PhortuneMerchantController',
|
||||
'PhortuneMerchantEditEngine' => 'PhabricatorEditEngine',
|
||||
'PhortuneMerchantEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'PhortuneMerchantHasMemberEdgeType' => 'PhabricatorEdgeType',
|
||||
'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantController',
|
||||
|
|
|
@ -82,7 +82,8 @@ final class PhabricatorPhortuneApplication extends PhabricatorApplication {
|
|||
'merchant/' => array(
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PhortuneMerchantListController',
|
||||
'picture/(?:(?P<id>\d+)/)?' => 'PhortuneMerchantPictureController',
|
||||
'edit/(?:(?P<id>\d+)/)?' => 'PhortuneMerchantEditController',
|
||||
$this->getEditRoutePattern('edit/')
|
||||
=> 'PhortuneMerchantEditController',
|
||||
'orders/(?P<merchantID>\d+)/(?:query/(?P<queryKey>[^/]+)/)?'
|
||||
=> 'PhortuneCartListController',
|
||||
'(?P<merchantID>\d+)/' => array(
|
||||
|
|
|
@ -4,193 +4,8 @@ final class PhortuneMerchantEditController
|
|||
extends PhortuneMerchantController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
if ($id) {
|
||||
$merchant = id(new PhortuneMerchantQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
if (!$merchant) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
$is_new = false;
|
||||
} else {
|
||||
$this->requireApplicationCapability(
|
||||
PhortuneMerchantCapability::CAPABILITY);
|
||||
|
||||
$merchant = PhortuneMerchant::initializeNewMerchant($viewer);
|
||||
$merchant->attachMemberPHIDs(array($viewer->getPHID()));
|
||||
$is_new = true;
|
||||
}
|
||||
|
||||
if ($is_new) {
|
||||
$title = pht('Create Merchant');
|
||||
$button_text = pht('Create Merchant');
|
||||
$cancel_uri = $this->getApplicationURI('merchant/');
|
||||
} else {
|
||||
$title = pht(
|
||||
'Edit Merchant %d %s',
|
||||
$merchant->getID(),
|
||||
$merchant->getName());
|
||||
$button_text = pht('Save Changes');
|
||||
$cancel_uri = $this->getApplicationURI(
|
||||
'/merchant/'.$merchant->getID().'/');
|
||||
}
|
||||
|
||||
$e_name = true;
|
||||
$v_name = $merchant->getName();
|
||||
$v_desc = $merchant->getDescription();
|
||||
$v_cont = $merchant->getContactInfo();
|
||||
$v_members = $merchant->getMemberPHIDs();
|
||||
$e_members = null;
|
||||
|
||||
$validation_exception = null;
|
||||
if ($request->isFormPost()) {
|
||||
$v_name = $request->getStr('name');
|
||||
$v_desc = $request->getStr('desc');
|
||||
$v_cont = $request->getStr('cont');
|
||||
$v_view = $request->getStr('viewPolicy');
|
||||
$v_edit = $request->getStr('editPolicy');
|
||||
$v_members = $request->getArr('memberPHIDs');
|
||||
|
||||
$type_name = PhortuneMerchantTransaction::TYPE_NAME;
|
||||
$type_desc = PhortuneMerchantTransaction::TYPE_DESCRIPTION;
|
||||
$type_cont = PhortuneMerchantTransaction::TYPE_CONTACTINFO;
|
||||
$type_edge = PhabricatorTransactions::TYPE_EDGE;
|
||||
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||
|
||||
$edge_members = PhortuneMerchantHasMemberEdgeType::EDGECONST;
|
||||
|
||||
$xactions = array();
|
||||
|
||||
$xactions[] = id(new PhortuneMerchantTransaction())
|
||||
->setTransactionType($type_name)
|
||||
->setNewValue($v_name);
|
||||
|
||||
$xactions[] = id(new PhortuneMerchantTransaction())
|
||||
->setTransactionType($type_desc)
|
||||
->setNewValue($v_desc);
|
||||
|
||||
$xactions[] = id(new PhortuneMerchantTransaction())
|
||||
->setTransactionType($type_cont)
|
||||
->setNewValue($v_cont);
|
||||
|
||||
$xactions[] = id(new PhortuneMerchantTransaction())
|
||||
->setTransactionType($type_view)
|
||||
->setNewValue($v_view);
|
||||
|
||||
$xactions[] = id(new PhortuneMerchantTransaction())
|
||||
->setTransactionType($type_edge)
|
||||
->setMetadataValue('edge:type', $edge_members)
|
||||
->setNewValue(
|
||||
array(
|
||||
'=' => array_fuse($v_members),
|
||||
));
|
||||
|
||||
$editor = id(new PhortuneMerchantEditor())
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnNoEffect(true);
|
||||
|
||||
try {
|
||||
$editor->applyTransactions($merchant, $xactions);
|
||||
|
||||
$id = $merchant->getID();
|
||||
$merchant_uri = $this->getApplicationURI("merchant/{$id}/");
|
||||
return id(new AphrontRedirectResponse())->setURI($merchant_uri);
|
||||
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||
$validation_exception = $ex;
|
||||
|
||||
$e_name = $ex->getShortMessage($type_name);
|
||||
$e_mbmers = $ex->getShortMessage($type_edge);
|
||||
|
||||
$merchant->setViewPolicy($v_view);
|
||||
return id(new PhortuneMerchantEditEngine())
|
||||
->setController($this)
|
||||
->buildResponse();
|
||||
}
|
||||
}
|
||||
|
||||
$policies = id(new PhabricatorPolicyQuery())
|
||||
->setViewer($viewer)
|
||||
->setObject($merchant)
|
||||
->execute();
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($viewer)
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setName('name')
|
||||
->setLabel(pht('Name'))
|
||||
->setValue($v_name)
|
||||
->setError($e_name))
|
||||
->appendChild(
|
||||
id(new PhabricatorRemarkupControl())
|
||||
->setUser($viewer)
|
||||
->setName('desc')
|
||||
->setLabel(pht('Description'))
|
||||
->setValue($v_desc))
|
||||
->appendChild(
|
||||
id(new PhabricatorRemarkupControl())
|
||||
->setUser($viewer)
|
||||
->setName('cont')
|
||||
->setLabel(pht('Contact Info'))
|
||||
->setValue($v_cont))
|
||||
->appendControl(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setDatasource(new PhabricatorPeopleDatasource())
|
||||
->setLabel(pht('Members'))
|
||||
->setName('memberPHIDs')
|
||||
->setValue($v_members)
|
||||
->setError($e_members))
|
||||
->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setName('viewPolicy')
|
||||
->setPolicyObject($merchant)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
||||
->setPolicies($policies))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue($button_text)
|
||||
->addCancelButton($cancel_uri));
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setHeader($title);
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
if ($is_new) {
|
||||
$crumbs->addTextCrumb(pht('Create Merchant'));
|
||||
$header->setHeaderIcon('fa-plus-square');
|
||||
} else {
|
||||
$crumbs->addTextCrumb(
|
||||
pht('Merchant %d', $merchant->getID()),
|
||||
$this->getApplicationURI('/merchant/'.$merchant->getID().'/'));
|
||||
$crumbs->addTextCrumb(pht('Edit'));
|
||||
$header->setHeaderIcon('fa-pencil');
|
||||
}
|
||||
$crumbs->setBorder(true);
|
||||
|
||||
$box = id(new PHUIObjectBoxView())
|
||||
->setHeaderText(pht('Merchant'))
|
||||
->setValidationException($validation_exception)
|
||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
||||
->setForm($form);
|
||||
|
||||
$view = id(new PHUITwoColumnView())
|
||||
->setHeader($header)
|
||||
->setFooter(array(
|
||||
$box,
|
||||
));
|
||||
|
||||
return $this->newPage()
|
||||
->setTitle($title)
|
||||
->setCrumbs($crumbs)
|
||||
->appendChild($view);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
120
src/applications/phortune/editor/PhortuneMerchantEditEngine.php
Normal file
120
src/applications/phortune/editor/PhortuneMerchantEditEngine.php
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
final class PhortuneMerchantEditEngine
|
||||
extends PhabricatorEditEngine {
|
||||
|
||||
const ENGINECONST = 'phortune.merchant';
|
||||
|
||||
public function getEngineName() {
|
||||
return pht('Phortune');
|
||||
}
|
||||
|
||||
public function getEngineApplicationClass() {
|
||||
return 'PhabricatorPhortuneApplication';
|
||||
}
|
||||
|
||||
public function getSummaryHeader() {
|
||||
return pht('Configure Phortune Merchant Forms');
|
||||
}
|
||||
|
||||
public function getSummaryText() {
|
||||
return pht('Configure creation and editing forms for Phortune Merchants.');
|
||||
}
|
||||
|
||||
protected function newEditableObject() {
|
||||
return PhortuneMerchant::initializeNewMerchant($this->getViewer());
|
||||
}
|
||||
|
||||
protected function newObjectQuery() {
|
||||
return new PhortuneMerchantQuery();
|
||||
}
|
||||
|
||||
protected function getObjectCreateTitleText($object) {
|
||||
return pht('Create New Merchant');
|
||||
}
|
||||
|
||||
protected function getObjectEditTitleText($object) {
|
||||
return pht('Edit Merchant: %s', $object->getName());
|
||||
}
|
||||
|
||||
protected function getObjectEditShortText($object) {
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
protected function getObjectCreateShortText() {
|
||||
return pht('Create Merchant');
|
||||
}
|
||||
|
||||
protected function getObjectName() {
|
||||
return pht('Merchant');
|
||||
}
|
||||
|
||||
protected function getObjectCreateCancelURI($object) {
|
||||
return $this->getApplication()->getApplicationURI('/');
|
||||
}
|
||||
|
||||
protected function getEditorURI() {
|
||||
return $this->getApplication()->getApplicationURI('edit/');
|
||||
}
|
||||
|
||||
protected function getObjectViewURI($object) {
|
||||
return $object->getViewURI();
|
||||
}
|
||||
|
||||
public function isEngineConfigurable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function buildCustomEditFields($object) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
if ($this->getIsCreate()) {
|
||||
$member_phids = array($viewer->getPHID());
|
||||
} else {
|
||||
$member_phids = $object->getMemberPHIDs();
|
||||
}
|
||||
|
||||
return array(
|
||||
id(new PhabricatorTextEditField())
|
||||
->setKey('name')
|
||||
->setLabel(pht('Name'))
|
||||
->setDescription(pht('Merchant name.'))
|
||||
->setConduitTypeDescription(pht('New Merchant name.'))
|
||||
->setIsRequired(true)
|
||||
->setTransactionType(PhortuneMerchantTransaction::TYPE_NAME)
|
||||
->setValue($object->getName()),
|
||||
|
||||
id(new PhabricatorRemarkupEditField())
|
||||
->setKey('description')
|
||||
->setLabel(pht('Description'))
|
||||
->setDescription(pht('Merchant description.'))
|
||||
->setConduitTypeDescription(pht('New merchant description.'))
|
||||
->setTransactionType(PhortuneMerchantTransaction::TYPE_DESCRIPTION)
|
||||
->setValue($object->getDescription()),
|
||||
|
||||
id(new PhabricatorRemarkupEditField())
|
||||
->setKey('contactInfo')
|
||||
->setLabel(pht('Contact Info'))
|
||||
->setDescription(pht('Merchant contact information.'))
|
||||
->setConduitTypeDescription(pht('Merchant contact information.'))
|
||||
->setTransactionType(PhortuneMerchantTransaction::TYPE_CONTACTINFO)
|
||||
->setValue($object->getContactInfo()),
|
||||
|
||||
id(new PhabricatorUsersEditField())
|
||||
->setKey('members')
|
||||
->setAliases(array('memberPHIDs'))
|
||||
->setLabel(pht('Members'))
|
||||
->setUseEdgeTransactions(true)
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
||||
->setMetadataValue(
|
||||
'edge:type',
|
||||
PhortuneMerchantHasMemberEdgeType::EDGECONST)
|
||||
->setDescription(pht('Initial merchant members.'))
|
||||
->setConduitDescription(pht('Set merchant members.'))
|
||||
->setConduitTypeDescription(pht('New list of members.'))
|
||||
->setValue($member_phids),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -63,7 +63,6 @@ final class PhortuneMerchant extends PhortuneDAO
|
|||
return $this->assertAttached($this->profileImageFile);
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue