@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 PhabricatorPolicyRulesView
4 extends AphrontView {
5
6 private $policy;
7
8 public function setPolicy(PhabricatorPolicy $policy) {
9 $this->policy = $policy;
10 return $this;
11 }
12
13 public function getPolicy() {
14 return $this->policy;
15 }
16
17 public function render() {
18 $policy = $this->getPolicy();
19
20 require_celerity_resource('policy-transaction-detail-css');
21
22 $rule_objects = array();
23 foreach ($policy->getCustomRuleClasses() as $class) {
24 $rule_objects[$class] = newv($class, array());
25 }
26
27 $policy = clone $policy;
28 $policy->attachRuleObjects($rule_objects);
29
30 $details = array();
31 $details[] = phutil_tag(
32 'p',
33 array(
34 'class' => 'policy-transaction-detail-intro',
35 ),
36 pht('These rules are processed in order:'));
37
38 foreach ($policy->getRules() as $index => $rule) {
39 $rule_object = $rule_objects[$rule['rule']];
40 if ($rule['action'] == 'allow') {
41 $icon = 'fa-check-circle green';
42 } else {
43 $icon = 'fa-minus-circle red';
44 }
45 $icon = id(new PHUIIconView())
46 ->setIcon($icon)
47 ->setText(
48 ucfirst($rule['action']).' '.$rule_object->getRuleDescription());
49
50 $handle_phids = $rule_object->getRequiredHandlePHIDsForSummary(
51 $rule['value']);
52 if ($handle_phids) {
53 $value = $this->getViewer()
54 ->renderHandleList($handle_phids)
55 ->setAsInline(true);
56 } else {
57 $value = $rule['value'];
58 }
59
60 $details[] = phutil_tag('div',
61 array(
62 'class' => 'policy-transaction-detail-row',
63 ),
64 array(
65 $icon,
66 $value,
67 ));
68 }
69
70 $details[] = phutil_tag(
71 'p',
72 array(
73 'class' => 'policy-transaction-detail-end',
74 ),
75 pht(
76 'If no rules match, %s all other users.',
77 phutil_tag('b',
78 array(),
79 $policy->getDefaultAction())));
80
81 return $details;
82 }
83
84}