mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-20 13:52:40 +01:00
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:
parent
5d1489a3ce
commit
088e98a30e
6 changed files with 69 additions and 11 deletions
|
@ -828,6 +828,8 @@ phutil_register_library_map(array(
|
|||
'JavelinViewExample' => 'applications/uiexample/examples/JavelinViewExample.php',
|
||||
'JavelinViewExampleServerView' => 'applications/uiexample/examples/JavelinViewExampleServerView.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',
|
||||
'LegalpadController' => 'applications/legalpad/controller/LegalpadController.php',
|
||||
'LegalpadDAO' => 'applications/legalpad/storage/LegalpadDAO.php',
|
||||
|
@ -3382,6 +3384,8 @@ phutil_register_library_map(array(
|
|||
'JavelinViewExample' => 'PhabricatorUIExample',
|
||||
'JavelinViewExampleServerView' => 'AphrontView',
|
||||
'LeaseHostBuildStepImplementation' => 'BuildStepImplementation',
|
||||
'LegalpadCapabilityDefaultEdit' => 'PhabricatorPolicyCapability',
|
||||
'LegalpadCapabilityDefaultView' => 'PhabricatorPolicyCapability',
|
||||
'LegalpadController' => 'PhabricatorController',
|
||||
'LegalpadDAO' => 'PhabricatorLiskDAO',
|
||||
'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) {
|
||||
$is_create = true;
|
||||
|
||||
$document = id(new LegalpadDocument())
|
||||
->setVersions(0)
|
||||
->setCreatorPHID($user->getPHID())
|
||||
->setContributorCount(0)
|
||||
->setRecentContributorPHIDs(array())
|
||||
->attachSignatures(array())
|
||||
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
|
||||
->setEditPolicy(PhabricatorPolicies::POLICY_USER);
|
||||
$document = LegalpadDocument::initializeNewDocument($user);
|
||||
$body = id(new LegalpadDocumentBody())
|
||||
->setCreatorPHID($user->getPHID());
|
||||
$document->attachDocumentBody($body);
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group legalpad
|
||||
*/
|
||||
final class LegalpadDocument extends LegalpadDAO
|
||||
implements
|
||||
PhabricatorPolicyInterface,
|
||||
|
@ -23,6 +20,25 @@ final class LegalpadDocument extends LegalpadDAO
|
|||
private $contributors = 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() {
|
||||
return array(
|
||||
self::CONFIG_AUX_PHID => true,
|
||||
|
|
Loading…
Reference in a new issue