Skip to content

Commit a8271ec

Browse files
author
epriestley
committed
Remove most callsites to Controller->renderHandlesForPHIDs()
Summary: Ref T7689. This moves most of the easy/testable callsites off `Controller->renderHandlesForPHIDs()`. Test Plan: - Viewed a file; viewed author; viewed "attached" tab. - Viewed a mock; viewed attached tasks. - Viewed a credential; viewed "Used By". - Viewed a paste; viewed author; viewed forks; viewed forked from. - Viewed a dashboard; viewed panel list. - Viewed a dashboard panel; viewed "Appears On". - Viewed a Phortune account; viewed "Members"; viewed payment methods. - Viewed a Phortune merchant account; viewed "Members". - Viewed Phortune account switcher; viewed "Accounts". - I just removed "Members:" here since it felt kind of out-of-place anyway. - Viewed a Phragment fragment, viewed "Latest Version", viewed "Snapshots". - Viewed a Phargment snapshot, viewed "Fragment". Reviewers: btrahan Reviewed By: btrahan Subscribers: hach-que, epriestley Maniphest Tasks: T7689 Differential Revision: https://secure.phabricator.com/D12207
1 parent dec03cf commit a8271ec

14 files changed

+61
-64
lines changed

src/applications/dashboard/controller/PhabricatorDashboardManageController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,9 @@ private function buildPropertyView(PhabricatorDashboard $dashboard) {
165165
pht('Editable By'),
166166
$descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
167167

168-
$panel_phids = $dashboard->getPanelPHIDs();
169-
$this->loadHandles($panel_phids);
170-
171168
$properties->addProperty(
172169
pht('Panels'),
173-
$this->renderHandlesForPHIDs($panel_phids));
170+
$viewer->renderHandleList($dashboard->getPanelPHIDs()));
174171

175172
return $properties;
176173
}

src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,14 @@ private function buildPropertyView(PhabricatorDashboardPanel $panel) {
163163
$dashboard_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
164164
$panel->getPHID(),
165165
PhabricatorDashboardPanelHasDashboardEdgeType::EDGECONST);
166-
$this->loadHandles($dashboard_phids);
167166

168167
$does_not_appear = pht(
169168
'This panel does not appear on any dashboards.');
170169

171170
$properties->addProperty(
172171
pht('Appears On'),
173172
$dashboard_phids
174-
? $this->renderHandlesForPHIDs($dashboard_phids)
173+
? $viewer->renderHandleList($dashboard_phids)
175174
: phutil_tag('em', array(), $does_not_appear));
176175

177176
return $properties;

src/applications/files/controller/PhabricatorFileInfoController.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ public function processRequest() {
3939

4040
$phid = $file->getPHID();
4141

42-
$handle_phids = array_merge(
43-
array($file->getAuthorPHID()),
44-
$file->getObjectPHIDs());
45-
46-
$this->loadHandles($handle_phids);
4742
$header = id(new PHUIHeaderView())
4843
->setUser($user)
4944
->setPolicyObject($file)
@@ -185,15 +180,14 @@ private function buildPropertyViews(
185180
$request = $this->getRequest();
186181
$user = $request->getUser();
187182

188-
189183
$properties = id(new PHUIPropertyListView());
190184
$properties->setActionList($actions);
191185
$box->addPropertyList($properties, pht('Details'));
192186

193187
if ($file->getAuthorPHID()) {
194188
$properties->addProperty(
195189
pht('Author'),
196-
$this->getHandle($file->getAuthorPHID())->renderLink());
190+
$user->renderHandle($file->getAuthorPHID()));
197191
}
198192

199193
$properties->addProperty(
@@ -270,7 +264,7 @@ private function buildPropertyViews(
270264

271265
$attached->addProperty(
272266
pht('Attached To'),
273-
$this->renderHandlesForPHIDs($phids));
267+
$user->renderHandleList($phids));
274268
}
275269

276270

src/applications/passphrase/controller/PassphraseCredentialViewController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,9 @@ private function buildPropertyView(
189189
PhabricatorCredentialsUsedByObjectEdgeType::EDGECONST);
190190

191191
if ($used_by_phids) {
192-
$this->loadHandles($used_by_phids);
193192
$properties->addProperty(
194193
pht('Used By'),
195-
$this->renderHandlesForPHIDs($used_by_phids));
194+
$viewer->renderHandleList($used_by_phids));
196195
}
197196

198197
$description = $credential->getDescription();

src/applications/paste/controller/PhabricatorPasteViewController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,35 +176,35 @@ private function buildPropertyView(
176176
PhabricatorPaste $paste,
177177
array $child_phids,
178178
PhabricatorActionListView $actions) {
179+
$viewer = $this->getViewer();
179180

180-
$user = $this->getRequest()->getUser();
181181
$properties = id(new PHUIPropertyListView())
182-
->setUser($user)
182+
->setUser($viewer)
183183
->setObject($paste)
184184
->setActionList($actions);
185185

186186
$properties->addProperty(
187187
pht('Author'),
188-
$this->getHandle($paste->getAuthorPHID())->renderLink());
188+
$viewer->renderHandle($paste->getAuthorPHID()));
189189

190190
$properties->addProperty(
191191
pht('Created'),
192-
phabricator_datetime($paste->getDateCreated(), $user));
192+
phabricator_datetime($paste->getDateCreated(), $viewer));
193193

194194
if ($paste->getParentPHID()) {
195195
$properties->addProperty(
196196
pht('Forked From'),
197-
$this->getHandle($paste->getParentPHID())->renderLink());
197+
$viewer->renderHandle($paste->getParentPHID()));
198198
}
199199

200200
if ($child_phids) {
201201
$properties->addProperty(
202202
pht('Forks'),
203-
$this->renderHandlesForPHIDs($child_phids));
203+
$viewer->renderHandleList($child_phids));
204204
}
205205

206206
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
207-
$user,
207+
$viewer,
208208
$paste);
209209

210210
return $properties;

src/applications/people/storage/PhabricatorUser.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

33
/**
4-
* @task factors Multi-Factor Authentication
4+
* @task factors Multi-Factor Authentication
5+
* @task handles Managing Handles
56
*/
67
final class PhabricatorUser
78
extends PhabricatorUserDAO
@@ -801,7 +802,7 @@ public static function getOmnipotentUser() {
801802
}
802803

803804

804-
/* -( Handles )------------------------------------------------------------ */
805+
/* -( Managing Handles )--------------------------------------------------- */
805806

806807

807808
/**
@@ -810,6 +811,7 @@ public static function getOmnipotentUser() {
810811
*
811812
* @param list<phid> List of PHIDs to load.
812813
* @return PhabricatorHandleList Handle list object.
814+
* @task handle
813815
*/
814816
public function loadHandles(array $phids) {
815817
if ($this->handlePool === null) {
@@ -821,6 +823,34 @@ public function loadHandles(array $phids) {
821823
}
822824

823825

826+
/**
827+
* Get a @{class:PHUIHandleView} for a single handle.
828+
*
829+
* This benefits from the viewer's internal handle pool.
830+
*
831+
* @param phid PHID to render a handle for.
832+
* @return PHUIHandleView View of the handle.
833+
* @task handle
834+
*/
835+
public function renderHandle($phid) {
836+
return $this->loadHandles(array($phid))->renderHandle($phid);
837+
}
838+
839+
840+
/**
841+
* Get a @{class:PHUIHandleListView} for a list of handles.
842+
*
843+
* This benefits from the viewer's internal handle pool.
844+
*
845+
* @param list<phid> List of PHIDs to render.
846+
* @return PHUIHandleListView View of the handles.
847+
* @task handle
848+
*/
849+
public function renderHandleList(array $phids) {
850+
return $this->loadHandles($phids)->renderList();
851+
}
852+
853+
824854
/* -( PhabricatorPolicyInterface )----------------------------------------- */
825855

826856

src/applications/pholio/controller/PholioMockViewController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public function processRequest() {
4242
$mock->getPHID(),
4343
PholioMockHasTaskEdgeType::EDGECONST);
4444
$this->setManiphestTaskPHIDs($phids);
45-
$phids[] = $mock->getAuthorPHID();
46-
$this->loadHandles($phids);
4745

4846
$engine = id(new PhabricatorMarkupEngine())
4947
->setViewer($user);
@@ -167,7 +165,7 @@ private function buildPropertyView(
167165

168166
$properties->addProperty(
169167
pht('Author'),
170-
$this->getHandle($mock->getAuthorPHID())->renderLink());
168+
$user->renderHandle($mock->getAuthorPHID()));
171169

172170
$properties->addProperty(
173171
pht('Created'),
@@ -176,7 +174,7 @@ private function buildPropertyView(
176174
if ($this->getManiphestTaskPHIDs()) {
177175
$properties->addProperty(
178176
pht('Maniphest Tasks'),
179-
$this->renderHandlesForPHIDs($this->getManiphestTaskPHIDs()));
177+
$user->renderHandleList($this->getManiphestTaskPHIDs()));
180178
}
181179

182180
$properties->invokeWillRenderEvent();

src/applications/phortune/controller/PhortuneAccountListController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ public function processRequest() {
3636

3737
foreach ($accounts as $account) {
3838
$this->loadHandles($account->getMemberPHIDs());
39-
$members = $this->renderHandlesForPHIDs($account->getMemberPHIDs(), ',');
4039
$item = id(new PHUIObjectItemView())
4140
->setObjectName(pht('Account %d', $account->getID()))
4241
->setHeader($account->getName())
4342
->setHref($this->getApplicationURI($account->getID().'/'))
44-
->addAttribute(pht('Members: %s', $members))
4543
->setObject($account);
4644

4745
$payment_list->addItem($item);

src/applications/phortune/controller/PhortuneAccountViewController.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@ public function handleRequest(AphrontRequest $request) {
5757
->setObject($account)
5858
->setUser($viewer);
5959

60-
$this->loadHandles($account->getMemberPHIDs());
61-
6260
$properties->addProperty(
6361
pht('Members'),
64-
$this->renderHandlesForPHIDs($account->getMemberPHIDs()));
62+
$viewer->renderHandleList($account->getMemberPHIDs()));
6563

6664
$status_items = $this->getStatusItemsForAccount($account, $invoices);
6765
$status_view = new PHUIStatusListView();
@@ -137,10 +135,6 @@ private function buildPaymentMethodsSection(PhortuneAccount $account) {
137135
->withAccountPHIDs(array($account->getPHID()))
138136
->execute();
139137

140-
if ($methods) {
141-
$this->loadHandles(mpull($methods, 'getAuthorPHID'));
142-
}
143-
144138
foreach ($methods as $method) {
145139
$id = $method->getID();
146140

src/applications/phortune/controller/PhortuneMerchantViewController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,9 @@ private function buildPropertyListView(
135135

136136
$view->addProperty(pht('Status'), $status_view);
137137

138-
$this->loadHandles($merchant->getMemberPHIDs());
139-
140138
$view->addProperty(
141139
pht('Members'),
142-
$this->renderHandlesForPHIDs($merchant->getMemberPHIDs()));
140+
$viewer->renderHandleList($merchant->getMemberPHIDs()));
143141

144142
$view->invokeWillRenderEvent();
145143

0 commit comments

Comments
 (0)