Page MenuHomePhabricator

D14467.diff
No OneTemporary

D14467.diff

diff --git a/resources/sql/autopatches/20151214.policyname.php b/resources/sql/autopatches/20151214.policyname.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20151214.policyname.php
@@ -0,0 +1,28 @@
+<?php
+
+$map = array(
+ 'PhabricatorProjectsPolicyRule' =>
+ 'PhabricatorProjectProjectMembersPolicyRule',
+);
+
+echo pht('Migrating policies...')."\n";
+$table = new PhabricatorPolicy();
+$conn_w = $table->establishConnection('w');
+
+foreach (new LiskMigrationIterator($table) as $policy) {
+ $old_rules = $policy->getRules();
+ $new_rules = array();
+
+ foreach ($old_rules as $rule) {
+ $existing_rule = $rule['rule'];
+ $rule['rule'] = idx($map, $existing_rule, $existing_rule);
+ $new_rules[] = $rule;
+ }
+
+ queryfx(
+ $conn_w,
+ 'UPDATE %T SET rules = %s WHERE id = %d',
+ $table->getTableName(),
+ json_encode($new_rules),
+ $policy->getID());
+}
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
@@ -2800,6 +2800,7 @@
'PhabricatorProjectMemberOfProjectEdgeType' => 'applications/project/edge/PhabricatorProjectMemberOfProjectEdgeType.php',
'PhabricatorProjectMembersDatasource' => 'applications/project/typeahead/PhabricatorProjectMembersDatasource.php',
'PhabricatorProjectMembersEditController' => 'applications/project/controller/PhabricatorProjectMembersEditController.php',
+ 'PhabricatorProjectMembersPolicyRule' => 'applications/project/policyrule/PhabricatorProjectMembersPolicyRule.php',
'PhabricatorProjectMembersRemoveController' => 'applications/project/controller/PhabricatorProjectMembersRemoveController.php',
'PhabricatorProjectMoveController' => 'applications/project/controller/PhabricatorProjectMoveController.php',
'PhabricatorProjectNoProjectsDatasource' => 'applications/project/typeahead/PhabricatorProjectNoProjectsDatasource.php',
@@ -2810,6 +2811,7 @@
'PhabricatorProjectProfileController' => 'applications/project/controller/PhabricatorProjectProfileController.php',
'PhabricatorProjectProjectHasMemberEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasMemberEdgeType.php',
'PhabricatorProjectProjectHasObjectEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasObjectEdgeType.php',
+ 'PhabricatorProjectProjectMembersPolicyRule' => 'applications/project/policyrule/PhabricatorProjectProjectMembersPolicyRule.php',
'PhabricatorProjectProjectPHIDType' => 'applications/project/phid/PhabricatorProjectProjectPHIDType.php',
'PhabricatorProjectQuery' => 'applications/project/query/PhabricatorProjectQuery.php',
'PhabricatorProjectRemoveHeraldAction' => 'applications/project/herald/PhabricatorProjectRemoveHeraldAction.php',
@@ -2831,7 +2833,6 @@
'PhabricatorProjectWatchController' => 'applications/project/controller/PhabricatorProjectWatchController.php',
'PhabricatorProjectsEditEngineExtension' => 'applications/project/editor/PhabricatorProjectsEditEngineExtension.php',
'PhabricatorProjectsEditField' => 'applications/transactions/editfield/PhabricatorProjectsEditField.php',
- 'PhabricatorProjectsPolicyRule' => 'applications/project/policyrule/PhabricatorProjectsPolicyRule.php',
'PhabricatorProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorProtocolAdapter.php',
'PhabricatorPygmentSetupCheck' => 'applications/config/check/PhabricatorPygmentSetupCheck.php',
'PhabricatorQuery' => 'infrastructure/query/PhabricatorQuery.php',
@@ -7053,6 +7054,7 @@
'PhabricatorProjectMemberOfProjectEdgeType' => 'PhabricatorEdgeType',
'PhabricatorProjectMembersDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorProjectMembersEditController' => 'PhabricatorProjectController',
+ 'PhabricatorProjectMembersPolicyRule' => 'PhabricatorPolicyRule',
'PhabricatorProjectMembersRemoveController' => 'PhabricatorProjectController',
'PhabricatorProjectMoveController' => 'PhabricatorProjectController',
'PhabricatorProjectNoProjectsDatasource' => 'PhabricatorTypeaheadDatasource',
@@ -7063,6 +7065,7 @@
'PhabricatorProjectProfileController' => 'PhabricatorProjectController',
'PhabricatorProjectProjectHasMemberEdgeType' => 'PhabricatorEdgeType',
'PhabricatorProjectProjectHasObjectEdgeType' => 'PhabricatorEdgeType',
+ 'PhabricatorProjectProjectMembersPolicyRule' => 'PhabricatorPolicyRule',
'PhabricatorProjectProjectPHIDType' => 'PhabricatorPHIDType',
'PhabricatorProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorProjectRemoveHeraldAction' => 'PhabricatorProjectHeraldAction',
@@ -7087,7 +7090,6 @@
'PhabricatorProjectWatchController' => 'PhabricatorProjectController',
'PhabricatorProjectsEditEngineExtension' => 'PhabricatorEditEngineExtension',
'PhabricatorProjectsEditField' => 'PhabricatorTokenizerEditField',
- 'PhabricatorProjectsPolicyRule' => 'PhabricatorPolicyRule',
'PhabricatorProtocolAdapter' => 'Phobject',
'PhabricatorPygmentSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorQuery' => 'Phobject',
diff --git a/src/applications/policy/rule/PhabricatorPolicyRule.php b/src/applications/policy/rule/PhabricatorPolicyRule.php
--- a/src/applications/policy/rule/PhabricatorPolicyRule.php
+++ b/src/applications/policy/rule/PhabricatorPolicyRule.php
@@ -11,10 +11,6 @@
const CONTROL_TYPE_NONE = 'none';
abstract public function getRuleDescription();
- abstract public function applyRule(
- PhabricatorUser $viewer,
- $value,
- PhabricatorPolicyInterface $object);
public function willApplyRules(
PhabricatorUser $viewer,
@@ -23,6 +19,11 @@
return;
}
+ abstract public function applyRule(
+ PhabricatorUser $viewer,
+ $value,
+ PhabricatorPolicyInterface $object);
+
public function getValueControlType() {
return self::CONTROL_TYPE_TEXT;
}
@@ -35,7 +36,7 @@
* Return `true` if this rule can be applied to the given object.
*
* Some policy rules may only operation on certain kinds of objects. For
- * example, a "task author" rule
+ * example, a "task author" rule can only operate on tasks.
*/
public function canApplyToObject(PhabricatorPolicyInterface $object) {
return true;
@@ -43,6 +44,7 @@
protected function getDatasourceTemplate(
PhabricatorTypeaheadDatasource $datasource) {
+
return array(
'markup' => new AphrontTokenizerTemplateView(),
'uri' => $datasource->getDatasourceURI(),
@@ -65,6 +67,7 @@
public function getRequiredHandlePHIDsForSummary($value) {
$phids = array();
+
switch ($this->getValueControlType()) {
case self::CONTROL_TYPE_TOKENIZER:
$phids = $value;
@@ -86,7 +89,7 @@
}
/**
- * Return true if the given value creates a rule with a meaningful effect.
+ * Return `true` if the given value creates a rule with a meaningful effect.
* An example of a rule with no meaningful effect is a "users" rule with no
* users specified.
*
@@ -131,7 +134,7 @@
$cache->setKey(self::getObjectPolicyCacheKey($object, $rule), $hint);
}
- protected function getTransactionHint(
+ final protected function getTransactionHint(
PhabricatorPolicyInterface $object) {
$cache = PhabricatorCaches::getRequestCache();
@@ -164,7 +167,7 @@
return null;
}
- public function getObjectPolicyFullKey() {
+ final public function getObjectPolicyFullKey() {
$key = $this->getObjectPolicyKey();
if (!$key) {
diff --git a/src/applications/project/controller/PhabricatorProjectProfileController.php b/src/applications/project/controller/PhabricatorProjectProfileController.php
--- a/src/applications/project/controller/PhabricatorProjectProfileController.php
+++ b/src/applications/project/controller/PhabricatorProjectProfileController.php
@@ -92,7 +92,8 @@
->setName(pht('Edit Details'))
->setIcon('fa-pencil')
->setHref($this->getApplicationURI("details/{$id}/"))
- ->setDisabled(!$can_edit));
+ ->setDisabled(!$can_edit)
+ ->setWorkflow(!$can_edit));
$view->addAction(
id(new PhabricatorActionView())
diff --git a/src/applications/project/policyrule/PhabricatorProjectMembersPolicyRule.php b/src/applications/project/policyrule/PhabricatorProjectMembersPolicyRule.php
new file mode 100644
--- /dev/null
+++ b/src/applications/project/policyrule/PhabricatorProjectMembersPolicyRule.php
@@ -0,0 +1,50 @@
+<?php
+
+final class PhabricatorProjectMembersPolicyRule extends PhabricatorPolicyRule {
+
+ public function getRuleDescription() {
+ return pht('members of project');
+ }
+
+ public function applyRule(
+ PhabricatorUser $viewer,
+ $value,
+ PhabricatorPolicyInterface $object) {
+
+ $edge_query = id(new PhabricatorEdgeQuery())
+ ->withSourcePHIDs(array($viewer->getPHID()))
+ ->withDestinationPHIDs(array($object->getPHID()))
+ ->withEdgeTypes(
+ array(
+ PhabricatorProjectMemberOfProjectEdgeType::EDGECONST,
+ ));
+ $edge_query->execute();
+
+ return (bool)$edge_query->getDestinationPHIDs();
+ }
+
+ public function getValueControlType() {
+ return self::CONTROL_TYPE_NONE;
+ }
+
+ public function canApplyToObject(PhabricatorPolicyInterface $object) {
+ return $object instanceof PhabricatorProject;
+ }
+
+ public function getObjectPolicyKey() {
+ return 'project.members';
+ }
+
+ public function getObjectPolicyName() {
+ return pht('Members');
+ }
+
+ public function getObjectPolicyIcon() {
+ return 'fa-users';
+ }
+
+ public function getPolicyExplanation() {
+ return pht('Members can take this action.');
+ }
+
+}
diff --git a/src/applications/project/policyrule/PhabricatorProjectsPolicyRule.php b/src/applications/project/policyrule/PhabricatorProjectProjectMembersPolicyRule.php
rename from src/applications/project/policyrule/PhabricatorProjectsPolicyRule.php
rename to src/applications/project/policyrule/PhabricatorProjectProjectMembersPolicyRule.php
--- a/src/applications/project/policyrule/PhabricatorProjectsPolicyRule.php
+++ b/src/applications/project/policyrule/PhabricatorProjectProjectMembersPolicyRule.php
@@ -1,6 +1,6 @@
<?php
-final class PhabricatorProjectsPolicyRule
+final class PhabricatorProjectProjectMembersPolicyRule
extends PhabricatorPolicyRule {
private $memberships = array();
diff --git a/src/applications/subscriptions/policyrule/PhabricatorSubscriptionsSubscribersPolicyRule.php b/src/applications/subscriptions/policyrule/PhabricatorSubscriptionsSubscribersPolicyRule.php
--- a/src/applications/subscriptions/policyrule/PhabricatorSubscriptionsSubscribersPolicyRule.php
+++ b/src/applications/subscriptions/policyrule/PhabricatorSubscriptionsSubscribersPolicyRule.php
@@ -6,26 +6,10 @@
private $subscribed = array();
private $sourcePHIDs = array();
- public function getObjectPolicyKey() {
- return 'subscriptions.subscribers';
- }
-
- public function getObjectPolicyName() {
- return pht('Subscribers');
- }
-
- public function getPolicyExplanation() {
- return pht('Subscribers can take this action.');
- }
-
public function getRuleDescription() {
return pht('subscribers');
}
- public function canApplyToObject(PhabricatorPolicyInterface $object) {
- return ($object instanceof PhabricatorSubscribableInterface);
- }
-
public function willApplyRules(
PhabricatorUser $viewer,
array $values,
@@ -118,4 +102,20 @@
return self::CONTROL_TYPE_NONE;
}
+ public function canApplyToObject(PhabricatorPolicyInterface $object) {
+ return $object instanceof PhabricatorSubscribableInterface;
+ }
+
+ public function getObjectPolicyKey() {
+ return 'subscriptions.subscribers';
+ }
+
+ public function getObjectPolicyName() {
+ return pht('Subscribers');
+ }
+
+ public function getPolicyExplanation() {
+ return pht('Subscribers can take this action.');
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Thu, Oct 31, 11:50 PM (5 d, 3 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6754609
Default Alt Text
D14467.diff (11 KB)

Event Timeline