Skip to content

Commit 7f0d0e4

Browse files
author
epriestley
committed
Make more Diffusion controllers/views capability-sensitive
Summary: Ref T603. I got most of this earlier, but finish it up. - Make a couple of controllers public; pretty much everything in Diffusion has implicit policy checks as a result of building a `DiffusionRequest`. - Add an "Edit" capability to commits. - Swap out the comment thing for commits. - Disable actions if the user can't take them. Test Plan: Viewed a bunch of interfaces while logged out, got appropriate results or roadblocks. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D7152
1 parent 5799e8e commit 7f0d0e4

File tree

7 files changed

+52
-6
lines changed

7 files changed

+52
-6
lines changed

src/applications/diffusion/controller/DiffusionCommitBranchesController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
final class DiffusionCommitBranchesController extends DiffusionController {
44

5+
public function shouldAllowPublic() {
6+
return true;
7+
}
8+
59
public function willProcessRequest(array $data) {
610
$data['user'] = $this->getRequest()->getUser();
711
$this->diffusionRequest = DiffusionRequest::newFromDictionary($data);

src/applications/diffusion/controller/DiffusionCommitController.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ final class DiffusionCommitController extends DiffusionController {
77
private $auditAuthorityPHIDs;
88
private $highlightedAudits;
99

10+
public function shouldAllowPublic() {
11+
return true;
12+
}
13+
1014
public function willProcessRequest(array $data) {
1115
// This controller doesn't use blob/path stuff, just pass the dictionary
1216
// in directly instead of using the AphrontRequest parsing mechanism.
@@ -609,7 +613,15 @@ private function renderAddCommentPanel(
609613
PhabricatorRepositoryCommit $commit,
610614
array $audit_requests) {
611615
assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest');
612-
$user = $this->getRequest()->getUser();
616+
617+
$request = $this->getRequest();
618+
$user = $request->getUser();
619+
620+
if (!$user->isLoggedIn()) {
621+
return id(new PhabricatorApplicationTransactionCommentView())
622+
->setUser($user)
623+
->setRequestURI($request->getRequestURI());
624+
}
613625

614626
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
615627

@@ -881,14 +893,20 @@ private function renderHeadsupActionList(
881893
->setObject($commit)
882894
->setObjectURI($request->getRequestURI());
883895

884-
// TODO -- integrate permissions into whether or not this action is shown
885-
$uri = '/diffusion/'.$repository->getCallSign().'/commit/'.
896+
$can_edit = PhabricatorPolicyFilter::hasCapability(
897+
$user,
898+
$commit,
899+
PhabricatorPolicyCapability::CAN_EDIT);
900+
901+
$uri = '/diffusion/'.$repository->getCallsign().'/commit/'.
886902
$commit->getCommitIdentifier().'/edit/';
887903

888904
$action = id(new PhabricatorActionView())
889905
->setName(pht('Edit Commit'))
890906
->setHref($uri)
891-
->setIcon('edit');
907+
->setIcon('edit')
908+
->setDisabled(!$can_edit)
909+
->setWorkflow(!$can_edit);
892910
$actions->addAction($action);
893911

894912
require_celerity_resource('phabricator-object-selector-css');
@@ -900,7 +918,8 @@ private function renderHeadsupActionList(
900918
->setName(pht('Edit Maniphest Tasks'))
901919
->setIcon('attach')
902920
->setHref('/search/attach/'.$commit->getPHID().'/TASK/edge/')
903-
->setWorkflow(true);
921+
->setWorkflow(true)
922+
->setDisabled(!$can_edit);
904923
$actions->addAction($action);
905924
}
906925

src/applications/diffusion/controller/DiffusionCommitTagsController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
final class DiffusionCommitTagsController extends DiffusionController {
44

5+
public function shouldAllowPublic() {
6+
return true;
7+
}
8+
59
public function willProcessRequest(array $data) {
610
$data['user'] = $this->getRequest()->getUser();
711
$this->diffusionRequest = DiffusionRequest::newFromDictionary($data);

src/applications/diffusion/controller/DiffusionExternalController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ public function willProcessRequest(array $data) {
66
// Don't build a DiffusionRequest.
77
}
88

9+
public function shouldAllowPublic() {
10+
return true;
11+
}
12+
913
public function processRequest() {
1014
$request = $this->getRequest();
1115

src/applications/diffusion/controller/DiffusionLastModifiedController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
final class DiffusionLastModifiedController extends DiffusionController {
44

5+
public function shouldAllowPublic() {
6+
return true;
7+
}
8+
59
public function processRequest() {
610
$drequest = $this->getDiffusionRequest();
711
$request = $this->getRequest();

src/applications/diffusion/request/DiffusionRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,13 @@ public function loadCommit() {
271271
if (empty($this->repositoryCommit)) {
272272
$repository = $this->getRepository();
273273

274+
// TODO: (T603) This should be a real query, but we need to sort out
275+
// the viewer.
274276
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
275277
'repositoryID = %d AND commitIdentifier = %s',
276278
$repository->getID(),
277279
$this->getCommit());
280+
$commit->attachRepository($repository);
278281
$this->repositoryCommit = $commit;
279282
}
280283
return $this->repositoryCommit;

src/applications/repository/storage/PhabricatorRepositoryCommit.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,19 @@ public function updateAuditStatus(array $requests) {
156156
public function getCapabilities() {
157157
return array(
158158
PhabricatorPolicyCapability::CAN_VIEW,
159+
PhabricatorPolicyCapability::CAN_EDIT,
159160
);
160161
}
161162

162163
public function getPolicy($capability) {
163-
return $this->getRepository()->getPolicy($capability);
164+
switch ($capability) {
165+
case PhabricatorPolicyCapability::CAN_VIEW:
166+
return $this->getRepository()->getPolicy($capability);
167+
case PhabricatorPolicyCapability::CAN_EDIT:
168+
// TODO: (T603) Who should be able to edit a commit? For now, retain
169+
// the existing policy.
170+
return PhabricatorPolicies::POLICY_USER;
171+
}
164172
}
165173

166174
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {

0 commit comments

Comments
 (0)