1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-02 11:42:42 +01:00
phorge-phorge/src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php
epriestley 9a36e6931c Inline custom policy rules inside policy capability explanation dialogs
Summary: Ref T13411. When users click a link to explain a capability (like the policy header on many objects, or the link next to specific capabilities in "Applications", "Diffusion", etc), inline the full ruleset for the custom policy into the dialog if the object has a custom policy.

Test Plan: {F6856365}

Maniphest Tasks: T13411

Differential Revision: https://secure.phabricator.com/D20805
2019-09-12 09:40:50 -07:00

73 lines
2.2 KiB
PHP

<?php
final class PhabricatorApplicationTransactionValueController
extends PhabricatorApplicationTransactionController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$phid = $request->getURIData('phid');
$type = $request->getURIData('value');
$xaction = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(array($phid))
->executeOne();
if (!$xaction) {
return new Aphront404Response();
}
// For now, this pathway only supports policy transactions
// to show the details of custom policies. If / when this pathway
// supports more transaction types, rendering coding should be moved
// into PhabricatorTransactions e.g. feed rendering code.
// TODO: This should be some kind of "hey do you support this?" thing on
// the transactions themselves.
switch ($xaction->getTransactionType()) {
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_JOIN_POLICY:
case PhabricatorRepositoryPushPolicyTransaction::TRANSACTIONTYPE:
case PhabricatorApplicationPolicyChangeTransaction::TRANSACTIONTYPE:
break;
default:
return new Aphront404Response();
break;
}
if ($type == 'old') {
$value = $xaction->getOldValue();
} else {
$value = $xaction->getNewValue();
}
$policy = id(new PhabricatorPolicyQuery())
->setViewer($viewer)
->withPHIDs(array($value))
->executeOne();
if (!$policy) {
return new Aphront404Response();
}
if ($policy->getType() != PhabricatorPolicyType::TYPE_CUSTOM) {
return new Aphront404Response();
}
$rules_view = id(new PhabricatorPolicyRulesView())
->setViewer($viewer)
->setPolicy($policy);
$cancel_uri = $this->guessCancelURI($viewer, $xaction);
return $this->newDialog()
->setTitle($policy->getFullName())
->setWidth(AphrontDialogView::WIDTH_FORM)
->appendChild($rules_view)
->addCancelButton($cancel_uri, pht('Close'));
}
}