2014-05-05 10:55:32 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorApplicationTransactionCommentRemoveController
|
|
|
|
extends PhabricatorApplicationTransactionController {
|
|
|
|
|
2015-12-01 19:46:57 -08:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$phid = $request->getURIData('phid');
|
2014-05-05 10:55:32 -07:00
|
|
|
|
|
|
|
$xaction = id(new PhabricatorObjectQuery())
|
2015-12-01 19:46:57 -08:00
|
|
|
->withPHIDs(array($phid))
|
2014-05-05 10:55:32 -07:00
|
|
|
->setViewer($viewer)
|
|
|
|
->executeOne();
|
|
|
|
if (!$xaction) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$xaction->getComment()) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($xaction->getComment()->getIsRemoved()) {
|
|
|
|
// You can't remove an already-removed comment.
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj_phid = $xaction->getObjectPHID();
|
|
|
|
$obj_handle = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($obj_phid))
|
|
|
|
->executeOne();
|
|
|
|
|
2019-03-28 15:32:23 -07:00
|
|
|
$done_uri = $obj_handle->getURI();
|
|
|
|
|
2019-05-23 10:55:55 -07:00
|
|
|
// We allow administrative removal of comments even if an object is locked,
|
|
|
|
// so you can lock a flamewar and then go clean it up. Locked threads may
|
|
|
|
// not otherwise be edited, and non-administrators can not remove comments
|
|
|
|
// from locked threads.
|
|
|
|
|
|
|
|
$object = $xaction->getObject();
|
2019-07-11 15:47:53 -07:00
|
|
|
$can_interact = PhabricatorPolicyFilter::canInteract(
|
2019-05-23 10:55:55 -07:00
|
|
|
$viewer,
|
2019-07-11 15:47:53 -07:00
|
|
|
$object);
|
2019-05-23 10:55:55 -07:00
|
|
|
if (!$can_interact && !$viewer->getIsAdmin()) {
|
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Conversation Locked'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht(
|
|
|
|
'You can not remove this comment because the conversation is '.
|
|
|
|
'locked.'))
|
|
|
|
->addCancelButton($done_uri);
|
|
|
|
}
|
|
|
|
|
2019-03-28 15:32:23 -07:00
|
|
|
if ($request->isFormOrHisecPost()) {
|
2014-05-05 10:55:32 -07:00
|
|
|
$comment = $xaction->getApplicationTransactionCommentObject()
|
|
|
|
->setContent('')
|
|
|
|
->setIsRemoved(true);
|
|
|
|
|
|
|
|
$editor = id(new PhabricatorApplicationTransactionCommentEditor())
|
|
|
|
->setActor($viewer)
|
2019-03-28 15:32:23 -07:00
|
|
|
->setRequest($request)
|
|
|
|
->setCancelURI($done_uri)
|
2014-05-05 10:55:32 -07:00
|
|
|
->setContentSource(PhabricatorContentSource::newFromRequest($request))
|
|
|
|
->applyEdit($xaction, $comment);
|
|
|
|
|
|
|
|
if ($request->isAjax()) {
|
2014-05-05 10:57:23 -07:00
|
|
|
return id(new AphrontAjaxResponse())->setContent(array());
|
2014-05-05 10:55:32 -07:00
|
|
|
} else {
|
2019-03-28 15:32:23 -07:00
|
|
|
return id(new AphrontReloadResponse())->setURI($done_uri);
|
2014-05-05 10:55:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$dialog = $this->newDialog()
|
|
|
|
->setTitle(pht('Remove Comment'));
|
|
|
|
|
|
|
|
$dialog
|
|
|
|
->appendParagraph(
|
|
|
|
pht(
|
|
|
|
"Removing a comment prevents anyone (including you) from reading ".
|
|
|
|
"it. Removing a comment also hides the comment's edit history ".
|
|
|
|
"and prevents it from being edited."))
|
|
|
|
->appendParagraph(
|
|
|
|
pht('Really remove this comment?'));
|
|
|
|
|
|
|
|
$dialog
|
|
|
|
->addSubmitButton(pht('Remove Comment'))
|
2019-03-28 15:32:23 -07:00
|
|
|
->addCancelButton($done_uri);
|
2014-05-05 10:55:32 -07:00
|
|
|
|
|
|
|
return $dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|