@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorApplicationTransactionValueController
4 extends PhabricatorApplicationTransactionController {
5
6 public function shouldAllowPublic() {
7 return true;
8 }
9
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $this->getViewer();
12 $phid = $request->getURIData('phid');
13 $type = $request->getURIData('value');
14
15 $xaction = id(new PhabricatorObjectQuery())
16 ->setViewer($viewer)
17 ->withPHIDs(array($phid))
18 ->executeOne();
19 if (!$xaction) {
20 return new Aphront404Response();
21 }
22
23 // For now, this pathway only supports policy transactions
24 // to show the details of custom policies. If / when this pathway
25 // supports more transaction types, rendering coding should be moved
26 // into PhabricatorTransactions e.g. feed rendering code.
27
28 // TODO: This should be some kind of "hey do you support this?" thing on
29 // the transactions themselves.
30
31 switch ($xaction->getTransactionType()) {
32 case PhabricatorTransactions::TYPE_VIEW_POLICY:
33 case PhabricatorTransactions::TYPE_EDIT_POLICY:
34 case PhabricatorTransactions::TYPE_JOIN_POLICY:
35 case PhabricatorRepositoryPushPolicyTransaction::TRANSACTIONTYPE:
36 case PhabricatorApplicationPolicyChangeTransaction::TRANSACTIONTYPE:
37 break;
38 default:
39 return new Aphront404Response();
40 }
41
42 if ($type == 'old') {
43 $value = $xaction->getOldValue();
44 } else {
45 $value = $xaction->getNewValue();
46 }
47
48 $policy = id(new PhabricatorPolicyQuery())
49 ->setViewer($viewer)
50 ->withPHIDs(array($value))
51 ->executeOne();
52 if (!$policy) {
53 return new Aphront404Response();
54 }
55
56 if ($policy->getType() != PhabricatorPolicyType::TYPE_CUSTOM) {
57 return new Aphront404Response();
58 }
59
60 $rules_view = id(new PhabricatorPolicyRulesView())
61 ->setViewer($viewer)
62 ->setPolicy($policy);
63
64 $cancel_uri = $this->guessCancelURI($viewer, $xaction);
65
66 return $this->newDialog()
67 ->setTitle($policy->getFullName())
68 ->setWidth(AphrontDialogView::WIDTH_FORM)
69 ->appendChild($rules_view)
70 ->addCancelButton($cancel_uri, pht('Close'));
71 }
72}