@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Prepare the policy rule edit endpoint for integration

Summary: Ref T603. Allow the endpoint to take an existing policy PHID to populate the editor and return a useful datastructure.

Test Plan: In the next revision, actually hooked this up.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7299

+66 -21
+6 -2
src/__phutil_library_map__.php
··· 3676 3676 'PhabricatorPhrequentConfigOptions' => 'PhabricatorApplicationConfigOptions', 3677 3677 'PhabricatorPhrictionConfigOptions' => 'PhabricatorApplicationConfigOptions', 3678 3678 'PhabricatorPolicies' => 'PhabricatorPolicyConstants', 3679 - 'PhabricatorPolicy' => 'PhabricatorPolicyDAO', 3679 + 'PhabricatorPolicy' => 3680 + array( 3681 + 0 => 'PhabricatorPolicyDAO', 3682 + 1 => 'PhabricatorPolicyInterface', 3683 + ), 3680 3684 'PhabricatorPolicyAwareQuery' => 'PhabricatorOffsetPagedQuery', 3681 3685 'PhabricatorPolicyAwareTestQuery' => 'PhabricatorPolicyAwareQuery', 3682 3686 'PhabricatorPolicyCapability' => 'Phobject', ··· 3694 3698 'PhabricatorPolicyManagementUnlockWorkflow' => 'PhabricatorPolicyManagementWorkflow', 3695 3699 'PhabricatorPolicyManagementWorkflow' => 'PhutilArgumentWorkflow', 3696 3700 'PhabricatorPolicyPHIDTypePolicy' => 'PhabricatorPHIDType', 3697 - 'PhabricatorPolicyQuery' => 'PhabricatorQuery', 3701 + 'PhabricatorPolicyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 3698 3702 'PhabricatorPolicyRuleAdministrators' => 'PhabricatorPolicyRule', 3699 3703 'PhabricatorPolicyRuleLunarPhase' => 'PhabricatorPolicyRule', 3700 3704 'PhabricatorPolicyRuleProjects' => 'PhabricatorPolicyRule',
+1 -1
src/applications/policy/application/PhabricatorApplicationPolicy.php
··· 15 15 '/policy/' => array( 16 16 'explain/(?P<phid>[^/]+)/(?P<capability>[^/]+)/' 17 17 => 'PhabricatorPolicyExplainController', 18 - 'edit/' => 'PhabricatorPolicyEditController', 18 + 'edit/(?:(?P<phid>[^/]+)/)?' => 'PhabricatorPolicyEditController', 19 19 ), 20 20 ); 21 21 }
+55 -18
src/applications/policy/controller/PhabricatorPolicyEditController.php
··· 3 3 final class PhabricatorPolicyEditController 4 4 extends PhabricatorPolicyController { 5 5 6 + private $phid; 7 + 8 + public function willProcessRequest(array $data) { 9 + $this->phid = idx($data, 'phid'); 10 + } 11 + 6 12 public function processRequest() { 7 13 $request = $this->getRequest(); 8 14 $viewer = $request->getUser(); 9 - 10 - $policy = new PhabricatorPolicy(); 11 - 12 - $root_id = celerity_generate_unique_node_id(); 13 15 14 16 $action_options = array( 15 - 'allow' => pht('Allow'), 16 - 'deny' => pht('Deny'), 17 + PhabricatorPolicy::ACTION_ALLOW => pht('Allow'), 18 + PhabricatorPolicy::ACTION_DENY => pht('Deny'), 17 19 ); 18 20 19 21 $rules = id(new PhutilSymbolLoader()) 20 22 ->setAncestorClass('PhabricatorPolicyRule') 21 23 ->loadObjects(); 22 - 23 24 $rules = msort($rules, 'getRuleOrder'); 24 25 25 - $default_value = 'deny'; 26 26 $default_rule = array( 27 27 'action' => head_key($action_options), 28 28 'rule' => head_key($rules), 29 29 'value' => null, 30 30 ); 31 31 32 + if ($this->phid) { 33 + $policies = id(new PhabricatorPolicyQuery()) 34 + ->setViewer($viewer) 35 + ->withPHIDs(array($this->phid)) 36 + ->execute(); 37 + if (!$policies) { 38 + return new Aphront404Response(); 39 + } 40 + $policy = head($policies); 41 + } else { 42 + $policy = id(new PhabricatorPolicy()) 43 + ->setRules(array($default_rule)) 44 + ->setDefaultAction(PhabricatorPolicy::ACTION_DENY); 45 + } 46 + 47 + $root_id = celerity_generate_unique_node_id(); 48 + 49 + $default_action = $policy->getDefaultAction(); 50 + $rule_data = $policy->getRules(); 51 + 32 52 if ($request->isFormPost()) { 33 53 $data = $request->getStr('rules'); 34 54 $data = @json_decode($data, true); ··· 63 83 ); 64 84 } 65 85 66 - $policy->setRules($rule_data); 67 - $policy->setDefaultAction($request->getStr('default')); 68 - $policy->save(); 86 + // NOTE: Policies are immutable once created, and we always create a new 87 + // policy here. If we didn't, we would need to lock this endpoint down, 88 + // as users could otherwise just go edit the policies of objects with 89 + // custom policies. 69 90 70 - // TODO: Integrate with policy editors. 71 - $id = $policy->getID(); 72 - throw new Exception("OK, saved policy {$id}!"); 73 - } else { 74 - $rule_data = array( 75 - $default_rule, 91 + $new_policy = new PhabricatorPolicy(); 92 + $new_policy->setRules($rule_data); 93 + $new_policy->setDefaultAction($request->getStr('default')); 94 + $new_policy->save(); 95 + 96 + $data = array( 97 + 'phid' => $new_policy->getPHID(), 98 + 'info' => array( 99 + 'name' => $new_policy->getName(), 100 + 'full' => $new_policy->getName(), 101 + 'icon' => $new_policy->getIcon(), 102 + ), 76 103 ); 104 + 105 + return id(new AphrontAjaxResponse())->setContent($data); 106 + } 107 + 108 + // Convert rule values to display format (for example, expanding PHIDs 109 + // into tokens). 110 + foreach ($rule_data as $key => $rule) { 111 + $rule_data[$key]['value'] = $rules[$rule['rule']]->getValueForDisplay( 112 + $viewer, 113 + $rule['value']); 77 114 } 78 115 79 116 $default_select = AphrontFormSelectControl::renderSelectTag( 80 - $default_value, 117 + $default_action, 81 118 $action_options, 82 119 array( 83 120 'name' => 'default',
+4
src/applications/policy/rule/PhabricatorPolicyRuleUsers.php
··· 38 38 } 39 39 40 40 public function getValueForDisplay(PhabricatorUser $viewer, $value) { 41 + if (!$value) { 42 + return array(); 43 + } 44 + 41 45 $handles = id(new PhabricatorHandleQuery()) 42 46 ->setViewer($viewer) 43 47 ->withPHIDs($value)