Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/herald/xaction/HeraldWebhookURITransaction.php
12256 views
1
<?php
2
3
final class HeraldWebhookURITransaction
4
extends HeraldWebhookTransactionType {
5
6
const TRANSACTIONTYPE = 'uri';
7
8
public function generateOldValue($object) {
9
return $object->getWebhookURI();
10
}
11
12
public function applyInternalEffects($object, $value) {
13
$object->setWebhookURI($value);
14
}
15
16
public function getTitle() {
17
return pht(
18
'%s changed the URI for this webhook from %s to %s.',
19
$this->renderAuthor(),
20
$this->renderOldValue(),
21
$this->renderNewValue());
22
}
23
24
public function getTitleForFeed() {
25
return pht(
26
'%s changed the URI for %s from %s to %s.',
27
$this->renderAuthor(),
28
$this->renderObject(),
29
$this->renderOldValue(),
30
$this->renderNewValue());
31
}
32
33
public function validateTransactions($object, array $xactions) {
34
$errors = array();
35
$viewer = $this->getActor();
36
37
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
38
$errors[] = $this->newRequiredError(
39
pht('Webhooks must have a URI.'));
40
return $errors;
41
}
42
43
$max_length = $object->getColumnMaximumByteLength('webhookURI');
44
foreach ($xactions as $xaction) {
45
$old_value = $this->generateOldValue($object);
46
$new_value = $xaction->getNewValue();
47
48
$new_length = strlen($new_value);
49
if ($new_length > $max_length) {
50
$errors[] = $this->newInvalidError(
51
pht(
52
'Webhook URIs can be no longer than %s characters.',
53
new PhutilNumber($max_length)),
54
$xaction);
55
}
56
57
try {
58
PhabricatorEnv::requireValidRemoteURIForFetch(
59
$new_value,
60
array(
61
'http',
62
'https',
63
));
64
} catch (Exception $ex) {
65
$errors[] = $this->newInvalidError(
66
$ex->getMessage(),
67
$xaction);
68
}
69
}
70
71
return $errors;
72
}
73
74
}
75
76