mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Update Phurl to use EditEngine
Summary: Fixes T10673. Set up Phurl to use Edit Engine. There's no way this is all I needed to do to get it working, so I'll be making another pass at it and testing more thoroughly... Test Plan: Ran through the Phurl URL creation/edit/deletion process. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley, yelirekim Maniphest Tasks: T10673 Differential Revision: https://secure.phabricator.com/D16573
This commit is contained in:
parent
9329e6a12d
commit
0817eb14a9
6 changed files with 113 additions and 272 deletions
|
@ -3184,6 +3184,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php',
|
||||
'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php',
|
||||
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
|
||||
'PhabricatorPhurlURLEditEngine' => 'applications/phurl/editor/PhabricatorPhurlURLEditEngine.php',
|
||||
'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php',
|
||||
'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php',
|
||||
'PhabricatorPhurlURLMailReceiver' => 'applications/phurl/mail/PhabricatorPhurlURLMailReceiver.php',
|
||||
|
@ -8097,6 +8098,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController',
|
||||
'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability',
|
||||
'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController',
|
||||
'PhabricatorPhurlURLEditEngine' => 'PhabricatorEditEngine',
|
||||
'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',
|
||||
'PhabricatorPhurlURLMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||
|
|
|
@ -38,7 +38,6 @@ final class PhabricatorPasteApplication extends PhabricatorApplication {
|
|||
=> 'PhabricatorPasteViewController',
|
||||
'/paste/' => array(
|
||||
'(query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorPasteListController',
|
||||
'create/' => 'PhabricatorPasteEditController',
|
||||
$this->getEditRoutePattern('edit/') => 'PhabricatorPasteEditController',
|
||||
'raw/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteRawController',
|
||||
'archive/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteArchiveController',
|
||||
|
|
|
@ -46,9 +46,7 @@ final class PhabricatorPhurlApplication extends PhabricatorApplication {
|
|||
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||
=> 'PhabricatorPhurlURLListController',
|
||||
'url/' => array(
|
||||
'create/'
|
||||
=> 'PhabricatorPhurlURLEditController',
|
||||
'edit/(?P<id>[1-9]\d*)/'
|
||||
$this->getEditRoutePattern('edit/')
|
||||
=> 'PhabricatorPhurlURLEditController',
|
||||
'comment/(?P<id>[1-9]\d*)/'
|
||||
=> 'PhabricatorPhurlURLCommentController',
|
||||
|
|
|
@ -3,17 +3,10 @@
|
|||
abstract class PhabricatorPhurlController extends PhabricatorController {
|
||||
|
||||
protected function buildApplicationCrumbs() {
|
||||
$can_create = $this->hasApplicationCapability(
|
||||
PhabricatorPhurlURLCreateCapability::CAPABILITY);
|
||||
|
||||
$crumbs = parent::buildApplicationCrumbs();
|
||||
$crumbs->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setName(pht('Shorten URL'))
|
||||
->setHref($this->getApplicationURI().'url/create/')
|
||||
->setIcon('fa-plus-square')
|
||||
->setDisabled(!$can_create)
|
||||
->setWorkflow(!$can_create));
|
||||
id(new PhabricatorPhurlURLEditEngine())
|
||||
->setViewer($this->getViewer())
|
||||
->addActionToCrumbs($crumbs);
|
||||
|
||||
return $crumbs;
|
||||
}
|
||||
|
|
|
@ -4,263 +4,8 @@ final class PhabricatorPhurlURLEditController
|
|||
extends PhabricatorPhurlController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$id = $request->getURIData('id');
|
||||
$is_create = !$id;
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
$user_phid = $viewer->getPHID();
|
||||
$error_long_url = true;
|
||||
$error_alias = null;
|
||||
$validation_exception = null;
|
||||
|
||||
$next_workflow = $request->getStr('next');
|
||||
$uri_query = $request->getStr('query');
|
||||
|
||||
if ($is_create) {
|
||||
$this->requireApplicationCapability(
|
||||
PhabricatorPhurlURLCreateCapability::CAPABILITY);
|
||||
|
||||
$url = PhabricatorPhurlURL::initializeNewPhurlURL(
|
||||
$viewer);
|
||||
$submit_label = pht('Create');
|
||||
$page_title = pht('Shorten URL');
|
||||
$header_icon = 'fa-plus-square';
|
||||
$subscribers = array();
|
||||
$cancel_uri = $this->getApplicationURI();
|
||||
} else {
|
||||
$url = id(new PhabricatorPhurlURLQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
|
||||
if (!$url) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$submit_label = pht('Update');
|
||||
$page_title = pht('Edit URL: %s', $url->getName());
|
||||
$header_icon = 'fa-pencil';
|
||||
|
||||
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
||||
$url->getPHID());
|
||||
|
||||
$cancel_uri = '/U'.$url->getID();
|
||||
}
|
||||
|
||||
if ($is_create) {
|
||||
$projects = array();
|
||||
} else {
|
||||
$projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||
$url->getPHID(),
|
||||
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
|
||||
$projects = array_reverse($projects);
|
||||
}
|
||||
|
||||
$name = $url->getName();
|
||||
$long_url = $url->getLongURL();
|
||||
$alias = $url->getAlias();
|
||||
$description = $url->getDescription();
|
||||
$edit_policy = $url->getEditPolicy();
|
||||
$view_policy = $url->getViewPolicy();
|
||||
$space = $url->getSpacePHID();
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$xactions = array();
|
||||
$name = $request->getStr('name');
|
||||
$long_url = $request->getStr('longURL');
|
||||
$alias = $request->getStr('alias');
|
||||
$projects = $request->getArr('projects');
|
||||
$description = $request->getStr('description');
|
||||
$subscribers = $request->getArr('subscribers');
|
||||
$edit_policy = $request->getStr('editPolicy');
|
||||
$view_policy = $request->getStr('viewPolicy');
|
||||
$space = $request->getStr('spacePHID');
|
||||
|
||||
$xactions[] = id(new PhabricatorPhurlURLTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorPhurlURLTransaction::TYPE_NAME)
|
||||
->setNewValue($name);
|
||||
|
||||
$xactions[] = id(new PhabricatorPhurlURLTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorPhurlURLTransaction::TYPE_URL)
|
||||
->setNewValue($long_url);
|
||||
|
||||
$xactions[] = id(new PhabricatorPhurlURLTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorPhurlURLTransaction::TYPE_ALIAS)
|
||||
->setNewValue($alias);
|
||||
|
||||
$xactions[] = id(new PhabricatorPhurlURLTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorTransactions::TYPE_SUBSCRIBERS)
|
||||
->setNewValue(array('=' => array_fuse($subscribers)));
|
||||
|
||||
$xactions[] = id(new PhabricatorPhurlURLTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION)
|
||||
->setNewValue($description);
|
||||
|
||||
$xactions[] = id(new PhabricatorPhurlURLTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
||||
->setNewValue($view_policy);
|
||||
|
||||
$xactions[] = id(new PhabricatorPhurlURLTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
|
||||
->setNewValue($edit_policy);
|
||||
|
||||
$xactions[] = id(new PhabricatorPhurlURLTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_SPACE)
|
||||
->setNewValue($space);
|
||||
|
||||
$editor = id(new PhabricatorPhurlURLEditor())
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnNoEffect(true);
|
||||
|
||||
try {
|
||||
$proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
|
||||
$xactions[] = id(new PhabricatorPhurlURLTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
||||
->setMetadataValue('edge:type', $proj_edge_type)
|
||||
->setNewValue(array('=' => array_fuse($projects)));
|
||||
|
||||
$xactions = $editor->applyTransactions($url, $xactions);
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI($url->getURI());
|
||||
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||
$validation_exception = $ex;
|
||||
$error_long_url = $ex->getShortMessage(
|
||||
PhabricatorPhurlURLTransaction::TYPE_URL);
|
||||
$error_alias = $ex->getShortMessage(
|
||||
PhabricatorPhurlURLTransaction::TYPE_ALIAS);
|
||||
}
|
||||
}
|
||||
|
||||
$current_policies = id(new PhabricatorPolicyQuery())
|
||||
->setViewer($viewer)
|
||||
->setObject($url)
|
||||
->execute();
|
||||
|
||||
$name = id(new AphrontFormTextControl())
|
||||
->setLabel(pht('Name'))
|
||||
->setName('name')
|
||||
->setValue($name);
|
||||
|
||||
$long_url = id(new AphrontFormTextControl())
|
||||
->setLabel(pht('URL'))
|
||||
->setName('longURL')
|
||||
->setValue($long_url)
|
||||
->setError($error_long_url);
|
||||
|
||||
$alias = id(new AphrontFormTextControl())
|
||||
->setLabel(pht('Alias'))
|
||||
->setName('alias')
|
||||
->setValue($alias)
|
||||
->setError($error_alias);
|
||||
|
||||
$projects = id(new AphrontFormTokenizerControl())
|
||||
->setLabel(pht('Tags'))
|
||||
->setName('projects')
|
||||
->setValue($projects)
|
||||
->setUser($viewer)
|
||||
->setDatasource(new PhabricatorProjectDatasource());
|
||||
|
||||
$description = id(new PhabricatorRemarkupControl())
|
||||
->setLabel(pht('Description'))
|
||||
->setName('description')
|
||||
->setValue($description)
|
||||
->setUser($viewer);
|
||||
|
||||
$view_policies = id(new AphrontFormPolicyControl())
|
||||
->setUser($viewer)
|
||||
->setValue($view_policy)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
||||
->setPolicyObject($url)
|
||||
->setPolicies($current_policies)
|
||||
->setSpacePHID($space)
|
||||
->setName('viewPolicy');
|
||||
$edit_policies = id(new AphrontFormPolicyControl())
|
||||
->setUser($viewer)
|
||||
->setValue($edit_policy)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
||||
->setPolicyObject($url)
|
||||
->setPolicies($current_policies)
|
||||
->setName('editPolicy');
|
||||
|
||||
$subscribers = id(new AphrontFormTokenizerControl())
|
||||
->setLabel(pht('Subscribers'))
|
||||
->setName('subscribers')
|
||||
->setValue($subscribers)
|
||||
->setUser($viewer)
|
||||
->setDatasource(new PhabricatorMetaMTAMailableDatasource());
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($viewer)
|
||||
->appendChild($name)
|
||||
->appendChild($long_url)
|
||||
->appendChild($alias)
|
||||
->appendControl($view_policies)
|
||||
->appendControl($edit_policies)
|
||||
->appendControl($subscribers)
|
||||
->appendChild($projects)
|
||||
->appendChild($description);
|
||||
|
||||
|
||||
if ($request->isAjax()) {
|
||||
return $this->newDialog()
|
||||
->setTitle($page_title)
|
||||
->setWidth(AphrontDialogView::WIDTH_FULL)
|
||||
->appendForm($form)
|
||||
->addCancelButton($cancel_uri)
|
||||
->addSubmitButton($submit_label);
|
||||
}
|
||||
|
||||
$submit = id(new AphrontFormSubmitControl())
|
||||
->addCancelButton($cancel_uri)
|
||||
->setValue($submit_label);
|
||||
|
||||
$form->appendChild($submit);
|
||||
|
||||
$form_box = id(new PHUIObjectBoxView())
|
||||
->setHeaderText($page_title)
|
||||
->setForm($form);
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
|
||||
if (!$is_create) {
|
||||
$crumbs->addTextCrumb($url->getMonogram(), $url->getURI());
|
||||
} else {
|
||||
$crumbs->addTextCrumb(pht('Create URL'));
|
||||
}
|
||||
|
||||
$crumbs->addTextCrumb($page_title);
|
||||
$crumbs->setBorder(true);
|
||||
|
||||
$object_box = id(new PHUIObjectBoxView())
|
||||
->setHeaderText(pht('URL'))
|
||||
->setValidationException($validation_exception)
|
||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
||||
->appendChild($form);
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setHeader($page_title)
|
||||
->setHeaderIcon($header_icon);
|
||||
|
||||
$view = id(new PHUITwoColumnView())
|
||||
->setHeader($header)
|
||||
->setFooter(array(
|
||||
$object_box,
|
||||
));
|
||||
|
||||
return $this->newPage()
|
||||
->setTitle($page_title)
|
||||
->setCrumbs($crumbs)
|
||||
->appendChild($view);
|
||||
return id(new PhabricatorPhurlURLEditEngine())
|
||||
->setController($this)
|
||||
->buildResponse();
|
||||
}
|
||||
}
|
||||
|
|
104
src/applications/phurl/editor/PhabricatorPhurlURLEditEngine.php
Normal file
104
src/applications/phurl/editor/PhabricatorPhurlURLEditEngine.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPhurlURLEditEngine
|
||||
extends PhabricatorEditEngine {
|
||||
|
||||
const ENGINECONST = 'phurl.url';
|
||||
|
||||
public function getEngineName() {
|
||||
return pht('Phurl');
|
||||
}
|
||||
|
||||
public function getEngineApplicationClass() {
|
||||
return 'PhabricatorPhurlApplication';
|
||||
}
|
||||
|
||||
public function getSummaryHeader() {
|
||||
return pht('Configure Phurl Forms');
|
||||
}
|
||||
|
||||
public function getSummaryText() {
|
||||
return pht('Configure creation and editing forms in Phurl.');
|
||||
}
|
||||
|
||||
protected function newEditableObject() {
|
||||
return PhabricatorPhurlURL::initializeNewPhurlURL($this->getViewer());
|
||||
}
|
||||
|
||||
protected function newObjectQuery() {
|
||||
return new PhabricatorPhurlURLQuery();
|
||||
}
|
||||
|
||||
protected function getObjectCreateTitleText($object) {
|
||||
return pht('Create New URL');
|
||||
}
|
||||
|
||||
protected function getObjectEditTitleText($object) {
|
||||
return pht('Edit URL: %s', $object->getName());
|
||||
}
|
||||
|
||||
protected function getObjectEditShortText($object) {
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
protected function getObjectCreateShortText() {
|
||||
return pht('Create URL');
|
||||
}
|
||||
|
||||
protected function getObjectName() {
|
||||
return pht('URL');
|
||||
}
|
||||
|
||||
protected function getObjectCreateCancelURI($object) {
|
||||
return $this->getApplication()->getApplicationURI('/');
|
||||
}
|
||||
|
||||
protected function getEditorURI() {
|
||||
return $this->getApplication()->getApplicationURI('url/edit/');
|
||||
}
|
||||
|
||||
protected function getObjectViewURI($object) {
|
||||
return $object->getURI();
|
||||
}
|
||||
|
||||
protected function getCreateNewObjectPolicy() {
|
||||
return $this->getApplication()->getPolicy(
|
||||
PhabricatorPhurlURLCreateCapability::CAPABILITY);
|
||||
}
|
||||
|
||||
protected function buildCustomEditFields($object) {
|
||||
|
||||
return array(
|
||||
id(new PhabricatorTextEditField())
|
||||
->setKey('name')
|
||||
->setLabel(pht('Name'))
|
||||
->setDescription(pht('URL name.'))
|
||||
->setConduitTypeDescription(pht('New URL name.'))
|
||||
->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_NAME)
|
||||
->setValue($object->getName()),
|
||||
id(new PhabricatorTextEditField())
|
||||
->setKey('url')
|
||||
->setLabel(pht('URL'))
|
||||
->setDescription(pht('The URL to shorten.'))
|
||||
->setConduitTypeDescription(pht('New URL.'))
|
||||
->setValue($object->getLongURL())
|
||||
->setIsRequired(true)
|
||||
->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_URL),
|
||||
id(new PhabricatorTextEditField())
|
||||
->setKey('alias')
|
||||
->setLabel(pht('Alias'))
|
||||
->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_ALIAS)
|
||||
->setDescription(pht('The alias to give the URL.'))
|
||||
->setConduitTypeDescription(pht('New alias.'))
|
||||
->setValue($object->getAlias()),
|
||||
id(new PhabricatorRemarkupEditField())
|
||||
->setKey('description')
|
||||
->setLabel(pht('Description'))
|
||||
->setDescription(pht('URL long description.'))
|
||||
->setConduitTypeDescription(pht('New URL description.'))
|
||||
->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION)
|
||||
->setValue($object->getDescription()),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue