Page MenuHomePhabricator

D9778.id23473.diff
No OneTemporary

D9778.id23473.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -854,6 +854,7 @@
'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 @@
'JavelinUIExample' => 'PhabricatorUIExample',
'JavelinViewExample' => 'PhabricatorUIExample',
'JavelinViewExampleServerView' => 'AphrontView',
+ 'LegalpadCapabilityCreateDocuments' => 'PhabricatorPolicyCapability',
'LegalpadCapabilityDefaultEdit' => 'PhabricatorPolicyCapability',
'LegalpadCapabilityDefaultView' => 'PhabricatorPolicyCapability',
'LegalpadController' => 'PhabricatorController',
diff --git a/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php b/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php
--- a/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php
+++ b/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php
@@ -69,6 +69,8 @@
protected function getCustomCapabilities() {
return array(
+ LegalpadCapabilityCreateDocuments::CAPABILITY => array(
+ ),
LegalpadCapabilityDefaultView::CAPABILITY => array(
),
LegalpadCapabilityDefaultEdit::CAPABILITY => array(
diff --git a/src/applications/legalpad/capability/LegalpadCapabilityCreateDocuments.php b/src/applications/legalpad/capability/LegalpadCapabilityCreateDocuments.php
new file mode 100644
--- /dev/null
+++ b/src/applications/legalpad/capability/LegalpadCapabilityCreateDocuments.php
@@ -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.');
+ }
+
+}
diff --git a/src/applications/legalpad/controller/LegalpadDocumentEditController.php b/src/applications/legalpad/controller/LegalpadDocumentEditController.php
--- a/src/applications/legalpad/controller/LegalpadDocumentEditController.php
+++ b/src/applications/legalpad/controller/LegalpadDocumentEditController.php
@@ -18,6 +18,9 @@
if (!$this->id) {
$is_create = true;
+ $this->requireApplicationCapability(
+ LegalpadCapabilityCreateDocuments::CAPABILITY);
+
$document = LegalpadDocument::initializeNewDocument($user);
$body = id(new LegalpadDocumentBody())
->setCreatorPHID($user->getPHID());
diff --git a/src/applications/legalpad/controller/LegalpadDocumentListController.php b/src/applications/legalpad/controller/LegalpadDocumentListController.php
--- a/src/applications/legalpad/controller/LegalpadDocumentListController.php
+++ b/src/applications/legalpad/controller/LegalpadDocumentListController.php
@@ -25,11 +25,17 @@
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;
}

File Metadata

Mime Type
text/plain
Expires
Thu, Oct 17, 6:02 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6720896
Default Alt Text
D9778.id23473.diff (4 KB)

Event Timeline