1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +01:00

Add a "Can Create Documents" permission for Legalpad

Summary: Ref T3116. Installs might reasonably want to restrict creation of these documents to actual lawyers or something.

Test Plan: Adjusted policy, tried to create document, set it back, created a document.

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T3116

Differential Revision: https://secure.phabricator.com/D9778
This commit is contained in:
epriestley 2014-06-29 12:43:13 -07:00
parent c1af499ed7
commit ea50ac32d3
6 changed files with 41 additions and 4 deletions

View file

@ -854,6 +854,7 @@ phutil_register_library_map(array(
'JavelinUIExample' => 'applications/uiexample/examples/JavelinUIExample.php',
'JavelinViewExample' => 'applications/uiexample/examples/JavelinViewExample.php',
'JavelinViewExampleServerView' => 'applications/uiexample/examples/JavelinViewExampleServerView.php',
'LegalpadCapabilityCreateDocuments' => 'applications/legalpad/capability/LegalpadCapabilityCreateDocuments.php',
'LegalpadCapabilityDefaultEdit' => 'applications/legalpad/capability/LegalpadCapabilityDefaultEdit.php',
'LegalpadCapabilityDefaultView' => 'applications/legalpad/capability/LegalpadCapabilityDefaultView.php',
'LegalpadConstants' => 'applications/legalpad/constants/LegalpadConstants.php',
@ -3603,6 +3604,7 @@ phutil_register_library_map(array(
'JavelinUIExample' => 'PhabricatorUIExample',
'JavelinViewExample' => 'PhabricatorUIExample',
'JavelinViewExampleServerView' => 'AphrontView',
'LegalpadCapabilityCreateDocuments' => 'PhabricatorPolicyCapability',
'LegalpadCapabilityDefaultEdit' => 'PhabricatorPolicyCapability',
'LegalpadCapabilityDefaultView' => 'PhabricatorPolicyCapability',
'LegalpadController' => 'PhabricatorController',

View file

@ -69,6 +69,8 @@ final class PhabricatorApplicationLegalpad extends PhabricatorApplication {
protected function getCustomCapabilities() {
return array(
LegalpadCapabilityCreateDocuments::CAPABILITY => array(
),
LegalpadCapabilityDefaultView::CAPABILITY => array(
),
LegalpadCapabilityDefaultEdit::CAPABILITY => array(

View file

@ -0,0 +1,20 @@
<?php
final class LegalpadCapabilityCreateDocuments
extends PhabricatorPolicyCapability {
const CAPABILITY = 'legalpad.create';
public function getCapabilityKey() {
return self::CAPABILITY;
}
public function getCapabilityName() {
return pht('Can Create Documents');
}
public function describeCapabilityRejection() {
return pht('You do not have permission to create new documents.');
}
}

View file

@ -18,6 +18,9 @@ final class LegalpadDocumentEditController extends LegalpadController {
if (!$this->id) {
$is_create = true;
$this->requireApplicationCapability(
LegalpadCapabilityCreateDocuments::CAPABILITY);
$document = LegalpadDocument::initializeNewDocument($user);
$body = id(new LegalpadDocumentBody())
->setCreatorPHID($user->getPHID());
@ -145,14 +148,15 @@ final class LegalpadDocumentEditController extends LegalpadController {
$submit = new AphrontFormSubmitControl();
if ($is_create) {
$submit->setValue(pht('Create Document'));
$submit->addCancelButton($this->getApplicationURI());
$title = pht('Create Document');
$short = pht('Create');
} else {
$submit->setValue(pht('Update Document'));
$submit->setValue(pht('Edit Document'));
$submit->addCancelButton(
$this->getApplicationURI('view/'.$document->getID()));
$title = pht('Update Document');
$short = pht('Update');
$title = pht('Edit Document');
$short = pht('Edit');
$crumbs->addTextCrumb(
$document->getMonogram(),

View file

@ -25,11 +25,17 @@ final class LegalpadDocumentListController extends LegalpadController {
public function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$can_create = $this->hasApplicationCapability(
LegalpadCapabilityCreateDocuments::CAPABILITY);
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('Create Document'))
->setHref($this->getApplicationURI('create/'))
->setIcon('fa-plus-square'));
->setIcon('fa-plus-square')
->setDisabled(!$can_create)
->setWorkflow(!$can_create));
return $crumbs;
}

View file

@ -71,6 +71,9 @@ final class LegalpadDocumentSignatureListController extends LegalpadController {
$crumbs->addTextCrumb(
$this->document->getMonogram(),
'/'.$this->document->getMonogram());
$crumbs->addTextCrumb(
pht('Manage'),
$this->getApplicationURI('view/'.$this->document->getID().'/'));
} else {
$crumbs->addTextCrumb(
pht('Signatures'),