Skip to content

Commit 4d362dd

Browse files
author
lkassianik
committed
Ref T6049, Add Phurl URL create capability
Summary: Ref T6049, Add Phurl URL create capability Test Plan: - Change {nav Home > Applications > Phurl > Configure} to allow no one to create Phurl URLs - Attempt {nav Phurl > Shorten URL}. Should not be able to create a Phurl. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Maniphest Tasks: T6049 Differential Revision: https://secure.phabricator.com/D14510
1 parent d5cb3cd commit 4d362dd

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,6 +2670,7 @@
26702670
'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php',
26712671
'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php',
26722672
'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php',
2673+
'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php',
26732674
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
26742675
'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php',
26752676
'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php',
@@ -6848,6 +6849,7 @@
68486849
),
68496850
'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController',
68506851
'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController',
6852+
'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability',
68516853
'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController',
68526854
'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor',
68536855
'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',

src/applications/phurl/application/PhabricatorPhurlApplication.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,12 @@ public function getShortRoutes() {
6060
);
6161
}
6262

63+
protected function getCustomCapabilities() {
64+
return array(
65+
PhabricatorPhurlURLCreateCapability::CAPABILITY => array(
66+
'default' => PhabricatorPolicies::POLICY_USER,
67+
),
68+
);
69+
}
70+
6371
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
final class PhabricatorPhurlURLCreateCapability
4+
extends PhabricatorPolicyCapability {
5+
6+
const CAPABILITY = 'phurl.url.create';
7+
8+
public function getCapabilityName() {
9+
return pht('Can Create Phurl URLs');
10+
}
11+
12+
public function describeCapabilityRejection() {
13+
return pht('You do not have permission to create a Phurl URL.');
14+
}
15+
16+
}

src/applications/phurl/controller/PhabricatorPhurlController.php

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

55
protected function buildApplicationCrumbs() {
6+
$can_create = $this->hasApplicationCapability(
7+
PhabricatorPhurlURLCreateCapability::CAPABILITY);
8+
69
$crumbs = parent::buildApplicationCrumbs();
710
$crumbs->addAction(
811
id(new PHUIListItemView())
912
->setName(pht('Shorten URL'))
1013
->setHref($this->getApplicationURI().'url/create/')
11-
->setIcon('fa-plus-square'));
14+
->setIcon('fa-plus-square')
15+
->setDisabled(!$can_create)
16+
->setWorkflow(!$can_create));
1217

1318
return $crumbs;
1419
}

src/applications/phurl/controller/PhabricatorPhurlURLEditController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public function handleRequest(AphrontRequest $request) {
1717
$uri_query = $request->getStr('query');
1818

1919
if ($is_create) {
20+
$this->requireApplicationCapability(
21+
PhabricatorPhurlURLCreateCapability::CAPABILITY);
22+
2023
$url = PhabricatorPhurlURL::initializeNewPhurlURL(
2124
$viewer);
2225
$submit_label = pht('Create');

0 commit comments

Comments
 (0)