Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldCredential.php
12242 views
1
<?php
2
3
final class PhabricatorStandardCustomFieldCredential
4
extends PhabricatorStandardCustomField {
5
6
public function getFieldType() {
7
return 'credential';
8
}
9
10
public function buildFieldIndexes() {
11
$indexes = array();
12
13
$value = $this->getFieldValue();
14
if (strlen($value)) {
15
$indexes[] = $this->newStringIndex($value);
16
}
17
18
return $indexes;
19
}
20
21
public function renderEditControl(array $handles) {
22
$provides_type = $this->getFieldConfigValue('credential.provides');
23
$credential_type = $this->getFieldConfigValue('credential.type');
24
25
$all_types = PassphraseCredentialType::getAllProvidesTypes();
26
if (!in_array($provides_type, $all_types)) {
27
$provides_type = PassphrasePasswordCredentialType::PROVIDES_TYPE;
28
}
29
30
$credentials = id(new PassphraseCredentialQuery())
31
->setViewer($this->getViewer())
32
->withIsDestroyed(false)
33
->withProvidesTypes(array($provides_type))
34
->execute();
35
36
return id(new PassphraseCredentialControl())
37
->setViewer($this->getViewer())
38
->setLabel($this->getFieldName())
39
->setName($this->getFieldKey())
40
->setCaption($this->getCaption())
41
->setAllowNull(!$this->getRequired())
42
->setCredentialType($credential_type)
43
->setValue($this->getFieldValue())
44
->setError($this->getFieldError())
45
->setOptions($credentials);
46
}
47
48
public function getRequiredHandlePHIDsForPropertyView() {
49
$value = $this->getFieldValue();
50
if ($value) {
51
return array($value);
52
}
53
return array();
54
}
55
56
public function renderPropertyViewValue(array $handles) {
57
$value = $this->getFieldValue();
58
if ($value) {
59
return $handles[$value]->renderLink();
60
}
61
return null;
62
}
63
64
public function validateApplicationTransactions(
65
PhabricatorApplicationTransactionEditor $editor,
66
$type,
67
array $xactions) {
68
69
$errors = parent::validateApplicationTransactions(
70
$editor,
71
$type,
72
$xactions);
73
74
$ok = PassphraseCredentialControl::validateTransactions(
75
$this->getViewer(),
76
$xactions);
77
78
if (!$ok) {
79
foreach ($xactions as $xaction) {
80
$errors[] = new PhabricatorApplicationTransactionValidationError(
81
$type,
82
pht('Invalid'),
83
pht(
84
'The selected credential does not exist, or you do not have '.
85
'permission to use it.'),
86
$xaction);
87
$this->setFieldError(pht('Invalid'));
88
}
89
}
90
91
return $errors;
92
}
93
94
public function getApplicationTransactionRequiredHandlePHIDs(
95
PhabricatorApplicationTransaction $xaction) {
96
$phids = array();
97
$old = $xaction->getOldValue();
98
$new = $xaction->getNewValue();
99
if ($old) {
100
$phids[] = $old;
101
}
102
if ($new) {
103
$phids[] = $new;
104
}
105
return $phids;
106
}
107
108
109
public function getApplicationTransactionTitle(
110
PhabricatorApplicationTransaction $xaction) {
111
$author_phid = $xaction->getAuthorPHID();
112
113
$old = $xaction->getOldValue();
114
$new = $xaction->getNewValue();
115
116
if ($old && !$new) {
117
return pht(
118
'%s removed %s as %s.',
119
$xaction->renderHandleLink($author_phid),
120
$xaction->renderHandleLink($old),
121
$this->getFieldName());
122
} else if ($new && !$old) {
123
return pht(
124
'%s set %s to %s.',
125
$xaction->renderHandleLink($author_phid),
126
$this->getFieldName(),
127
$xaction->renderHandleLink($new));
128
} else {
129
return pht(
130
'%s changed %s from %s to %s.',
131
$xaction->renderHandleLink($author_phid),
132
$this->getFieldName(),
133
$xaction->renderHandleLink($old),
134
$xaction->renderHandleLink($new));
135
}
136
}
137
138
139
protected function getHTTPParameterType() {
140
return new AphrontPHIDHTTPParameterType();
141
}
142
143
protected function newConduitSearchParameterType() {
144
return new ConduitPHIDParameterType();
145
}
146
147
protected function newConduitEditParameterType() {
148
return new ConduitPHIDParameterType();
149
}
150
151
}
152
153