@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 PhabricatorAuthProviderConfig
4 extends PhabricatorAuthDAO
5 implements
6 PhabricatorApplicationTransactionInterface,
7 PhabricatorPolicyInterface,
8 PhabricatorDestructibleInterface {
9
10 protected $providerClass;
11 protected $providerType;
12 protected $providerDomain;
13
14 protected $isEnabled;
15 protected $shouldAllowLogin = 0;
16 protected $shouldAllowRegistration = 0;
17 protected $shouldAllowLink = 0;
18 protected $shouldAllowUnlink = 0;
19 protected $shouldTrustEmails = 0;
20 protected $shouldAutoLogin = 0;
21
22 protected $properties = array();
23
24 private $provider;
25
26 public function generatePHID() {
27 return PhabricatorPHID::generateNewPHID(
28 PhabricatorAuthAuthProviderPHIDType::TYPECONST);
29 }
30
31 protected function getConfiguration() {
32 return array(
33 self::CONFIG_AUX_PHID => true,
34 self::CONFIG_SERIALIZATION => array(
35 'properties' => self::SERIALIZATION_JSON,
36 ),
37 self::CONFIG_COLUMN_SCHEMA => array(
38 'isEnabled' => 'bool',
39 'providerClass' => 'text128',
40 'providerType' => 'text32',
41 'providerDomain' => 'text128',
42 'shouldAllowLogin' => 'bool',
43 'shouldAllowRegistration' => 'bool',
44 'shouldAllowLink' => 'bool',
45 'shouldAllowUnlink' => 'bool',
46 'shouldTrustEmails' => 'bool',
47 'shouldAutoLogin' => 'bool',
48 ),
49 self::CONFIG_KEY_SCHEMA => array(
50 'key_provider' => array(
51 'columns' => array('providerType', 'providerDomain'),
52 'unique' => true,
53 ),
54 'key_class' => array(
55 'columns' => array('providerClass'),
56 ),
57 ),
58 ) + parent::getConfiguration();
59 }
60
61 public function getProperty($key, $default = null) {
62 return idx($this->properties, $key, $default);
63 }
64
65 public function setProperty($key, $value) {
66 $this->properties[$key] = $value;
67 return $this;
68 }
69
70 public function getProvider() {
71 if (!$this->provider) {
72 $base = PhabricatorAuthProvider::getAllBaseProviders();
73 $found = null;
74 foreach ($base as $provider) {
75 if (get_class($provider) == $this->providerClass) {
76 $found = $provider;
77 break;
78 }
79 }
80 if ($found) {
81 $this->provider = id(clone $found)->attachProviderConfig($this);
82 }
83 }
84 return $this->provider;
85 }
86
87 public function getURI() {
88 return '/auth/config/view/'.$this->getID().'/';
89 }
90
91 public function getObjectName() {
92 return pht('Auth Provider %d', $this->getID());
93 }
94
95 public function getDisplayName() {
96 return $this->getProvider()->getProviderName();
97 }
98
99 public function getSortVector() {
100 return id(new PhutilSortVector())
101 ->addString($this->getDisplayName());
102 }
103
104 public function newIconView() {
105 return $this->getProvider()->newIconView();
106 }
107
108
109/* -( PhabricatorApplicationTransactionInterface )------------------------- */
110
111
112 public function getApplicationTransactionEditor() {
113 return new PhabricatorAuthProviderConfigEditor();
114 }
115
116 public function getApplicationTransactionTemplate() {
117 return new PhabricatorAuthProviderConfigTransaction();
118 }
119
120
121/* -( PhabricatorPolicyInterface )----------------------------------------- */
122
123
124 public function getCapabilities() {
125 return array(
126 PhabricatorPolicyCapability::CAN_VIEW,
127 PhabricatorPolicyCapability::CAN_EDIT,
128 );
129 }
130
131 public function getPolicy($capability) {
132 switch ($capability) {
133 case PhabricatorPolicyCapability::CAN_VIEW:
134 return PhabricatorPolicies::POLICY_USER;
135 case PhabricatorPolicyCapability::CAN_EDIT:
136 return PhabricatorPolicies::POLICY_ADMIN;
137 }
138 }
139
140 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
141 return false;
142 }
143
144
145/* -( PhabricatorDestructibleInterface )----------------------------------- */
146
147
148 public function destroyObjectPermanently(
149 PhabricatorDestructionEngine $engine) {
150
151 $viewer = $engine->getViewer();
152 $config_phid = $this->getPHID();
153
154 $accounts = id(new PhabricatorExternalAccountQuery())
155 ->setViewer($viewer)
156 ->withProviderConfigPHIDs(array($config_phid))
157 ->newIterator();
158 foreach ($accounts as $account) {
159 $engine->destroyObject($account);
160 }
161
162 $identifiers = id(new PhabricatorExternalAccountIdentifierQuery())
163 ->setViewer($viewer)
164 ->withProviderConfigPHIDs(array($config_phid))
165 ->newIterator();
166 foreach ($identifiers as $identifier) {
167 $engine->destroyObject($identifier);
168 }
169
170 $this->delete();
171 }
172
173}