1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-04 04:32:43 +01:00
phorge-phorge/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentRawController.php
lkassianik 7a6f4ab75a T6594, Logged out users should see "View Raw" in dropdown of timeline items
Summary: Fixes T6594, Logged out users should be able to "View Raw" comments in public objects.

Test Plan: Log out, open maniphest task with comments, open dropdown associated with comment, click "View Raw", should be able to see raw comment.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T6594

Differential Revision: https://secure.phabricator.com/D11295
2015-01-09 06:47:16 -08:00

92 lines
2.6 KiB
PHP

<?php
final class PhabricatorApplicationTransactionCommentRawController
extends PhabricatorApplicationTransactionController {
private $phid;
public function willProcessRequest(array $data) {
$this->phid = $data['phid'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$xaction = id(new PhabricatorObjectQuery())
->withPHIDs(array($this->phid))
->setViewer($user)
->executeOne();
if (!$xaction) {
return new Aphront404Response();
}
if (!$xaction->getComment()) {
// You can't view a raw comment if there is no comment.
return new Aphront404Response();
}
if ($xaction->getComment()->getIsRemoved()) {
// You can't view a raw comment if the comment is deleted.
return new Aphront400Response();
}
$obj_phid = $xaction->getObjectPHID();
$obj_handle = id(new PhabricatorHandleQuery())
->setViewer($user)
->withPHIDs(array($obj_phid))
->executeOne();
$title = pht('Raw Comment');
$body = $xaction->getComment()->getContent();
$addendum = null;
if ($request->getExists('email')) {
$content_source = $xaction->getContentSource();
$source_email = PhabricatorContentSource::SOURCE_EMAIL;
if ($content_source->getSource() == $source_email) {
$source_id = $content_source->getParam('id');
if ($source_id) {
$message = id(new PhabricatorMetaMTAReceivedMail())->loadOneWhere(
'id = %d',
$source_id);
if ($message) {
$title = pht('Email Body Text');
$body = $message->getRawTextBody();
$details_text = pht(
'For full details, run `/bin/mail show-outbound --id %d`',
$source_id);
$addendum = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($details_text),
'default',
$user);
}
}
}
}
$dialog = id(new AphrontDialogView())
->setUser($user)
->addCancelButton($obj_handle->getURI())
->setTitle($title);
$dialog
->addHiddenInput('anchor', $request->getStr('anchor'))
->appendChild(
id(new PHUIFormLayoutView())
->setFullWidth(true)
->appendChild(
id(new AphrontFormTextAreaControl())
->setReadOnly(true)
->setValue($body)));
if ($addendum) {
$dialog->appendParagraph($addendum);
}
return id(new AphrontDialogResponse())->setDialog($dialog);
}
public function shouldAllowPublic() {
return true;
}
}