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

View file

@ -69,6 +69,8 @@ final class PhabricatorApplicationLegalpad extends PhabricatorApplication {
protected function getCustomCapabilities() { protected function getCustomCapabilities() {
return array( return array(
LegalpadCapabilityCreateDocuments::CAPABILITY => array(
),
LegalpadCapabilityDefaultView::CAPABILITY => array( LegalpadCapabilityDefaultView::CAPABILITY => array(
), ),
LegalpadCapabilityDefaultEdit::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) { if (!$this->id) {
$is_create = true; $is_create = true;
$this->requireApplicationCapability(
LegalpadCapabilityCreateDocuments::CAPABILITY);
$document = LegalpadDocument::initializeNewDocument($user); $document = LegalpadDocument::initializeNewDocument($user);
$body = id(new LegalpadDocumentBody()) $body = id(new LegalpadDocumentBody())
->setCreatorPHID($user->getPHID()); ->setCreatorPHID($user->getPHID());
@ -145,14 +148,15 @@ final class LegalpadDocumentEditController extends LegalpadController {
$submit = new AphrontFormSubmitControl(); $submit = new AphrontFormSubmitControl();
if ($is_create) { if ($is_create) {
$submit->setValue(pht('Create Document')); $submit->setValue(pht('Create Document'));
$submit->addCancelButton($this->getApplicationURI());
$title = pht('Create Document'); $title = pht('Create Document');
$short = pht('Create'); $short = pht('Create');
} else { } else {
$submit->setValue(pht('Update Document')); $submit->setValue(pht('Edit Document'));
$submit->addCancelButton( $submit->addCancelButton(
$this->getApplicationURI('view/'.$document->getID())); $this->getApplicationURI('view/'.$document->getID()));
$title = pht('Update Document'); $title = pht('Edit Document');
$short = pht('Update'); $short = pht('Edit');
$crumbs->addTextCrumb( $crumbs->addTextCrumb(
$document->getMonogram(), $document->getMonogram(),

View file

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

View file

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