1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 14:30:56 +01:00

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
This commit is contained in:
epriestley 2012-08-09 09:45:07 -07:00
parent 57a0722636
commit c34dd2158b

View file

@ -18,6 +18,10 @@
final class AphrontFormPolicyControl extends AphrontFormControl { final class AphrontFormPolicyControl extends AphrontFormControl {
private $user;
private $object;
private $capability;
public function setUser(PhabricatorUser $user) { public function setUser(PhabricatorUser $user) {
$this->user = $user; $this->user = $user;
return $this; return $this;
@ -27,6 +31,25 @@ final class AphrontFormPolicyControl extends AphrontFormControl {
return $this->user; return $this->user;
} }
public function setPolicyObject(PhabricatorPolicyInterface $object) {
$this->object = $object;
return $this;
}
public function setCapability($capability) {
$this->capability = $capability;
$labels = array(
PhabricatorPolicyCapability::CAN_VIEW => 'Visible To',
PhabricatorPolicyCapability::CAN_EDIT => 'Editable By',
PhabricatorPolicyCapability::CAN_JOIN => 'Joinable By',
);
$this->setLabel(idx($labels, $this->capability, 'Unknown Policy'));
return $this;
}
protected function getCustomControlClass() { protected function getCustomControlClass() {
return 'aphront-form-control-policy'; return 'aphront-form-control-policy';
} }
@ -34,6 +57,11 @@ final class AphrontFormPolicyControl extends AphrontFormControl {
private function getOptions() { private function getOptions() {
$show_public = PhabricatorEnv::getEnvConfig('policy.allow-public'); $show_public = PhabricatorEnv::getEnvConfig('policy.allow-public');
if ($this->capability != PhabricatorPolicyCapability::CAN_VIEW) {
// We don't generally permit 'public' for anything except viewing.
$show_public = false;
}
if ($this->getValue() == PhabricatorPolicies::POLICY_PUBLIC) { if ($this->getValue() == PhabricatorPolicies::POLICY_PUBLIC) {
// If the object already has a "public" policy, show the option in // If the object already has a "public" policy, show the option in
// the dropdown even if it will be enforced as "users", so we don't // the dropdown even if it will be enforced as "users", so we don't
@ -59,6 +87,20 @@ final class AphrontFormPolicyControl extends AphrontFormControl {
} }
protected function renderInput() { protected function renderInput() {
if (!$this->object) {
throw new Exception("Call setPolicyObject() before rendering!");
}
if (!$this->capability) {
throw new Exception("Call setCapability() before rendering!");
}
$policy = $this->object->getPolicy($this->capability);
if (!$policy) {
// TODO: Make this configurable.
$policy = PhabricatorPolicies::POLICY_USER;
}
$this->setValue($policy);
return AphrontFormSelectControl::renderSelectTag( return AphrontFormSelectControl::renderSelectTag(
$this->getValue(), $this->getValue(),
$this->getOptions(), $this->getOptions(),