Summary: This commit doesn't change license of any file. It just makes the license implicit (inherited from LICENSE file in the root directory). We are removing the headers for these reasons: - It wastes space in editors, less code is visible in editor upon opening a file. - It brings noise to diff of the first change of any file every year. - It confuses Git file copy detection when creating small files. - We don't have an explicit license header in other files (JS, CSS, images, documentation). - Using license header in every file is not obligatory: http://www.apache.org/dev/apply-license.html#new. This change is approved by Alma Chao (Lead Open Source and IP Counsel at Facebook). Test Plan: Verified that the license survived only in LICENSE file and that it didn't modify externals. Reviewers: epriestley, davidrecordon Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2035 Differential Revision: https://secure.phabricator.com/D3886
90 lines
2.3 KiB
PHP
90 lines
2.3 KiB
PHP
<?php
|
|
|
|
final class AphrontFormPolicyControl extends AphrontFormControl {
|
|
|
|
private $user;
|
|
private $object;
|
|
private $capability;
|
|
private $policies;
|
|
|
|
public function setUser(PhabricatorUser $user) {
|
|
$this->user = $user;
|
|
return $this;
|
|
}
|
|
|
|
public function getUser() {
|
|
return $this->user;
|
|
}
|
|
|
|
public function setPolicyObject(PhabricatorPolicyInterface $object) {
|
|
$this->object = $object;
|
|
return $this;
|
|
}
|
|
|
|
public function setPolicies(array $policies) {
|
|
assert_instances_of($policies, 'PhabricatorPolicy');
|
|
$this->policies = $policies;
|
|
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() {
|
|
return 'aphront-form-control-policy';
|
|
}
|
|
|
|
protected function getOptions() {
|
|
$options = array();
|
|
foreach ($this->policies as $policy) {
|
|
if (($policy->getPHID() == PhabricatorPolicies::POLICY_PUBLIC) &&
|
|
($this->capability != PhabricatorPolicyCapability::CAN_VIEW)) {
|
|
// Never expose "Public" for anything except "Can View".
|
|
continue;
|
|
}
|
|
|
|
$type_name = PhabricatorPolicyType::getPolicyTypeName($policy->getType());
|
|
$options[$type_name][$policy->getPHID()] = $policy->getFullName();
|
|
}
|
|
return $options;
|
|
}
|
|
|
|
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(
|
|
$this->getValue(),
|
|
$this->getOptions(),
|
|
array(
|
|
'name' => $this->getName(),
|
|
'disabled' => $this->getDisabled() ? 'disabled' : null,
|
|
'id' => $this->getID(),
|
|
));
|
|
}
|
|
|
|
|
|
}
|