@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 DiffusionRepositoryPoliciesManagementPanel
4 extends DiffusionRepositoryManagementPanel {
5
6 const PANELKEY = 'policies';
7
8 public function getManagementPanelLabel() {
9 return pht('Policies');
10 }
11
12 public function getManagementPanelOrder() {
13 return 300;
14 }
15
16 public function getManagementPanelIcon() {
17 $viewer = $this->getViewer();
18 $repository = $this->getRepository();
19
20 $can_view = PhabricatorPolicyCapability::CAN_VIEW;
21 $can_edit = PhabricatorPolicyCapability::CAN_EDIT;
22 $can_push = DiffusionPushCapability::CAPABILITY;
23
24 $actual_values = array(
25 'spacePHID' => $repository->getSpacePHID(),
26 'view' => $repository->getPolicy($can_view),
27 'edit' => $repository->getPolicy($can_edit),
28 'push' => $repository->getPolicy($can_push),
29 );
30
31 $default = PhabricatorRepository::initializeNewRepository(
32 $viewer);
33
34 $default_values = array(
35 'spacePHID' => $default->getSpacePHID(),
36 'view' => $default->getPolicy($can_view),
37 'edit' => $default->getPolicy($can_edit),
38 'push' => $default->getPolicy($can_push),
39 );
40
41 if ($actual_values === $default_values) {
42 return 'fa-lock grey';
43 } else {
44 return 'fa-lock';
45 }
46 }
47
48 protected function getEditEngineFieldKeys() {
49 return array(
50 'policy.view',
51 'policy.edit',
52 'spacePHID',
53 'policy.push',
54 );
55 }
56
57 public function buildManagementPanelCurtain() {
58 $repository = $this->getRepository();
59 $viewer = $this->getViewer();
60 $action_list = $this->newActionList();
61
62 $can_edit = PhabricatorPolicyFilter::hasCapability(
63 $viewer,
64 $repository,
65 PhabricatorPolicyCapability::CAN_EDIT);
66
67 $edit_uri = $this->getEditPageURI();
68
69 $action_list->addAction(
70 id(new PhabricatorActionView())
71 ->setName(pht('Edit Policies'))
72 ->setHref($edit_uri)
73 ->setIcon('fa-pencil')
74 ->setDisabled(!$can_edit)
75 ->setWorkflow(!$can_edit));
76
77 return $this->newCurtainView()
78 ->setActionList($action_list);
79 }
80
81
82 public function buildManagementPanelContent() {
83 $repository = $this->getRepository();
84 $viewer = $this->getViewer();
85
86 $view = id(new PHUIPropertyListView())
87 ->setViewer($viewer);
88
89 $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
90 $viewer,
91 $repository);
92
93 $view_parts = array();
94 if (PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($viewer)) {
95 $space_phid = PhabricatorSpacesNamespaceQuery::getObjectSpacePHID(
96 $repository);
97 $view_parts[] = $viewer->renderHandle($space_phid);
98 }
99 $view_parts[] = $descriptions[PhabricatorPolicyCapability::CAN_VIEW];
100
101 $view->addProperty(
102 pht('Visible To'),
103 phutil_implode_html(" \xC2\xB7 ", $view_parts));
104
105 $view->addProperty(
106 pht('Editable By'),
107 $descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
108
109 $pushable = $repository->isHosted()
110 ? $descriptions[DiffusionPushCapability::CAPABILITY]
111 : phutil_tag('em', array(), pht('Not a Hosted Repository'));
112 $view->addProperty(pht('Pushable By'), $pushable);
113
114 return $this->newBox(pht('Policies'), $view);
115 }
116
117}