Differential D20805 Diff 49609 src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | public function handleRequest(AphrontRequest $request) { | ||||
if (!$policy) { | if (!$policy) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
if ($policy->getType() != PhabricatorPolicyType::TYPE_CUSTOM) { | if ($policy->getType() != PhabricatorPolicyType::TYPE_CUSTOM) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$rule_objects = array(); | $rules_view = id(new PhabricatorPolicyRulesView()) | ||||
foreach ($policy->getCustomRuleClasses() as $class) { | ->setViewer($viewer) | ||||
$rule_objects[$class] = newv($class, array()); | ->setPolicy($policy); | ||||
} | |||||
$policy->attachRuleObjects($rule_objects); | |||||
$this->requireResource('policy-transaction-detail-css'); | |||||
$cancel_uri = $this->guessCancelURI($viewer, $xaction); | $cancel_uri = $this->guessCancelURI($viewer, $xaction); | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle($policy->getFullName()) | ->setTitle($policy->getFullName()) | ||||
->setWidth(AphrontDialogView::WIDTH_FORM) | ->setWidth(AphrontDialogView::WIDTH_FORM) | ||||
->appendChild($this->renderPolicyDetails($policy, $rule_objects)) | ->appendChild($rules_view) | ||||
->addCancelButton($cancel_uri, pht('Close')); | ->addCancelButton($cancel_uri, pht('Close')); | ||||
} | } | ||||
private function extractPHIDs( | |||||
PhabricatorPolicy $policy, | |||||
array $rule_objects) { | |||||
$phids = array(); | |||||
foreach ($policy->getRules() as $rule) { | |||||
$rule_object = $rule_objects[$rule['rule']]; | |||||
$phids[] = | |||||
$rule_object->getRequiredHandlePHIDsForSummary($rule['value']); | |||||
} | |||||
return array_filter(array_mergev($phids)); | |||||
} | |||||
private function renderPolicyDetails( | |||||
PhabricatorPolicy $policy, | |||||
array $rule_objects) { | |||||
$details = array(); | |||||
$details[] = phutil_tag( | |||||
'p', | |||||
array( | |||||
'class' => 'policy-transaction-detail-intro', | |||||
), | |||||
pht('These rules are processed in order:')); | |||||
foreach ($policy->getRules() as $index => $rule) { | |||||
$rule_object = $rule_objects[$rule['rule']]; | |||||
if ($rule['action'] == 'allow') { | |||||
$icon = 'fa-check-circle green'; | |||||
} else { | |||||
$icon = 'fa-minus-circle red'; | |||||
} | |||||
$icon = id(new PHUIIconView()) | |||||
->setIcon($icon) | |||||
->setText( | |||||
ucfirst($rule['action']).' '.$rule_object->getRuleDescription()); | |||||
$handle_phids = $rule_object->getRequiredHandlePHIDsForSummary( | |||||
$rule['value']); | |||||
if ($handle_phids) { | |||||
$value = $this->getViewer() | |||||
->renderHandleList($handle_phids) | |||||
->setAsInline(true); | |||||
} else { | |||||
$value = $rule['value']; | |||||
} | |||||
$details[] = phutil_tag('div', | |||||
array( | |||||
'class' => 'policy-transaction-detail-row', | |||||
), | |||||
array( | |||||
$icon, | |||||
$value, | |||||
)); | |||||
} | |||||
$details[] = phutil_tag( | |||||
'p', | |||||
array( | |||||
'class' => 'policy-transaction-detail-end', | |||||
), | |||||
pht( | |||||
'If no rules match, %s all other users.', | |||||
phutil_tag('b', | |||||
array(), | |||||
$policy->getDefaultAction()))); | |||||
return $details; | |||||
} | |||||
} | } |