@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.

Enhance policy control

Summary: Make the policy control accept a more sensible set of inputs. (This currently has no callsites.)

Test Plan: Used in future diff.

Reviewers: vrana, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

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

+42
+42
src/view/form/control/AphrontFormPolicyControl.php
··· 18 18 19 19 final class AphrontFormPolicyControl extends AphrontFormControl { 20 20 21 + private $user; 22 + private $object; 23 + private $capability; 24 + 21 25 public function setUser(PhabricatorUser $user) { 22 26 $this->user = $user; 23 27 return $this; ··· 27 31 return $this->user; 28 32 } 29 33 34 + public function setPolicyObject(PhabricatorPolicyInterface $object) { 35 + $this->object = $object; 36 + return $this; 37 + } 38 + 39 + public function setCapability($capability) { 40 + $this->capability = $capability; 41 + 42 + $labels = array( 43 + PhabricatorPolicyCapability::CAN_VIEW => 'Visible To', 44 + PhabricatorPolicyCapability::CAN_EDIT => 'Editable By', 45 + PhabricatorPolicyCapability::CAN_JOIN => 'Joinable By', 46 + ); 47 + 48 + $this->setLabel(idx($labels, $this->capability, 'Unknown Policy')); 49 + 50 + return $this; 51 + } 52 + 30 53 protected function getCustomControlClass() { 31 54 return 'aphront-form-control-policy'; 32 55 } 33 56 34 57 private function getOptions() { 35 58 $show_public = PhabricatorEnv::getEnvConfig('policy.allow-public'); 59 + 60 + if ($this->capability != PhabricatorPolicyCapability::CAN_VIEW) { 61 + // We don't generally permit 'public' for anything except viewing. 62 + $show_public = false; 63 + } 36 64 37 65 if ($this->getValue() == PhabricatorPolicies::POLICY_PUBLIC) { 38 66 // If the object already has a "public" policy, show the option in ··· 59 87 } 60 88 61 89 protected function renderInput() { 90 + if (!$this->object) { 91 + throw new Exception("Call setPolicyObject() before rendering!"); 92 + } 93 + if (!$this->capability) { 94 + throw new Exception("Call setCapability() before rendering!"); 95 + } 96 + 97 + $policy = $this->object->getPolicy($this->capability); 98 + if (!$policy) { 99 + // TODO: Make this configurable. 100 + $policy = PhabricatorPolicies::POLICY_USER; 101 + } 102 + $this->setValue($policy); 103 + 62 104 return AphrontFormSelectControl::renderSelectTag( 63 105 $this->getValue(), 64 106 $this->getOptions(),