Page MenuHomePhabricator

D7282.diff

diff --git a/resources/sql/patches/20131010.pstorage.sql b/resources/sql/patches/20131010.pstorage.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/patches/20131010.pstorage.sql
@@ -0,0 +1,9 @@
+CREATE TABLE {$NAMESPACE}_policy.policy (
+ id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ phid VARCHAR(64) NOT NULL COLLATE utf8_bin,
+ rules LONGTEXT NOT NULL COLLATE utf8_bin,
+ defaultAction VARCHAR(32) NOT NULL COLLATE utf8_bin,
+ dateCreated INT UNSIGNED NOT NULL,
+ dateModified INT UNSIGNED NOT NULL,
+ UNIQUE KEY (phid)
+) ENGINE=InnoDB, COLLATE utf8_general_ci;
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
@@ -1472,7 +1472,7 @@
'PhabricatorPhrequentConfigOptions' => 'applications/phrequent/config/PhabricatorPhrequentConfigOptions.php',
'PhabricatorPhrictionConfigOptions' => 'applications/phriction/config/PhabricatorPhrictionConfigOptions.php',
'PhabricatorPolicies' => 'applications/policy/constants/PhabricatorPolicies.php',
- 'PhabricatorPolicy' => 'applications/policy/filter/PhabricatorPolicy.php',
+ 'PhabricatorPolicy' => 'applications/policy/storage/PhabricatorPolicy.php',
'PhabricatorPolicyAwareQuery' => 'infrastructure/query/policy/PhabricatorPolicyAwareQuery.php',
'PhabricatorPolicyAwareTestQuery' => 'applications/policy/__tests__/PhabricatorPolicyAwareTestQuery.php',
'PhabricatorPolicyCapability' => 'applications/policy/capability/PhabricatorPolicyCapability.php',
@@ -1482,6 +1482,7 @@
'PhabricatorPolicyConfigOptions' => 'applications/policy/config/PhabricatorPolicyConfigOptions.php',
'PhabricatorPolicyConstants' => 'applications/policy/constants/PhabricatorPolicyConstants.php',
'PhabricatorPolicyController' => 'applications/policy/controller/PhabricatorPolicyController.php',
+ 'PhabricatorPolicyDAO' => 'applications/policy/storage/PhabricatorPolicyDAO.php',
'PhabricatorPolicyDataTestCase' => 'applications/policy/__tests__/PhabricatorPolicyDataTestCase.php',
'PhabricatorPolicyEditController' => 'applications/policy/controller/PhabricatorPolicyEditController.php',
'PhabricatorPolicyException' => 'applications/policy/exception/PhabricatorPolicyException.php',
@@ -1491,6 +1492,7 @@
'PhabricatorPolicyManagementShowWorkflow' => 'applications/policy/management/PhabricatorPolicyManagementShowWorkflow.php',
'PhabricatorPolicyManagementUnlockWorkflow' => 'applications/policy/management/PhabricatorPolicyManagementUnlockWorkflow.php',
'PhabricatorPolicyManagementWorkflow' => 'applications/policy/management/PhabricatorPolicyManagementWorkflow.php',
+ 'PhabricatorPolicyPHIDTypePolicy' => 'applications/policy/phid/PhabricatorPolicyPHIDTypePolicy.php',
'PhabricatorPolicyQuery' => 'applications/policy/query/PhabricatorPolicyQuery.php',
'PhabricatorPolicyRule' => 'applications/policy/rule/PhabricatorPolicyRule.php',
'PhabricatorPolicyRuleAdministrators' => 'applications/policy/rule/PhabricatorPolicyRuleAdministrators.php',
@@ -3670,21 +3672,24 @@
'PhabricatorPhrequentConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPhrictionConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPolicies' => 'PhabricatorPolicyConstants',
+ 'PhabricatorPolicy' => 'PhabricatorPolicyDAO',
'PhabricatorPolicyAwareQuery' => 'PhabricatorOffsetPagedQuery',
'PhabricatorPolicyAwareTestQuery' => 'PhabricatorPolicyAwareQuery',
'PhabricatorPolicyCapability' => 'Phobject',
'PhabricatorPolicyCapabilityCanEdit' => 'PhabricatorPolicyCapability',
'PhabricatorPolicyCapabilityCanJoin' => 'PhabricatorPolicyCapability',
'PhabricatorPolicyCapabilityCanView' => 'PhabricatorPolicyCapability',
'PhabricatorPolicyConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPolicyController' => 'PhabricatorController',
+ 'PhabricatorPolicyDAO' => 'PhabricatorLiskDAO',
'PhabricatorPolicyDataTestCase' => 'PhabricatorTestCase',
'PhabricatorPolicyEditController' => 'PhabricatorPolicyController',
'PhabricatorPolicyException' => 'Exception',
'PhabricatorPolicyExplainController' => 'PhabricatorPolicyController',
'PhabricatorPolicyManagementShowWorkflow' => 'PhabricatorPolicyManagementWorkflow',
'PhabricatorPolicyManagementUnlockWorkflow' => 'PhabricatorPolicyManagementWorkflow',
'PhabricatorPolicyManagementWorkflow' => 'PhutilArgumentWorkflow',
+ 'PhabricatorPolicyPHIDTypePolicy' => 'PhabricatorPHIDType',
'PhabricatorPolicyQuery' => 'PhabricatorQuery',
'PhabricatorPolicyRuleAdministrators' => 'PhabricatorPolicyRule',
'PhabricatorPolicyRuleLunarPhase' => 'PhabricatorPolicyRule',
diff --git a/src/applications/policy/controller/PhabricatorPolicyEditController.php b/src/applications/policy/controller/PhabricatorPolicyEditController.php
--- a/src/applications/policy/controller/PhabricatorPolicyEditController.php
+++ b/src/applications/policy/controller/PhabricatorPolicyEditController.php
@@ -7,6 +7,8 @@
$request = $this->getRequest();
$viewer = $request->getUser();
+ $policy = new PhabricatorPolicy();
+
$root_id = celerity_generate_unique_node_id();
$action_options = array(
@@ -53,16 +55,21 @@
$rule_obj = $rules[$rule_class];
$value = $rule_obj->getValueForStorage(idx($rule, 'value'));
- $value = $rule_obj->getValueForDisplay($viewer, $value);
$rule_data[] = array(
'action' => $action,
'rule' => $rule_class,
'value' => $value,
);
}
- $default_value = $request->getStr('default');
+ $policy->setRules($rule_data);
+ $policy->setDefaultAction($request->getStr('default'));
+ $policy->save();
+
+ // TODO: Integrate with policy editors.
+ $id = $policy->getID();
+ throw new Exception("OK, saved policy {$id}!");
} else {
$rule_data = array(
$default_rule,
@@ -76,7 +83,6 @@
'name' => 'default',
));
-
$form = id(new PHUIFormLayoutView())
->appendChild(
javelin_tag(
diff --git a/src/applications/policy/phid/PhabricatorPolicyPHIDTypePolicy.php b/src/applications/policy/phid/PhabricatorPolicyPHIDTypePolicy.php
new file mode 100644
--- /dev/null
+++ b/src/applications/policy/phid/PhabricatorPolicyPHIDTypePolicy.php
@@ -0,0 +1,48 @@
+<?php
+
+final class PhabricatorPolicyPHIDTypePolicy
+ extends PhabricatorPHIDType {
+
+ const TYPECONST = 'PLCY';
+
+ public function getTypeConstant() {
+ return self::TYPECONST;
+ }
+
+ public function getTypeName() {
+ return pht('Policy');
+ }
+
+ public function newObject() {
+ return new PhabricatorPolicy();
+ }
+
+ public function loadObjects(
+ PhabricatorObjectQuery $query,
+ array $phids) {
+
+ return id(new PhabricatorPolicyQuery())
+ ->setViewer($query->getViewer())
+ ->setParentQuery($query)
+ ->withPHIDs($phids)
+ ->execute();
+ }
+
+ public function loadHandles(
+ PhabricatorHandleQuery $query,
+ array $handles,
+ array $objects) {
+
+ foreach ($handles as $phid => $handle) {
+ $policy = $objects[$phid];
+
+ $handle->setName($policy->getName());
+ $handle->setURI($policy->getHref());
+ }
+ }
+
+ public function canLoadNamedObject($name) {
+ return false;
+ }
+
+}
diff --git a/src/applications/policy/query/PhabricatorPolicyQuery.php b/src/applications/policy/query/PhabricatorPolicyQuery.php
--- a/src/applications/policy/query/PhabricatorPolicyQuery.php
+++ b/src/applications/policy/query/PhabricatorPolicyQuery.php
@@ -4,6 +4,7 @@
private $viewer;
private $object;
+ private $phids;
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
@@ -15,6 +16,11 @@
return $this;
}
+ public function withPHIDs(array $phids) {
+ $this->phids = $phids;
+ return $this;
+ }
+
public static function loadPolicies(
PhabricatorUser $viewer,
PhabricatorPolicyInterface $object) {
@@ -68,9 +74,6 @@
if (!$this->viewer) {
throw new Exception('Call setViewer() before execute()!');
}
- if (!$this->object) {
- throw new Exception('Call setObject() before execute()!');
- }
$results = $this->getGlobalPolicies();
@@ -93,13 +96,15 @@
$results = mpull($results, null, 'getPHID');
$other_policies = array();
- $capabilities = $this->object->getCapabilities();
- foreach ($capabilities as $capability) {
- $policy = $this->object->getPolicy($capability);
- if (!$policy) {
- continue;
+ if ($this->object) {
+ $capabilities = $this->object->getCapabilities();
+ foreach ($capabilities as $capability) {
+ $policy = $this->object->getPolicy($capability);
+ if (!$policy) {
+ continue;
+ }
+ $other_policies[$policy] = $policy;
}
- $other_policies[$policy] = $policy;
}
// If this install doesn't have "Public" enabled, remove it as an option
@@ -127,6 +132,15 @@
$results = msort($results, 'getSortKey');
+ if ($this->phids) {
+ $phids = array_fuse($this->phids);
+ foreach ($results as $key => $result) {
+ if (empty($phids[$result->getPHID()])) {
+ unset($results[$key]);
+ }
+ }
+ }
+
return $results;
}
@@ -160,7 +174,8 @@
$results[$constant] = id(new PhabricatorPolicy())
->setType(PhabricatorPolicyType::TYPE_GLOBAL)
->setPHID($constant)
- ->setName(self::getGlobalPolicyName($constant));
+ ->setName(self::getGlobalPolicyName($constant))
+ ->makeEphemeral();
}
return $results;
diff --git a/src/applications/policy/filter/PhabricatorPolicy.php b/src/applications/policy/storage/PhabricatorPolicy.php
rename from src/applications/policy/filter/PhabricatorPolicy.php
rename to src/applications/policy/storage/PhabricatorPolicy.php
--- a/src/applications/policy/filter/PhabricatorPolicy.php
+++ b/src/applications/policy/storage/PhabricatorPolicy.php
@@ -1,13 +1,33 @@
<?php
-final class PhabricatorPolicy {
+final class PhabricatorPolicy
+ extends PhabricatorPolicyDAO {
+
+ const ACTION_ACCEPT = 'accept';
+ const ACTION_DENY = 'deny';
- private $phid;
private $name;
private $type;
private $href;
private $icon;
+ protected $rules = array();
+ protected $defaultAction = self::ACTION_DENY;
+
+ public function getConfiguration() {
+ return array(
+ self::CONFIG_AUX_PHID => true,
+ self::CONFIG_SERIALIZATION => array(
+ 'rules' => self::SERIALIZATION_JSON,
+ ),
+ ) + parent::getConfiguration();
+ }
+
+ public function generatePHID() {
+ return PhabricatorPHID::generateNewPHID(
+ PhabricatorPolicyPHIDTypePolicy::TYPECONST);
+ }
+
public static function newFromPolicyAndHandle(
$policy_identifier,
PhabricatorObjectHandle $handle = null) {
@@ -48,6 +68,8 @@
break;
}
+ $policy->makeEphemeral();
+
return $policy;
}
@@ -69,15 +91,6 @@
return $this->name;
}
- public function setPHID($phid) {
- $this->phid = $phid;
- return $this;
- }
-
- public function getPHID() {
- return $this->phid;
- }
-
public function setHref($href) {
$this->href = $href;
return $this;
diff --git a/src/applications/policy/storage/PhabricatorPolicyDAO.php b/src/applications/policy/storage/PhabricatorPolicyDAO.php
new file mode 100644
--- /dev/null
+++ b/src/applications/policy/storage/PhabricatorPolicyDAO.php
@@ -0,0 +1,9 @@
+<?php
+
+abstract class PhabricatorPolicyDAO extends PhabricatorLiskDAO {
+
+ public function getApplicationName() {
+ return 'policy';
+ }
+
+}
diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
--- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
+++ b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
@@ -204,6 +204,10 @@
'type' => 'db',
'name' => 'legalpad',
),
+ 'db.policy' => array(
+ 'type' => 'db',
+ 'name' => 'policy',
+ ),
'0000.legacy.sql' => array(
'type' => 'sql',
'name' => $this->getPatchPath('0000.legacy.sql'),
@@ -1664,6 +1668,10 @@
'type' => 'sql',
'name' => $this->getPatchPath('20131006.hdisable.sql'),
),
+ '20131010.pstorage.sql' => array(
+ 'type' => 'sql',
+ 'name' => $this->getPatchPath('20131010.pstorage.sql'),
+ ),
);
}
}

File Metadata

Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/kx/sh/3hccac4tcrxrjngp
Default Alt Text
D7282.diff (12 KB)

Event Timeline