1
0
Fork 0
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:
lkassianik 2015-11-18 12:24:09 -08:00
parent d5cb3cd277
commit 4d362ddcee
5 changed files with 35 additions and 1 deletions

View file

@ -2670,6 +2670,7 @@ phutil_register_library_map(array(
'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php',
'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php',
'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php',
'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php',
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php',
'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php',
@ -6848,6 +6849,7 @@ phutil_register_library_map(array(
),
'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController',
'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController',
'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability',
'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController',
'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',

View file

@ -60,4 +60,12 @@ final class PhabricatorPhurlApplication extends PhabricatorApplication {
);
}
protected function getCustomCapabilities() {
return array(
PhabricatorPhurlURLCreateCapability::CAPABILITY => array(
'default' => PhabricatorPolicies::POLICY_USER,
),
);
}
}

View file

@ -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.');
}
}

View file

@ -3,12 +3,17 @@
abstract class PhabricatorPhurlController extends PhabricatorController {
protected function buildApplicationCrumbs() {
$can_create = $this->hasApplicationCapability(
PhabricatorPhurlURLCreateCapability::CAPABILITY);
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('Shorten URL'))
->setHref($this->getApplicationURI().'url/create/')
->setIcon('fa-plus-square'));
->setIcon('fa-plus-square')
->setDisabled(!$can_create)
->setWorkflow(!$can_create));
return $crumbs;
}

View file

@ -17,6 +17,9 @@ final class PhabricatorPhurlURLEditController
$uri_query = $request->getStr('query');
if ($is_create) {
$this->requireApplicationCapability(
PhabricatorPhurlURLCreateCapability::CAPABILITY);
$url = PhabricatorPhurlURL::initializeNewPhurlURL(
$viewer);
$submit_label = pht('Create');