mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 13:22:42 +01:00
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
This commit is contained in:
parent
d5cb3cd277
commit
4d362ddcee
5 changed files with 35 additions and 1 deletions
|
@ -2670,6 +2670,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php',
|
'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php',
|
||||||
'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php',
|
'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php',
|
||||||
'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php',
|
'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php',
|
||||||
|
'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php',
|
||||||
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
|
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
|
||||||
'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php',
|
'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php',
|
||||||
'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php',
|
'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php',
|
||||||
|
@ -6848,6 +6849,7 @@ phutil_register_library_map(array(
|
||||||
),
|
),
|
||||||
'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController',
|
'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController',
|
||||||
'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController',
|
'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController',
|
||||||
|
'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability',
|
||||||
'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController',
|
'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController',
|
||||||
'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',
|
'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',
|
||||||
|
|
|
@ -60,4 +60,12 @@ final class PhabricatorPhurlApplication extends PhabricatorApplication {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getCustomCapabilities() {
|
||||||
|
return array(
|
||||||
|
PhabricatorPhurlURLCreateCapability::CAPABILITY => array(
|
||||||
|
'default' => PhabricatorPolicies::POLICY_USER,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorPhurlURLCreateCapability
|
||||||
|
extends PhabricatorPolicyCapability {
|
||||||
|
|
||||||
|
const CAPABILITY = 'phurl.url.create';
|
||||||
|
|
||||||
|
public function getCapabilityName() {
|
||||||
|
return pht('Can Create Phurl URLs');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function describeCapabilityRejection() {
|
||||||
|
return pht('You do not have permission to create a Phurl URL.');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,12 +3,17 @@
|
||||||
abstract class PhabricatorPhurlController extends PhabricatorController {
|
abstract class PhabricatorPhurlController extends PhabricatorController {
|
||||||
|
|
||||||
protected function buildApplicationCrumbs() {
|
protected function buildApplicationCrumbs() {
|
||||||
|
$can_create = $this->hasApplicationCapability(
|
||||||
|
PhabricatorPhurlURLCreateCapability::CAPABILITY);
|
||||||
|
|
||||||
$crumbs = parent::buildApplicationCrumbs();
|
$crumbs = parent::buildApplicationCrumbs();
|
||||||
$crumbs->addAction(
|
$crumbs->addAction(
|
||||||
id(new PHUIListItemView())
|
id(new PHUIListItemView())
|
||||||
->setName(pht('Shorten URL'))
|
->setName(pht('Shorten URL'))
|
||||||
->setHref($this->getApplicationURI().'url/create/')
|
->setHref($this->getApplicationURI().'url/create/')
|
||||||
->setIcon('fa-plus-square'));
|
->setIcon('fa-plus-square')
|
||||||
|
->setDisabled(!$can_create)
|
||||||
|
->setWorkflow(!$can_create));
|
||||||
|
|
||||||
return $crumbs;
|
return $crumbs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ final class PhabricatorPhurlURLEditController
|
||||||
$uri_query = $request->getStr('query');
|
$uri_query = $request->getStr('query');
|
||||||
|
|
||||||
if ($is_create) {
|
if ($is_create) {
|
||||||
|
$this->requireApplicationCapability(
|
||||||
|
PhabricatorPhurlURLCreateCapability::CAPABILITY);
|
||||||
|
|
||||||
$url = PhabricatorPhurlURL::initializeNewPhurlURL(
|
$url = PhabricatorPhurlURL::initializeNewPhurlURL(
|
||||||
$viewer);
|
$viewer);
|
||||||
$submit_label = pht('Create');
|
$submit_label = pht('Create');
|
||||||
|
|
Loading…
Reference in a new issue