Skip to content

Commit 0817eb1

Browse files
author
Josh Cox
committed
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
1 parent 9329e6a commit 0817eb1

File tree

6 files changed

+113
-272
lines changed

6 files changed

+113
-272
lines changed

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,6 +3184,7 @@
31843184
'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php',
31853185
'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php',
31863186
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
3187+
'PhabricatorPhurlURLEditEngine' => 'applications/phurl/editor/PhabricatorPhurlURLEditEngine.php',
31873188
'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php',
31883189
'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php',
31893190
'PhabricatorPhurlURLMailReceiver' => 'applications/phurl/mail/PhabricatorPhurlURLMailReceiver.php',
@@ -8097,6 +8098,7 @@
80978098
'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController',
80988099
'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability',
80998100
'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController',
8101+
'PhabricatorPhurlURLEditEngine' => 'PhabricatorEditEngine',
81008102
'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor',
81018103
'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',
81028104
'PhabricatorPhurlURLMailReceiver' => 'PhabricatorObjectMailReceiver',

src/applications/paste/application/PhabricatorPasteApplication.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public function getRoutes() {
3838
=> 'PhabricatorPasteViewController',
3939
'/paste/' => array(
4040
'(query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorPasteListController',
41-
'create/' => 'PhabricatorPasteEditController',
4241
$this->getEditRoutePattern('edit/') => 'PhabricatorPasteEditController',
4342
'raw/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteRawController',
4443
'archive/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteArchiveController',

src/applications/phurl/application/PhabricatorPhurlApplication.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ public function getRoutes() {
4646
'(?:query/(?P<queryKey>[^/]+)/)?'
4747
=> 'PhabricatorPhurlURLListController',
4848
'url/' => array(
49-
'create/'
50-
=> 'PhabricatorPhurlURLEditController',
51-
'edit/(?P<id>[1-9]\d*)/'
49+
$this->getEditRoutePattern('edit/')
5250
=> 'PhabricatorPhurlURLEditController',
5351
'comment/(?P<id>[1-9]\d*)/'
5452
=> 'PhabricatorPhurlURLCommentController',

src/applications/phurl/controller/PhabricatorPhurlController.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,10 @@
33
abstract class PhabricatorPhurlController extends PhabricatorController {
44

55
protected function buildApplicationCrumbs() {
6-
$can_create = $this->hasApplicationCapability(
7-
PhabricatorPhurlURLCreateCapability::CAPABILITY);
8-
96
$crumbs = parent::buildApplicationCrumbs();
10-
$crumbs->addAction(
11-
id(new PHUIListItemView())
12-
->setName(pht('Shorten URL'))
13-
->setHref($this->getApplicationURI().'url/create/')
14-
->setIcon('fa-plus-square')
15-
->setDisabled(!$can_create)
16-
->setWorkflow(!$can_create));
7+
id(new PhabricatorPhurlURLEditEngine())
8+
->setViewer($this->getViewer())
9+
->addActionToCrumbs($crumbs);
1710

1811
return $crumbs;
1912
}

src/applications/phurl/controller/PhabricatorPhurlURLEditController.php

Lines changed: 3 additions & 258 deletions
Original file line numberDiff line numberDiff line change
@@ -4,263 +4,8 @@ final class PhabricatorPhurlURLEditController
44
extends PhabricatorPhurlController {
55

66
public function handleRequest(AphrontRequest $request) {
7-
$id = $request->getURIData('id');
8-
$is_create = !$id;
9-
10-
$viewer = $this->getViewer();
11-
$user_phid = $viewer->getPHID();
12-
$error_long_url = true;
13-
$error_alias = null;
14-
$validation_exception = null;
15-
16-
$next_workflow = $request->getStr('next');
17-
$uri_query = $request->getStr('query');
18-
19-
if ($is_create) {
20-
$this->requireApplicationCapability(
21-
PhabricatorPhurlURLCreateCapability::CAPABILITY);
22-
23-
$url = PhabricatorPhurlURL::initializeNewPhurlURL(
24-
$viewer);
25-
$submit_label = pht('Create');
26-
$page_title = pht('Shorten URL');
27-
$header_icon = 'fa-plus-square';
28-
$subscribers = array();
29-
$cancel_uri = $this->getApplicationURI();
30-
} else {
31-
$url = id(new PhabricatorPhurlURLQuery())
32-
->setViewer($viewer)
33-
->withIDs(array($id))
34-
->requireCapabilities(
35-
array(
36-
PhabricatorPolicyCapability::CAN_VIEW,
37-
PhabricatorPolicyCapability::CAN_EDIT,
38-
))
39-
->executeOne();
40-
41-
if (!$url) {
42-
return new Aphront404Response();
43-
}
44-
45-
$submit_label = pht('Update');
46-
$page_title = pht('Edit URL: %s', $url->getName());
47-
$header_icon = 'fa-pencil';
48-
49-
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
50-
$url->getPHID());
51-
52-
$cancel_uri = '/U'.$url->getID();
53-
}
54-
55-
if ($is_create) {
56-
$projects = array();
57-
} else {
58-
$projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
59-
$url->getPHID(),
60-
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
61-
$projects = array_reverse($projects);
62-
}
63-
64-
$name = $url->getName();
65-
$long_url = $url->getLongURL();
66-
$alias = $url->getAlias();
67-
$description = $url->getDescription();
68-
$edit_policy = $url->getEditPolicy();
69-
$view_policy = $url->getViewPolicy();
70-
$space = $url->getSpacePHID();
71-
72-
if ($request->isFormPost()) {
73-
$xactions = array();
74-
$name = $request->getStr('name');
75-
$long_url = $request->getStr('longURL');
76-
$alias = $request->getStr('alias');
77-
$projects = $request->getArr('projects');
78-
$description = $request->getStr('description');
79-
$subscribers = $request->getArr('subscribers');
80-
$edit_policy = $request->getStr('editPolicy');
81-
$view_policy = $request->getStr('viewPolicy');
82-
$space = $request->getStr('spacePHID');
83-
84-
$xactions[] = id(new PhabricatorPhurlURLTransaction())
85-
->setTransactionType(
86-
PhabricatorPhurlURLTransaction::TYPE_NAME)
87-
->setNewValue($name);
88-
89-
$xactions[] = id(new PhabricatorPhurlURLTransaction())
90-
->setTransactionType(
91-
PhabricatorPhurlURLTransaction::TYPE_URL)
92-
->setNewValue($long_url);
93-
94-
$xactions[] = id(new PhabricatorPhurlURLTransaction())
95-
->setTransactionType(
96-
PhabricatorPhurlURLTransaction::TYPE_ALIAS)
97-
->setNewValue($alias);
98-
99-
$xactions[] = id(new PhabricatorPhurlURLTransaction())
100-
->setTransactionType(
101-
PhabricatorTransactions::TYPE_SUBSCRIBERS)
102-
->setNewValue(array('=' => array_fuse($subscribers)));
103-
104-
$xactions[] = id(new PhabricatorPhurlURLTransaction())
105-
->setTransactionType(
106-
PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION)
107-
->setNewValue($description);
108-
109-
$xactions[] = id(new PhabricatorPhurlURLTransaction())
110-
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
111-
->setNewValue($view_policy);
112-
113-
$xactions[] = id(new PhabricatorPhurlURLTransaction())
114-
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
115-
->setNewValue($edit_policy);
116-
117-
$xactions[] = id(new PhabricatorPhurlURLTransaction())
118-
->setTransactionType(PhabricatorTransactions::TYPE_SPACE)
119-
->setNewValue($space);
120-
121-
$editor = id(new PhabricatorPhurlURLEditor())
122-
->setActor($viewer)
123-
->setContentSourceFromRequest($request)
124-
->setContinueOnNoEffect(true);
125-
126-
try {
127-
$proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
128-
$xactions[] = id(new PhabricatorPhurlURLTransaction())
129-
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
130-
->setMetadataValue('edge:type', $proj_edge_type)
131-
->setNewValue(array('=' => array_fuse($projects)));
132-
133-
$xactions = $editor->applyTransactions($url, $xactions);
134-
return id(new AphrontRedirectResponse())
135-
->setURI($url->getURI());
136-
} catch (PhabricatorApplicationTransactionValidationException $ex) {
137-
$validation_exception = $ex;
138-
$error_long_url = $ex->getShortMessage(
139-
PhabricatorPhurlURLTransaction::TYPE_URL);
140-
$error_alias = $ex->getShortMessage(
141-
PhabricatorPhurlURLTransaction::TYPE_ALIAS);
142-
}
143-
}
144-
145-
$current_policies = id(new PhabricatorPolicyQuery())
146-
->setViewer($viewer)
147-
->setObject($url)
148-
->execute();
149-
150-
$name = id(new AphrontFormTextControl())
151-
->setLabel(pht('Name'))
152-
->setName('name')
153-
->setValue($name);
154-
155-
$long_url = id(new AphrontFormTextControl())
156-
->setLabel(pht('URL'))
157-
->setName('longURL')
158-
->setValue($long_url)
159-
->setError($error_long_url);
160-
161-
$alias = id(new AphrontFormTextControl())
162-
->setLabel(pht('Alias'))
163-
->setName('alias')
164-
->setValue($alias)
165-
->setError($error_alias);
166-
167-
$projects = id(new AphrontFormTokenizerControl())
168-
->setLabel(pht('Tags'))
169-
->setName('projects')
170-
->setValue($projects)
171-
->setUser($viewer)
172-
->setDatasource(new PhabricatorProjectDatasource());
173-
174-
$description = id(new PhabricatorRemarkupControl())
175-
->setLabel(pht('Description'))
176-
->setName('description')
177-
->setValue($description)
178-
->setUser($viewer);
179-
180-
$view_policies = id(new AphrontFormPolicyControl())
181-
->setUser($viewer)
182-
->setValue($view_policy)
183-
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
184-
->setPolicyObject($url)
185-
->setPolicies($current_policies)
186-
->setSpacePHID($space)
187-
->setName('viewPolicy');
188-
$edit_policies = id(new AphrontFormPolicyControl())
189-
->setUser($viewer)
190-
->setValue($edit_policy)
191-
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
192-
->setPolicyObject($url)
193-
->setPolicies($current_policies)
194-
->setName('editPolicy');
195-
196-
$subscribers = id(new AphrontFormTokenizerControl())
197-
->setLabel(pht('Subscribers'))
198-
->setName('subscribers')
199-
->setValue($subscribers)
200-
->setUser($viewer)
201-
->setDatasource(new PhabricatorMetaMTAMailableDatasource());
202-
203-
$form = id(new AphrontFormView())
204-
->setUser($viewer)
205-
->appendChild($name)
206-
->appendChild($long_url)
207-
->appendChild($alias)
208-
->appendControl($view_policies)
209-
->appendControl($edit_policies)
210-
->appendControl($subscribers)
211-
->appendChild($projects)
212-
->appendChild($description);
213-
214-
215-
if ($request->isAjax()) {
216-
return $this->newDialog()
217-
->setTitle($page_title)
218-
->setWidth(AphrontDialogView::WIDTH_FULL)
219-
->appendForm($form)
220-
->addCancelButton($cancel_uri)
221-
->addSubmitButton($submit_label);
222-
}
223-
224-
$submit = id(new AphrontFormSubmitControl())
225-
->addCancelButton($cancel_uri)
226-
->setValue($submit_label);
227-
228-
$form->appendChild($submit);
229-
230-
$form_box = id(new PHUIObjectBoxView())
231-
->setHeaderText($page_title)
232-
->setForm($form);
233-
234-
$crumbs = $this->buildApplicationCrumbs();
235-
236-
if (!$is_create) {
237-
$crumbs->addTextCrumb($url->getMonogram(), $url->getURI());
238-
} else {
239-
$crumbs->addTextCrumb(pht('Create URL'));
240-
}
241-
242-
$crumbs->addTextCrumb($page_title);
243-
$crumbs->setBorder(true);
244-
245-
$object_box = id(new PHUIObjectBoxView())
246-
->setHeaderText(pht('URL'))
247-
->setValidationException($validation_exception)
248-
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
249-
->appendChild($form);
250-
251-
$header = id(new PHUIHeaderView())
252-
->setHeader($page_title)
253-
->setHeaderIcon($header_icon);
254-
255-
$view = id(new PHUITwoColumnView())
256-
->setHeader($header)
257-
->setFooter(array(
258-
$object_box,
259-
));
260-
261-
return $this->newPage()
262-
->setTitle($page_title)
263-
->setCrumbs($crumbs)
264-
->appendChild($view);
7+
return id(new PhabricatorPhurlURLEditEngine())
8+
->setController($this)
9+
->buildResponse();
26510
}
26611
}

0 commit comments

Comments
 (0)