Path: blob/master/src/applications/almanac/xaction/AlmanacBindingServiceTransaction.php
12256 views
<?php12final class AlmanacBindingServiceTransaction3extends AlmanacBindingTransactionType {45const TRANSACTIONTYPE = 'almanac:binding:service';67public function generateOldValue($object) {8return $object->getServicePHID();9}1011public function applyInternalEffects($object, $value) {12$object->setServicePHID($value);13}1415public function validateTransactions($object, array $xactions) {16$errors = array();1718$service_phid = $object->getServicePHID();19if ($this->isEmptyTextTransaction($service_phid, $xactions)) {20$errors[] = $this->newRequiredError(21pht('Bindings must have a service.'));22}2324foreach ($xactions as $xaction) {25if (!$this->isNewObject()) {26$errors[] = $this->newInvalidError(27pht(28'The service for a binding can not be changed once it has '.29'been created.'),30$xaction);31continue;32}3334$service_phid = $xaction->getNewValue();35$services = id(new AlmanacServiceQuery())36->setViewer($this->getActor())37->withPHIDs(array($service_phid))38->execute();39if (!$services) {40$errors[] = $this->newInvalidError(41pht('You can not bind a nonexistent or restricted service.'),42$xaction);43continue;44}4546$service = head($services);47$can_edit = PhabricatorPolicyFilter::hasCapability(48$this->getActor(),49$service,50PhabricatorPolicyCapability::CAN_EDIT);51if (!$can_edit) {52$errors[] = $this->newInvalidError(53pht(54'You can not bind a service which you do not have permission '.55'to edit.'));56continue;57}58}5960return $errors;61}6263}646566