@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class HeraldWebhookURITransaction
4 extends HeraldWebhookTransactionType {
5
6 const TRANSACTIONTYPE = 'uri';
7 private $webhookURIMaxLength = 2048;
8
9 public function generateOldValue($object) {
10 return $object->getWebhookURI();
11 }
12
13 public function applyInternalEffects($object, $value) {
14 $object->setWebhookURI($value);
15 }
16
17 public function getTitle() {
18 return pht(
19 '%s changed the URI for this webhook from %s to %s.',
20 $this->renderAuthor(),
21 $this->renderOldValue(),
22 $this->renderNewValue());
23 }
24
25 public function getTitleForFeed() {
26 return pht(
27 '%s changed the URI for %s from %s to %s.',
28 $this->renderAuthor(),
29 $this->renderObject(),
30 $this->renderOldValue(),
31 $this->renderNewValue());
32 }
33
34 public function validateTransactions($object, array $xactions) {
35 $errors = array();
36 $viewer = $this->getActor();
37
38 if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
39 $errors[] = $this->newRequiredError(
40 pht('Webhooks must have a URI.'));
41 return $errors;
42 }
43
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 > $this->webhookURIMaxLength) {
50 $errors[] = $this->newInvalidError(
51 pht(
52 'Webhook URIs can be no longer than %s characters.',
53 new PhutilNumber($this->webhookURIMaxLength)),
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}