Differential D20918 Diff 49845 src/applications/policy/controller/PhabricatorPolicyExplainController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/policy/controller/PhabricatorPolicyExplainController.php
Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | private function buildSpaceSection( | ||||
$space_section->appendHint( | $space_section->appendHint( | ||||
pht( | pht( | ||||
'After a user passes space policy checks, they must still pass '. | 'After a user passes space policy checks, they must still pass '. | ||||
'object policy checks.')); | 'object policy checks.')); | ||||
return $space_section; | return $space_section; | ||||
} | } | ||||
private function getStrengthInformation( | |||||
PhabricatorPolicyInterface $object, | |||||
PhabricatorPolicy $policy, | |||||
$capability) { | |||||
$viewer = $this->getViewer(); | |||||
$strength = null; | |||||
if ($object instanceof PhabricatorPolicyCodexInterface) { | |||||
$codex = id(PhabricatorPolicyCodex::newFromObject($object, $viewer)) | |||||
->setCapability($capability); | |||||
$strength = $codex->compareToDefaultPolicy($policy); | |||||
$default_policy = $codex->getDefaultPolicy(); | |||||
} else { | |||||
$default_policy = PhabricatorPolicyQuery::getDefaultPolicyForObject( | |||||
$viewer, | |||||
$object, | |||||
$capability); | |||||
if ($default_policy) { | |||||
if ($default_policy->getPHID() == $policy->getPHID()) { | |||||
return; | |||||
} | |||||
if ($default_policy->getPHID() != $policy->getPHID()) { | |||||
if ($default_policy->isStrongerThan($policy)) { | |||||
$strength = PhabricatorPolicyStrengthConstants::WEAKER; | |||||
} else if ($policy->isStrongerThan($default_policy)) { | |||||
$strength = PhabricatorPolicyStrengthConstants::STRONGER; | |||||
} else { | |||||
$strength = PhabricatorPolicyStrengthConstants::ADJUSTED; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
if (!$strength) { | |||||
return; | |||||
} | |||||
if ($strength == PhabricatorPolicyStrengthConstants::WEAKER) { | |||||
$info = pht( | |||||
'This object has a less restrictive policy ("%s") than the default '. | |||||
'policy for similar objects (which is "%s").', | |||||
$policy->getShortName(), | |||||
$default_policy->getShortName()); | |||||
} else if ($strength == PhabricatorPolicyStrengthConstants::STRONGER) { | |||||
$info = pht( | |||||
'This object has a more restrictive policy ("%s") than the default '. | |||||
'policy for similar objects (which is "%s").', | |||||
$policy->getShortName(), | |||||
$default_policy->getShortName()); | |||||
} else { | |||||
$info = pht( | |||||
'This object has a different policy ("%s") than the default policy '. | |||||
'for similar objects (which is "%s").', | |||||
$policy->getShortName(), | |||||
$default_policy->getShortName()); | |||||
} | |||||
return $info; | |||||
} | |||||
private function getCapabilityName($capability) { | private function getCapabilityName($capability) { | ||||
$capability_name = $capability; | $capability_name = $capability; | ||||
$capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability); | $capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability); | ||||
if ($capobj) { | if ($capobj) { | ||||
$capability_name = $capobj->getCapabilityName(); | $capability_name = $capobj->getCapabilityName(); | ||||
} | } | ||||
return $capability_name; | return $capability_name; | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | private function buildObjectSection( | ||||
if ($policy->isCustomPolicy()) { | if ($policy->isCustomPolicy()) { | ||||
$rules_view = id(new PhabricatorPolicyRulesView()) | $rules_view = id(new PhabricatorPolicyRulesView()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->setPolicy($policy); | ->setPolicy($policy); | ||||
$object_section->appendRulesView($rules_view); | $object_section->appendRulesView($rules_view); | ||||
} | } | ||||
$strength = $this->getStrengthInformation($object, $policy, $capability); | |||||
if ($strength) { | |||||
$object_section->appendHint($strength); | |||||
} | |||||
return $object_section; | return $object_section; | ||||
} | } | ||||
} | } |