Differential D21231 Diff 50567 src/applications/diffusion/controller/DiffusionInlineCommentController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionInlineCommentController.php
<?php | <?php | ||||
final class DiffusionInlineCommentController | final class DiffusionInlineCommentController | ||||
extends PhabricatorInlineCommentController { | extends PhabricatorInlineCommentController { | ||||
protected function newInlineCommentQuery() { | |||||
return new DiffusionDiffInlineCommentQuery(); | |||||
} | |||||
private function getCommitPHID() { | private function getCommitPHID() { | ||||
return $this->getRequest()->getURIData('phid'); | return $this->getRequest()->getURIData('phid'); | ||||
} | } | ||||
private function loadCommit() { | private function loadCommit() { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$commit_phid = $this->getCommitPHID(); | $commit_phid = $this->getCommitPHID(); | ||||
Show All 22 Lines | if (!$path) { | ||||
throw new Exception(pht('Invalid path ID!')); | throw new Exception(pht('Invalid path ID!')); | ||||
} | } | ||||
return id(new PhabricatorAuditInlineComment()) | return id(new PhabricatorAuditInlineComment()) | ||||
->setCommitPHID($commit->getPHID()) | ->setCommitPHID($commit->getPHID()) | ||||
->setPathID($path_id); | ->setPathID($path_id); | ||||
} | } | ||||
protected function loadComment($id) { | |||||
$viewer = $this->getViewer(); | |||||
$inline = id(new DiffusionDiffInlineCommentQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($id)) | |||||
->executeOne(); | |||||
if ($inline) { | |||||
$inline = $inline->newInlineCommentObject(); | |||||
} | |||||
return $inline; | |||||
} | |||||
protected function loadCommentByPHID($phid) { | |||||
$viewer = $this->getViewer(); | |||||
$inline = id(new DiffusionDiffInlineCommentQuery()) | |||||
->setViewer($viewer) | |||||
->withPHIDs(array($phid)) | |||||
->executeOne(); | |||||
if ($inline) { | |||||
$inline = $inline->newInlineCommentObject(); | |||||
} | |||||
return $inline; | |||||
} | |||||
protected function loadCommentForEdit($id) { | |||||
$viewer = $this->getViewer(); | |||||
$inline = $this->loadComment($id); | |||||
if (!$this->canEditInlineComment($viewer, $inline)) { | |||||
throw new Exception(pht('That comment is not editable!')); | |||||
} | |||||
return $inline; | |||||
} | |||||
protected function loadCommentForDone($id) { | protected function loadCommentForDone($id) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$inline = $this->loadComment($id); | $inline = $this->loadCommentByID($id); | ||||
if (!$inline) { | if (!$inline) { | ||||
throw new Exception(pht('Failed to load comment "%d".', $id)); | throw new Exception(pht('Failed to load comment "%d".', $id)); | ||||
} | } | ||||
$commit = id(new DiffusionCommitQuery()) | $commit = id(new DiffusionCommitQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs(array($inline->getCommitPHID())) | ->withPHIDs(array($inline->getCommitPHID())) | ||||
->executeOne(); | ->executeOne(); | ||||
Show All 16 Lines | if ($viewer_is_owner) { | ||||
pht( | pht( | ||||
'You can not mark this comment as complete: you did not author '. | 'You can not mark this comment as complete: you did not author '. | ||||
'the commit and the comment is not a draft you wrote.')); | 'the commit and the comment is not a draft you wrote.')); | ||||
} | } | ||||
return $inline; | return $inline; | ||||
} | } | ||||
private function canEditInlineComment( | protected function canEditInlineComment( | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
PhabricatorAuditInlineComment $inline) { | PhabricatorAuditInlineComment $inline) { | ||||
// Only the author may edit a comment. | // Only the author may edit a comment. | ||||
if ($inline->getAuthorPHID() != $viewer->getPHID()) { | if ($inline->getAuthorPHID() != $viewer->getPHID()) { | ||||
return false; | return false; | ||||
} | } | ||||
Show All 33 Lines |