Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/passphrase/storage/PassphraseCredential.php
12256 views
1
<?php
2
3
final class PassphraseCredential extends PassphraseDAO
4
implements
5
PhabricatorApplicationTransactionInterface,
6
PhabricatorPolicyInterface,
7
PhabricatorFlaggableInterface,
8
PhabricatorSubscribableInterface,
9
PhabricatorDestructibleInterface,
10
PhabricatorSpacesInterface,
11
PhabricatorFulltextInterface,
12
PhabricatorFerretInterface {
13
14
protected $name;
15
protected $credentialType;
16
protected $providesType;
17
protected $viewPolicy;
18
protected $editPolicy;
19
protected $description;
20
protected $username;
21
protected $secretID;
22
protected $isDestroyed;
23
protected $isLocked = 0;
24
protected $allowConduit = 0;
25
protected $authorPHID;
26
protected $spacePHID;
27
28
private $secret = self::ATTACHABLE;
29
private $implementation = self::ATTACHABLE;
30
31
public static function initializeNewCredential(PhabricatorUser $actor) {
32
$app = id(new PhabricatorApplicationQuery())
33
->setViewer($actor)
34
->withClasses(array('PhabricatorPassphraseApplication'))
35
->executeOne();
36
37
$view_policy = $app->getPolicy(PassphraseDefaultViewCapability::CAPABILITY);
38
$edit_policy = $app->getPolicy(PassphraseDefaultEditCapability::CAPABILITY);
39
40
return id(new PassphraseCredential())
41
->setName('')
42
->setUsername('')
43
->setDescription('')
44
->setIsDestroyed(0)
45
->setAuthorPHID($actor->getPHID())
46
->setViewPolicy($view_policy)
47
->setEditPolicy($edit_policy)
48
->setSpacePHID($actor->getDefaultSpacePHID());
49
}
50
51
public function getMonogram() {
52
return 'K'.$this->getID();
53
}
54
55
public function getURI() {
56
return '/'.$this->getMonogram();
57
}
58
59
protected function getConfiguration() {
60
return array(
61
self::CONFIG_AUX_PHID => true,
62
self::CONFIG_COLUMN_SCHEMA => array(
63
'name' => 'text255',
64
'credentialType' => 'text64',
65
'providesType' => 'text64',
66
'description' => 'text',
67
'username' => 'text255',
68
'secretID' => 'id?',
69
'isDestroyed' => 'bool',
70
'isLocked' => 'bool',
71
'allowConduit' => 'bool',
72
),
73
self::CONFIG_KEY_SCHEMA => array(
74
'key_secret' => array(
75
'columns' => array('secretID'),
76
'unique' => true,
77
),
78
'key_type' => array(
79
'columns' => array('credentialType'),
80
),
81
'key_provides' => array(
82
'columns' => array('providesType'),
83
),
84
),
85
) + parent::getConfiguration();
86
}
87
88
public function generatePHID() {
89
return PhabricatorPHID::generateNewPHID(
90
PassphraseCredentialPHIDType::TYPECONST);
91
}
92
93
public function attachSecret(PhutilOpaqueEnvelope $secret = null) {
94
$this->secret = $secret;
95
return $this;
96
}
97
98
public function getSecret() {
99
return $this->assertAttached($this->secret);
100
}
101
102
public function getCredentialTypeImplementation() {
103
$type = $this->getCredentialType();
104
return PassphraseCredentialType::getTypeByConstant($type);
105
}
106
107
public function attachImplementation(PassphraseCredentialType $impl) {
108
$this->implementation = $impl;
109
return $this;
110
}
111
112
public function getImplementation() {
113
return $this->assertAttached($this->implementation);
114
}
115
116
117
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
118
119
120
public function getApplicationTransactionEditor() {
121
return new PassphraseCredentialTransactionEditor();
122
}
123
124
public function getApplicationTransactionTemplate() {
125
return new PassphraseCredentialTransaction();
126
}
127
128
129
/* -( PhabricatorPolicyInterface )----------------------------------------- */
130
131
132
public function getCapabilities() {
133
return array(
134
PhabricatorPolicyCapability::CAN_VIEW,
135
PhabricatorPolicyCapability::CAN_EDIT,
136
);
137
}
138
139
public function getPolicy($capability) {
140
switch ($capability) {
141
case PhabricatorPolicyCapability::CAN_VIEW:
142
return $this->getViewPolicy();
143
case PhabricatorPolicyCapability::CAN_EDIT:
144
return $this->getEditPolicy();
145
}
146
}
147
148
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
149
return false;
150
}
151
152
153
/* -( PhabricatorSubscribableInterface )----------------------------------- */
154
155
156
public function isAutomaticallySubscribed($phid) {
157
return false;
158
}
159
160
161
/* -( PhabricatorDestructibleInterface )----------------------------------- */
162
163
public function destroyObjectPermanently(
164
PhabricatorDestructionEngine $engine) {
165
166
$this->openTransaction();
167
$secrets = id(new PassphraseSecret())->loadAllWhere(
168
'id = %d',
169
$this->getSecretID());
170
foreach ($secrets as $secret) {
171
$secret->delete();
172
}
173
$this->delete();
174
$this->saveTransaction();
175
}
176
177
178
/* -( PhabricatorSpacesInterface )----------------------------------------- */
179
180
181
public function getSpacePHID() {
182
return $this->spacePHID;
183
}
184
185
186
/* -( PhabricatorFulltextInterface )--------------------------------------- */
187
188
189
public function newFulltextEngine() {
190
return new PassphraseCredentialFulltextEngine();
191
}
192
193
194
/* -( PhabricatorFerretInterface )----------------------------------------- */
195
196
197
public function newFerretEngine() {
198
return new PassphraseCredentialFerretEngine();
199
}
200
201
202
}
203
204