Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/xaction/AlmanacBindingServiceTransaction.php
12256 views
1
<?php
2
3
final class AlmanacBindingServiceTransaction
4
extends AlmanacBindingTransactionType {
5
6
const TRANSACTIONTYPE = 'almanac:binding:service';
7
8
public function generateOldValue($object) {
9
return $object->getServicePHID();
10
}
11
12
public function applyInternalEffects($object, $value) {
13
$object->setServicePHID($value);
14
}
15
16
public function validateTransactions($object, array $xactions) {
17
$errors = array();
18
19
$service_phid = $object->getServicePHID();
20
if ($this->isEmptyTextTransaction($service_phid, $xactions)) {
21
$errors[] = $this->newRequiredError(
22
pht('Bindings must have a service.'));
23
}
24
25
foreach ($xactions as $xaction) {
26
if (!$this->isNewObject()) {
27
$errors[] = $this->newInvalidError(
28
pht(
29
'The service for a binding can not be changed once it has '.
30
'been created.'),
31
$xaction);
32
continue;
33
}
34
35
$service_phid = $xaction->getNewValue();
36
$services = id(new AlmanacServiceQuery())
37
->setViewer($this->getActor())
38
->withPHIDs(array($service_phid))
39
->execute();
40
if (!$services) {
41
$errors[] = $this->newInvalidError(
42
pht('You can not bind a nonexistent or restricted service.'),
43
$xaction);
44
continue;
45
}
46
47
$service = head($services);
48
$can_edit = PhabricatorPolicyFilter::hasCapability(
49
$this->getActor(),
50
$service,
51
PhabricatorPolicyCapability::CAN_EDIT);
52
if (!$can_edit) {
53
$errors[] = $this->newInvalidError(
54
pht(
55
'You can not bind a service which you do not have permission '.
56
'to edit.'));
57
continue;
58
}
59
}
60
61
return $errors;
62
}
63
64
}
65
66