Allow configuration of default document policies for Legalpad
Summary: Ref T3116. User request / generally modern feature. Test Plan: Set defaults to whacky projects and created a new document; it defaulted appropriately. Reviewers: btrahan Reviewed By: btrahan CC: aran, allan.laal Maniphest Tasks: T3116 Differential Revision: https://secure.phabricator.com/D8110
This commit is contained in:
@@ -828,6 +828,8 @@ phutil_register_library_map(array(
|
|||||||
'JavelinViewExample' => 'applications/uiexample/examples/JavelinViewExample.php',
|
'JavelinViewExample' => 'applications/uiexample/examples/JavelinViewExample.php',
|
||||||
'JavelinViewExampleServerView' => 'applications/uiexample/examples/JavelinViewExampleServerView.php',
|
'JavelinViewExampleServerView' => 'applications/uiexample/examples/JavelinViewExampleServerView.php',
|
||||||
'LeaseHostBuildStepImplementation' => 'applications/harbormaster/step/LeaseHostBuildStepImplementation.php',
|
'LeaseHostBuildStepImplementation' => 'applications/harbormaster/step/LeaseHostBuildStepImplementation.php',
|
||||||
|
'LegalpadCapabilityDefaultEdit' => 'applications/legalpad/capability/LegalpadCapabilityDefaultEdit.php',
|
||||||
|
'LegalpadCapabilityDefaultView' => 'applications/legalpad/capability/LegalpadCapabilityDefaultView.php',
|
||||||
'LegalpadConstants' => 'applications/legalpad/constants/LegalpadConstants.php',
|
'LegalpadConstants' => 'applications/legalpad/constants/LegalpadConstants.php',
|
||||||
'LegalpadController' => 'applications/legalpad/controller/LegalpadController.php',
|
'LegalpadController' => 'applications/legalpad/controller/LegalpadController.php',
|
||||||
'LegalpadDAO' => 'applications/legalpad/storage/LegalpadDAO.php',
|
'LegalpadDAO' => 'applications/legalpad/storage/LegalpadDAO.php',
|
||||||
@@ -3382,6 +3384,8 @@ phutil_register_library_map(array(
|
|||||||
'JavelinViewExample' => 'PhabricatorUIExample',
|
'JavelinViewExample' => 'PhabricatorUIExample',
|
||||||
'JavelinViewExampleServerView' => 'AphrontView',
|
'JavelinViewExampleServerView' => 'AphrontView',
|
||||||
'LeaseHostBuildStepImplementation' => 'BuildStepImplementation',
|
'LeaseHostBuildStepImplementation' => 'BuildStepImplementation',
|
||||||
|
'LegalpadCapabilityDefaultEdit' => 'PhabricatorPolicyCapability',
|
||||||
|
'LegalpadCapabilityDefaultView' => 'PhabricatorPolicyCapability',
|
||||||
'LegalpadController' => 'PhabricatorController',
|
'LegalpadController' => 'PhabricatorController',
|
||||||
'LegalpadDAO' => 'PhabricatorLiskDAO',
|
'LegalpadDAO' => 'PhabricatorLiskDAO',
|
||||||
'LegalpadDocument' =>
|
'LegalpadDocument' =>
|
||||||
|
|||||||
@@ -51,4 +51,13 @@ final class PhabricatorApplicationLegalpad extends PhabricatorApplication {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getCustomCapabilities() {
|
||||||
|
return array(
|
||||||
|
LegalpadCapabilityDefaultView::CAPABILITY => array(
|
||||||
|
),
|
||||||
|
LegalpadCapabilityDefaultEdit::CAPABILITY => array(
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
final class LegalpadCapabilityDefaultEdit
|
||||||
|
extends PhabricatorPolicyCapability {
|
||||||
|
|
||||||
|
const CAPABILITY = 'legalpad.default.edit';
|
||||||
|
|
||||||
|
public function getCapabilityKey() {
|
||||||
|
return self::CAPABILITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCapabilityName() {
|
||||||
|
return pht('Default Edit Policy');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
final class LegalpadCapabilityDefaultView
|
||||||
|
extends PhabricatorPolicyCapability {
|
||||||
|
|
||||||
|
const CAPABILITY = 'legalpad.default.view';
|
||||||
|
|
||||||
|
public function getCapabilityKey() {
|
||||||
|
return self::CAPABILITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCapabilityName() {
|
||||||
|
return pht('Default View Policy');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shouldAllowPublicPolicySetting() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,14 +18,7 @@ final class LegalpadDocumentEditController extends LegalpadController {
|
|||||||
if (!$this->id) {
|
if (!$this->id) {
|
||||||
$is_create = true;
|
$is_create = true;
|
||||||
|
|
||||||
$document = id(new LegalpadDocument())
|
$document = LegalpadDocument::initializeNewDocument($user);
|
||||||
->setVersions(0)
|
|
||||||
->setCreatorPHID($user->getPHID())
|
|
||||||
->setContributorCount(0)
|
|
||||||
->setRecentContributorPHIDs(array())
|
|
||||||
->attachSignatures(array())
|
|
||||||
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
|
|
||||||
->setEditPolicy(PhabricatorPolicies::POLICY_USER);
|
|
||||||
$body = id(new LegalpadDocumentBody())
|
$body = id(new LegalpadDocumentBody())
|
||||||
->setCreatorPHID($user->getPHID());
|
->setCreatorPHID($user->getPHID());
|
||||||
$document->attachDocumentBody($body);
|
$document->attachDocumentBody($body);
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legalpad
|
|
||||||
*/
|
|
||||||
final class LegalpadDocument extends LegalpadDAO
|
final class LegalpadDocument extends LegalpadDAO
|
||||||
implements
|
implements
|
||||||
PhabricatorPolicyInterface,
|
PhabricatorPolicyInterface,
|
||||||
@@ -23,6 +20,25 @@ final class LegalpadDocument extends LegalpadDAO
|
|||||||
private $contributors = self::ATTACHABLE;
|
private $contributors = self::ATTACHABLE;
|
||||||
private $signatures = self::ATTACHABLE;
|
private $signatures = self::ATTACHABLE;
|
||||||
|
|
||||||
|
public static function initializeNewDocument(PhabricatorUser $actor) {
|
||||||
|
$app = id(new PhabricatorApplicationQuery())
|
||||||
|
->setViewer($actor)
|
||||||
|
->withClasses(array('PhabricatorApplicationLegalpad'))
|
||||||
|
->executeOne();
|
||||||
|
|
||||||
|
$view_policy = $app->getPolicy(LegalpadCapabilityDefaultView::CAPABILITY);
|
||||||
|
$edit_policy = $app->getPolicy(LegalpadCapabilityDefaultEdit::CAPABILITY);
|
||||||
|
|
||||||
|
return id(new LegalpadDocument())
|
||||||
|
->setVersions(0)
|
||||||
|
->setCreatorPHID($actor->getPHID())
|
||||||
|
->setContributorCount(0)
|
||||||
|
->setRecentContributorPHIDs(array())
|
||||||
|
->attachSignatures(array())
|
||||||
|
->setViewPolicy($view_policy)
|
||||||
|
->setEditPolicy($edit_policy);
|
||||||
|
}
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
self::CONFIG_AUX_PHID => true,
|
self::CONFIG_AUX_PHID => true,
|
||||||
|
|||||||
Reference in New Issue
Block a user