@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 PhabricatorApplicationTransactionCommentEditController
4 extends PhabricatorApplicationTransactionController {
5
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
8
9 $xaction = id(new PhabricatorObjectQuery())
10 ->setViewer($viewer)
11 ->withPHIDs(array($request->getURIData('phid')))
12 ->executeOne();
13 if (!$xaction) {
14 return new Aphront404Response();
15 }
16
17 if (!$xaction->getComment()) {
18 // You can't currently edit a transaction which doesn't have a comment.
19 // Some day you may be able to edit the visibility.
20 return new Aphront404Response();
21 }
22
23 if ($xaction->getComment()->getIsRemoved()) {
24 // You can't edit history of a transaction with a removed comment.
25 return new Aphront400Response();
26 }
27
28 $phid = $xaction->getObjectPHID();
29 $handles = $viewer->loadHandles(array($phid));
30 $obj_handle = $handles[$phid];
31
32 $done_uri = $obj_handle->getURI();
33
34 // If an object is locked, you can't edit comments on it. Two reasons to
35 // lock threads are to calm contentious issues and to freeze state for
36 // auditing, and editing comments serves neither goal.
37
38 $object = $xaction->getObject();
39 $can_interact = PhabricatorPolicyFilter::canInteract(
40 $viewer,
41 $object);
42 if (!$can_interact) {
43 return $this->newDialog()
44 ->setTitle(pht('Conversation Locked'))
45 ->appendParagraph(
46 pht(
47 'You can not edit this comment because the conversation is '.
48 'locked.'))
49 ->addCancelButton($done_uri);
50 }
51
52 if ($request->isFormOrHisecPost()) {
53 $text = $request->getStr('text');
54
55 $comment = $xaction->getApplicationTransactionCommentObject();
56 $comment->setContent($text);
57 if (!strlen($text)) {
58 $comment->setIsDeleted(true);
59 }
60
61 $editor = id(new PhabricatorApplicationTransactionCommentEditor())
62 ->setActor($viewer)
63 ->setContentSource(PhabricatorContentSource::newFromRequest($request))
64 ->setRequest($request)
65 ->setCancelURI($done_uri)
66 ->applyEdit($xaction, $comment);
67
68 if ($request->isAjax()) {
69 return id(new AphrontAjaxResponse())->setContent(array());
70 } else {
71 return id(new AphrontReloadResponse())->setURI($done_uri);
72 }
73 }
74
75 $errors = array();
76 if ($xaction->getIsMFATransaction()) {
77 $message = pht(
78 'This comment was signed with MFA, so you will be required to '.
79 'provide MFA credentials to make changes.');
80
81 $errors[] = id(new PHUIInfoView())
82 ->setSeverity(PHUIInfoView::SEVERITY_MFA)
83 ->setErrors(array($message));
84 }
85
86 $form = id(new AphrontFormView())
87 ->setUser($viewer)
88 ->setFullWidth(true)
89 ->appendControl(
90 id(new PhabricatorRemarkupControl())
91 ->setName('text')
92 ->setValue($xaction->getComment()->getContent()));
93
94 return $this->newDialog()
95 ->setTitle(pht('Edit Comment'))
96 ->appendChild($errors)
97 ->appendForm($form)
98 ->addSubmitButton(pht('Save Changes'))
99 ->addCancelButton($done_uri);
100 }
101
102}