@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 PhabricatorNamedQuery extends PhabricatorSearchDAO
4 implements PhabricatorPolicyInterface {
5
6 protected $queryKey;
7 protected $queryName;
8 protected $userPHID;
9 protected $engineClassName;
10
11 protected $isBuiltin = 0;
12 protected $isDisabled = 0;
13 protected $sequence = 0;
14
15 const SCOPE_GLOBAL = 'scope.global';
16
17 protected function getConfiguration() {
18 return array(
19 self::CONFIG_COLUMN_SCHEMA => array(
20 'engineClassName' => 'text128',
21 'queryName' => 'text255',
22 'queryKey' => 'text12',
23 'isBuiltin' => 'bool',
24 'isDisabled' => 'bool',
25 'sequence' => 'uint32',
26 ),
27 self::CONFIG_KEY_SCHEMA => array(
28 'key_userquery' => array(
29 'columns' => array('userPHID', 'engineClassName', 'queryKey'),
30 'unique' => true,
31 ),
32 ),
33 ) + parent::getConfiguration();
34 }
35
36 public function isGlobal() {
37 if ($this->getIsBuiltin()) {
38 return true;
39 }
40
41 if ($this->getUserPHID() === self::SCOPE_GLOBAL) {
42 return true;
43 }
44
45 return false;
46 }
47
48 public function getNamedQuerySortVector() {
49 if (!$this->isGlobal()) {
50 $phase = 0;
51 } else {
52 $phase = 1;
53 }
54
55 return id(new PhutilSortVector())
56 ->addInt($phase)
57 ->addInt($this->sequence)
58 ->addInt($this->getID());
59 }
60
61/* -( PhabricatorPolicyInterface )----------------------------------------- */
62
63
64 public function getCapabilities() {
65 return array(
66 PhabricatorPolicyCapability::CAN_VIEW,
67 PhabricatorPolicyCapability::CAN_EDIT,
68 );
69 }
70
71 public function getPolicy($capability) {
72 return PhabricatorPolicies::POLICY_NOONE;
73 }
74
75 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
76 if ($viewer->getPHID() == $this->getUserPHID()) {
77 return true;
78 }
79
80 if ($this->isGlobal()) {
81 switch ($capability) {
82 case PhabricatorPolicyCapability::CAN_VIEW:
83 return true;
84 case PhabricatorPolicyCapability::CAN_EDIT:
85 return $viewer->getIsAdmin();
86 }
87 }
88
89 return false;
90 }
91
92 public function describeAutomaticCapability($capability) {
93 return pht(
94 'The queries you have saved are private. Only you can view or edit '.
95 'them.');
96 }
97
98}