@@ -4,263 +4,8 @@ final class PhabricatorPhurlURLEditController
4
4
extends PhabricatorPhurlController {
5
5
6
6
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 ();
265
10
}
266
11
}
0 commit comments