Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14003255
D16319.id39289.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
D16319.id39289.diff
View Options
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
@@ -2974,12 +2974,15 @@
'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 @@
'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 @@
'PhabricatorPHPMailerConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPackagesApplication' => 'PhabricatorApplication',
'PhabricatorPackagesController' => 'PhabricatorController',
+ 'PhabricatorPackagesCreatePublisherCapability' => 'PhabricatorPolicyCapability',
'PhabricatorPackagesDAO' => 'PhabricatorLiskDAO',
'PhabricatorPackagesEditEngine' => 'PhabricatorEditEngine',
'PhabricatorPackagesEditor' => 'PhabricatorApplicationTransactionEditor',
@@ -7803,6 +7808,8 @@
),
'PhabricatorPackagesPackageController' => 'PhabricatorPackagesController',
'PhabricatorPackagesPackageDatasource' => 'PhabricatorTypeaheadDatasource',
+ 'PhabricatorPackagesPackageDefaultEditCapability' => 'PhabricatorPolicyCapability',
+ 'PhabricatorPackagesPackageDefaultViewCapability' => 'PhabricatorPolicyCapability',
'PhabricatorPackagesPackageEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'PhabricatorPackagesPackageEditController' => 'PhabricatorPackagesPackageController',
'PhabricatorPackagesPackageEditEngine' => 'PhabricatorPackagesEditEngine',
@@ -7830,6 +7837,7 @@
),
'PhabricatorPackagesPublisherController' => 'PhabricatorPackagesController',
'PhabricatorPackagesPublisherDatasource' => 'PhabricatorTypeaheadDatasource',
+ 'PhabricatorPackagesPublisherDefaultEditCapability' => 'PhabricatorPolicyCapability',
'PhabricatorPackagesPublisherEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'PhabricatorPackagesPublisherEditController' => 'PhabricatorPackagesPublisherController',
'PhabricatorPackagesPublisherEditEngine' => 'PhabricatorPackagesEditEngine',
diff --git a/src/applications/packages/application/PhabricatorPackagesApplication.php b/src/applications/packages/application/PhabricatorPackagesApplication.php
--- a/src/applications/packages/application/PhabricatorPackagesApplication.php
+++ b/src/applications/packages/application/PhabricatorPackagesApplication.php
@@ -26,6 +26,27 @@
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(
diff --git a/src/applications/packages/capability/PhabricatorPackagesCreatePublisherCapability.php b/src/applications/packages/capability/PhabricatorPackagesCreatePublisherCapability.php
new file mode 100644
--- /dev/null
+++ b/src/applications/packages/capability/PhabricatorPackagesCreatePublisherCapability.php
@@ -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.');
+ }
+
+}
diff --git a/src/applications/packages/capability/PhabricatorPackagesPackageDefaultEditCapability.php b/src/applications/packages/capability/PhabricatorPackagesPackageDefaultEditCapability.php
new file mode 100644
--- /dev/null
+++ b/src/applications/packages/capability/PhabricatorPackagesPackageDefaultEditCapability.php
@@ -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');
+ }
+
+}
diff --git a/src/applications/packages/capability/PhabricatorPackagesPackageDefaultViewCapability.php b/src/applications/packages/capability/PhabricatorPackagesPackageDefaultViewCapability.php
new file mode 100644
--- /dev/null
+++ b/src/applications/packages/capability/PhabricatorPackagesPackageDefaultViewCapability.php
@@ -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;
+ }
+
+}
diff --git a/src/applications/packages/capability/PhabricatorPackagesPublisherDefaultEditCapability.php b/src/applications/packages/capability/PhabricatorPackagesPublisherDefaultEditCapability.php
new file mode 100644
--- /dev/null
+++ b/src/applications/packages/capability/PhabricatorPackagesPublisherDefaultEditCapability.php
@@ -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');
+ }
+
+}
diff --git a/src/applications/packages/editor/PhabricatorPackagesPublisherEditEngine.php b/src/applications/packages/editor/PhabricatorPackagesPublisherEditEngine.php
--- a/src/applications/packages/editor/PhabricatorPackagesPublisherEditEngine.php
+++ b/src/applications/packages/editor/PhabricatorPackagesPublisherEditEngine.php
@@ -62,6 +62,11 @@
return $object->getURI();
}
+ protected function getCreateNewObjectPolicy() {
+ return $this->getApplication()->getPolicy(
+ PhabricatorPackagesCreatePublisherCapability::CAPABILITY);
+ }
+
protected function buildCustomEditFields($object) {
$fields = array();
diff --git a/src/applications/packages/storage/PhabricatorPackagesPackage.php b/src/applications/packages/storage/PhabricatorPackagesPackage.php
--- a/src/applications/packages/storage/PhabricatorPackagesPackage.php
+++ b/src/applications/packages/storage/PhabricatorPackagesPackage.php
@@ -19,7 +19,20 @@
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() {
diff --git a/src/applications/packages/storage/PhabricatorPackagesPublisher.php b/src/applications/packages/storage/PhabricatorPackagesPublisher.php
--- a/src/applications/packages/storage/PhabricatorPackagesPublisher.php
+++ b/src/applications/packages/storage/PhabricatorPackagesPublisher.php
@@ -15,7 +15,16 @@
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() {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Oct 27, 4:03 AM (3 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6751840
Default Alt Text
D16319.id39289.diff (11 KB)
Attached To
Mode
D16319: Add default create, view, edit capabilities to Packages
Attached
Detach File
Event Timeline
Log In to Comment