Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14344480
D7282.id16395.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
D7282.id16395.diff
View Options
Index: resources/sql/patches/20131010.pstorage.sql
===================================================================
--- /dev/null
+++ 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;
Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ 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,6 +3672,7 @@
'PhabricatorPhrequentConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPhrictionConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPolicies' => 'PhabricatorPolicyConstants',
+ 'PhabricatorPolicy' => 'PhabricatorPolicyDAO',
'PhabricatorPolicyAwareQuery' => 'PhabricatorOffsetPagedQuery',
'PhabricatorPolicyAwareTestQuery' => 'PhabricatorPolicyAwareQuery',
'PhabricatorPolicyCapability' => 'Phobject',
@@ -3678,6 +3681,7 @@
'PhabricatorPolicyCapabilityCanView' => 'PhabricatorPolicyCapability',
'PhabricatorPolicyConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPolicyController' => 'PhabricatorController',
+ 'PhabricatorPolicyDAO' => 'PhabricatorLiskDAO',
'PhabricatorPolicyDataTestCase' => 'PhabricatorTestCase',
'PhabricatorPolicyEditController' => 'PhabricatorPolicyController',
'PhabricatorPolicyException' => 'Exception',
@@ -3685,6 +3689,7 @@
'PhabricatorPolicyManagementShowWorkflow' => 'PhabricatorPolicyManagementWorkflow',
'PhabricatorPolicyManagementUnlockWorkflow' => 'PhabricatorPolicyManagementWorkflow',
'PhabricatorPolicyManagementWorkflow' => 'PhutilArgumentWorkflow',
+ 'PhabricatorPolicyPHIDTypePolicy' => 'PhabricatorPHIDType',
'PhabricatorPolicyQuery' => 'PhabricatorQuery',
'PhabricatorPolicyRuleAdministrators' => 'PhabricatorPolicyRule',
'PhabricatorPolicyRuleLunarPhase' => 'PhabricatorPolicyRule',
Index: src/applications/policy/controller/PhabricatorPolicyEditController.php
===================================================================
--- src/applications/policy/controller/PhabricatorPolicyEditController.php
+++ 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,7 +55,6 @@
$rule_obj = $rules[$rule_class];
$value = $rule_obj->getValueForStorage(idx($rule, 'value'));
- $value = $rule_obj->getValueForDisplay($viewer, $value);
$rule_data[] = array(
'action' => $action,
@@ -62,7 +63,13 @@
);
}
- $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(
Index: src/applications/policy/phid/PhabricatorPolicyPHIDTypePolicy.php
===================================================================
--- /dev/null
+++ 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;
+ }
+
+}
Index: src/applications/policy/query/PhabricatorPolicyQuery.php
===================================================================
--- src/applications/policy/query/PhabricatorPolicyQuery.php
+++ 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;
Index: src/applications/policy/storage/PhabricatorPolicy.php
===================================================================
--- src/applications/policy/storage/PhabricatorPolicy.php
+++ 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;
Index: src/applications/policy/storage/PhabricatorPolicyDAO.php
===================================================================
--- /dev/null
+++ src/applications/policy/storage/PhabricatorPolicyDAO.php
@@ -0,0 +1,9 @@
+<?php
+
+abstract class PhabricatorPolicyDAO extends PhabricatorLiskDAO {
+
+ public function getApplicationName() {
+ return 'policy';
+ }
+
+}
Index: src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
===================================================================
--- src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
+++ 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
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 12:44 AM (20 h, 34 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6908887
Default Alt Text
D7282.id16395.diff (11 KB)
Attached To
Mode
D7282: Add storage for custom policies
Attached
Detach File
Event Timeline
Log In to Comment