mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
Add default create, view, edit capabilities to Packages
Summary: Ref T8116. This adds a control for creating publishers (default: administrators) and default publisher/package edit controls. I've left the edit defaults at "no one" for now to force you to select a policy. This might be something to look at later. Test Plan: Created publishers, packages. Tried to create publishers with "can create" policy set restrictively. Reviewers: chad Reviewed By: chad Maniphest Tasks: T8116 Differential Revision: https://secure.phabricator.com/D16319
This commit is contained in:
parent
ee37eca2e4
commit
f5d2f8e07a
9 changed files with 114 additions and 2 deletions
|
@ -2974,12 +2974,15 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPHPMailerConfigOptions' => 'applications/config/option/PhabricatorPHPMailerConfigOptions.php',
|
||||
'PhabricatorPackagesApplication' => 'applications/packages/application/PhabricatorPackagesApplication.php',
|
||||
'PhabricatorPackagesController' => 'applications/packages/controller/PhabricatorPackagesController.php',
|
||||
'PhabricatorPackagesCreatePublisherCapability' => 'applications/packages/capability/PhabricatorPackagesCreatePublisherCapability.php',
|
||||
'PhabricatorPackagesDAO' => 'applications/packages/storage/PhabricatorPackagesDAO.php',
|
||||
'PhabricatorPackagesEditEngine' => 'applications/packages/editor/PhabricatorPackagesEditEngine.php',
|
||||
'PhabricatorPackagesEditor' => 'applications/packages/editor/PhabricatorPackagesEditor.php',
|
||||
'PhabricatorPackagesPackage' => 'applications/packages/storage/PhabricatorPackagesPackage.php',
|
||||
'PhabricatorPackagesPackageController' => 'applications/packages/controller/PhabricatorPackagesPackageController.php',
|
||||
'PhabricatorPackagesPackageDatasource' => 'applications/packages/typeahead/PhabricatorPackagesPackageDatasource.php',
|
||||
'PhabricatorPackagesPackageDefaultEditCapability' => 'applications/packages/capability/PhabricatorPackagesPackageDefaultEditCapability.php',
|
||||
'PhabricatorPackagesPackageDefaultViewCapability' => 'applications/packages/capability/PhabricatorPackagesPackageDefaultViewCapability.php',
|
||||
'PhabricatorPackagesPackageEditConduitAPIMethod' => 'applications/packages/conduit/PhabricatorPackagesPackageEditConduitAPIMethod.php',
|
||||
'PhabricatorPackagesPackageEditController' => 'applications/packages/controller/PhabricatorPackagesPackageEditController.php',
|
||||
'PhabricatorPackagesPackageEditEngine' => 'applications/packages/editor/PhabricatorPackagesPackageEditEngine.php',
|
||||
|
@ -2999,6 +3002,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPackagesPublisher' => 'applications/packages/storage/PhabricatorPackagesPublisher.php',
|
||||
'PhabricatorPackagesPublisherController' => 'applications/packages/controller/PhabricatorPackagesPublisherController.php',
|
||||
'PhabricatorPackagesPublisherDatasource' => 'applications/packages/typeahead/PhabricatorPackagesPublisherDatasource.php',
|
||||
'PhabricatorPackagesPublisherDefaultEditCapability' => 'applications/packages/capability/PhabricatorPackagesPublisherDefaultEditCapability.php',
|
||||
'PhabricatorPackagesPublisherEditConduitAPIMethod' => 'applications/packages/conduit/PhabricatorPackagesPublisherEditConduitAPIMethod.php',
|
||||
'PhabricatorPackagesPublisherEditController' => 'applications/packages/controller/PhabricatorPackagesPublisherEditController.php',
|
||||
'PhabricatorPackagesPublisherEditEngine' => 'applications/packages/editor/PhabricatorPackagesPublisherEditEngine.php',
|
||||
|
@ -7789,6 +7793,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPHPMailerConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorPackagesApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorPackagesController' => 'PhabricatorController',
|
||||
'PhabricatorPackagesCreatePublisherCapability' => 'PhabricatorPolicyCapability',
|
||||
'PhabricatorPackagesDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorPackagesEditEngine' => 'PhabricatorEditEngine',
|
||||
'PhabricatorPackagesEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
|
@ -7803,6 +7808,8 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'PhabricatorPackagesPackageController' => 'PhabricatorPackagesController',
|
||||
'PhabricatorPackagesPackageDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'PhabricatorPackagesPackageDefaultEditCapability' => 'PhabricatorPolicyCapability',
|
||||
'PhabricatorPackagesPackageDefaultViewCapability' => 'PhabricatorPolicyCapability',
|
||||
'PhabricatorPackagesPackageEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
|
||||
'PhabricatorPackagesPackageEditController' => 'PhabricatorPackagesPackageController',
|
||||
'PhabricatorPackagesPackageEditEngine' => 'PhabricatorPackagesEditEngine',
|
||||
|
@ -7830,6 +7837,7 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'PhabricatorPackagesPublisherController' => 'PhabricatorPackagesController',
|
||||
'PhabricatorPackagesPublisherDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'PhabricatorPackagesPublisherDefaultEditCapability' => 'PhabricatorPolicyCapability',
|
||||
'PhabricatorPackagesPublisherEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
|
||||
'PhabricatorPackagesPublisherEditController' => 'PhabricatorPackagesPublisherController',
|
||||
'PhabricatorPackagesPublisherEditEngine' => 'PhabricatorPackagesEditEngine',
|
||||
|
|
|
@ -26,6 +26,27 @@ final class PhabricatorPackagesApplication extends PhabricatorApplication {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected function getCustomCapabilities() {
|
||||
return array(
|
||||
PhabricatorPackagesCreatePublisherCapability::CAPABILITY => array(
|
||||
'default' => PhabricatorPolicies::POLICY_ADMIN,
|
||||
),
|
||||
PhabricatorPackagesPublisherDefaultEditCapability::CAPABILITY => array(
|
||||
'caption' => pht('Default edit policy for newly created publishers.'),
|
||||
'template' => PhabricatorPackagesPublisherPHIDType::TYPECONST,
|
||||
'default' => PhabricatorPolicies::POLICY_NOONE,
|
||||
),
|
||||
PhabricatorPackagesPackageDefaultViewCapability::CAPABILITY => array(
|
||||
'caption' => pht('Default edit policy for newly created packages.'),
|
||||
'template' => PhabricatorPackagesPackagePHIDType::TYPECONST,
|
||||
),
|
||||
PhabricatorPackagesPackageDefaultEditCapability::CAPABILITY => array(
|
||||
'caption' => pht('Default view policy for newly created packages.'),
|
||||
'template' => PhabricatorPackagesPackagePHIDType::TYPECONST,
|
||||
'default' => PhabricatorPolicies::POLICY_NOONE,
|
||||
),
|
||||
);
|
||||
}
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
'/package/' => array(
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPackagesCreatePublisherCapability
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'packages.publisher.create';
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Create Publishers');
|
||||
}
|
||||
|
||||
public function describeCapabilityRejection() {
|
||||
return pht('You do not have permission to create publishers.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPackagesPackageDefaultEditCapability
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'packages.package.default.edit';
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Package Edit Policy');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPackagesPackageDefaultViewCapability
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'packages.package.default.view';
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Package View Policy');
|
||||
}
|
||||
|
||||
public function shouldAllowPublicPolicySetting() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPackagesPublisherDefaultEditCapability
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'packages.publisher.default.edit';
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Publisher Edit Policy');
|
||||
}
|
||||
|
||||
}
|
|
@ -62,6 +62,11 @@ final class PhabricatorPackagesPublisherEditEngine
|
|||
return $object->getURI();
|
||||
}
|
||||
|
||||
protected function getCreateNewObjectPolicy() {
|
||||
return $this->getApplication()->getPolicy(
|
||||
PhabricatorPackagesCreatePublisherCapability::CAPABILITY);
|
||||
}
|
||||
|
||||
protected function buildCustomEditFields($object) {
|
||||
$fields = array();
|
||||
|
||||
|
|
|
@ -19,7 +19,20 @@ final class PhabricatorPackagesPackage
|
|||
private $publisher = self::ATTACHABLE;
|
||||
|
||||
public static function initializeNewPackage(PhabricatorUser $actor) {
|
||||
return id(new self());
|
||||
$packages_application = id(new PhabricatorApplicationQuery())
|
||||
->setViewer($actor)
|
||||
->withClasses(array('PhabricatorPackagesApplication'))
|
||||
->executeOne();
|
||||
|
||||
$view_policy = $packages_application->getPolicy(
|
||||
PhabricatorPackagesPackageDefaultViewCapability::CAPABILITY);
|
||||
|
||||
$edit_policy = $packages_application->getPolicy(
|
||||
PhabricatorPackagesPackageDefaultEditCapability::CAPABILITY);
|
||||
|
||||
return id(new self())
|
||||
->setViewPolicy($view_policy)
|
||||
->setEditPolicy($edit_policy);
|
||||
}
|
||||
|
||||
protected function getConfiguration() {
|
||||
|
|
|
@ -15,7 +15,16 @@ final class PhabricatorPackagesPublisher
|
|||
protected $editPolicy;
|
||||
|
||||
public static function initializeNewPublisher(PhabricatorUser $actor) {
|
||||
return id(new self());
|
||||
$packages_application = id(new PhabricatorApplicationQuery())
|
||||
->setViewer($actor)
|
||||
->withClasses(array('PhabricatorPackagesApplication'))
|
||||
->executeOne();
|
||||
|
||||
$edit_policy = $packages_application->getPolicy(
|
||||
PhabricatorPackagesPublisherDefaultEditCapability::CAPABILITY);
|
||||
|
||||
return id(new self())
|
||||
->setEditPolicy($edit_policy);
|
||||
}
|
||||
|
||||
protected function getConfiguration() {
|
||||
|
|
Loading…
Reference in a new issue