Differential D21231 Diff 50567 src/applications/differential/controller/DifferentialInlineCommentEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/controller/DifferentialInlineCommentEditController.php
<?php | <?php | ||||
final class DifferentialInlineCommentEditController | final class DifferentialInlineCommentEditController | ||||
extends PhabricatorInlineCommentController { | extends PhabricatorInlineCommentController { | ||||
protected function newInlineCommentQuery() { | |||||
return new DifferentialDiffInlineCommentQuery(); | |||||
} | |||||
private function getRevisionID() { | private function getRevisionID() { | ||||
return $this->getRequest()->getURIData('id'); | return $this->getRequest()->getURIData('id'); | ||||
} | } | ||||
private function loadRevision() { | private function loadRevision() { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$revision_id = $this->getRevisionID(); | $revision_id = $this->getRevisionID(); | ||||
Show All 39 Lines | if ($diff->getRevisionID() != $revision->getID()) { | ||||
$revision->getID())); | $revision->getID())); | ||||
} | } | ||||
return id(new DifferentialInlineComment()) | return id(new DifferentialInlineComment()) | ||||
->setRevision($revision) | ->setRevision($revision) | ||||
->setChangesetID($changeset_id); | ->setChangesetID($changeset_id); | ||||
} | } | ||||
protected function loadComment($id) { | |||||
return id(new DifferentialInlineCommentQuery()) | |||||
->setViewer($this->getViewer()) | |||||
->withIDs(array($id)) | |||||
->withDeletedDrafts(true) | |||||
->needHidden(true) | |||||
->executeOne(); | |||||
} | |||||
protected function loadCommentByPHID($phid) { | |||||
return id(new DifferentialInlineCommentQuery()) | |||||
->setViewer($this->getViewer()) | |||||
->withPHIDs(array($phid)) | |||||
->withDeletedDrafts(true) | |||||
->needHidden(true) | |||||
->executeOne(); | |||||
} | |||||
protected function loadCommentForEdit($id) { | |||||
$viewer = $this->getViewer(); | |||||
$inline = $this->loadComment($id); | |||||
if (!$inline) { | |||||
throw new Exception( | |||||
pht('Unable to load inline "%s".', $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('Unable to load inline "%d".', $id)); | throw new Exception(pht('Unable to load inline "%d".', $id)); | ||||
} | } | ||||
$changeset = id(new DifferentialChangesetQuery()) | $changeset = id(new DifferentialChangesetQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($inline->getChangesetID())) | ->withIDs(array($inline->getChangesetID())) | ||||
->executeOne(); | ->executeOne(); | ||||
Show All 32 Lines | if ($is_owner) { | ||||
pht( | pht( | ||||
'You are not the revision owner, and this is not a draft comment '. | 'You are not the revision owner, and this is not a draft comment '. | ||||
'you authored.')); | 'you authored.')); | ||||
} | } | ||||
return $inline; | return $inline; | ||||
} | } | ||||
private function canEditInlineComment( | protected function canEditInlineComment( | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
DifferentialInlineComment $inline) { | DifferentialInlineComment $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 20 Lines • Show All 86 Lines • Show Last 20 Lines |