mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
Lift most "InlineController" querying to the base class
Summary: Ref T13513. Move querying to "DiffInlineCommentQuery" classes and lift them into the base Controller. Test Plan: In Differential and Diffusion, created, edited, and submitted inline comments. Maniphest Tasks: T13513 Differential Revision: https://secure.phabricator.com/D21231
This commit is contained in:
parent
949b9163d0
commit
af5b94b234
3 changed files with 70 additions and 83 deletions
|
@ -3,6 +3,10 @@
|
|||
final class DifferentialInlineCommentEditController
|
||||
extends PhabricatorInlineCommentController {
|
||||
|
||||
protected function newInlineCommentQuery() {
|
||||
return new DifferentialDiffInlineCommentQuery();
|
||||
}
|
||||
|
||||
private function getRevisionID() {
|
||||
return $this->getRequest()->getURIData('id');
|
||||
}
|
||||
|
@ -58,44 +62,10 @@ final class DifferentialInlineCommentEditController
|
|||
->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) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$inline = $this->loadComment($id);
|
||||
$inline = $this->loadCommentByID($id);
|
||||
if (!$inline) {
|
||||
throw new Exception(pht('Unable to load inline "%d".', $id));
|
||||
}
|
||||
|
@ -144,7 +114,7 @@ final class DifferentialInlineCommentEditController
|
|||
return $inline;
|
||||
}
|
||||
|
||||
private function canEditInlineComment(
|
||||
protected function canEditInlineComment(
|
||||
PhabricatorUser $viewer,
|
||||
DifferentialInlineComment $inline) {
|
||||
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
final class DiffusionInlineCommentController
|
||||
extends PhabricatorInlineCommentController {
|
||||
|
||||
protected function newInlineCommentQuery() {
|
||||
return new DiffusionDiffInlineCommentQuery();
|
||||
}
|
||||
|
||||
private function getCommitPHID() {
|
||||
return $this->getRequest()->getURIData('phid');
|
||||
}
|
||||
|
@ -41,48 +45,10 @@ final class DiffusionInlineCommentController
|
|||
->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) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$inline = $this->loadComment($id);
|
||||
$inline = $this->loadCommentByID($id);
|
||||
if (!$inline) {
|
||||
throw new Exception(pht('Failed to load comment "%d".', $id));
|
||||
}
|
||||
|
@ -115,7 +81,7 @@ final class DiffusionInlineCommentController
|
|||
return $inline;
|
||||
}
|
||||
|
||||
private function canEditInlineComment(
|
||||
protected function canEditInlineComment(
|
||||
PhabricatorUser $viewer,
|
||||
PhabricatorAuditInlineComment $inline) {
|
||||
|
||||
|
|
|
@ -4,10 +4,8 @@ abstract class PhabricatorInlineCommentController
|
|||
extends PhabricatorController {
|
||||
|
||||
abstract protected function createComment();
|
||||
abstract protected function loadComment($id);
|
||||
abstract protected function loadCommentForEdit($id);
|
||||
abstract protected function newInlineCommentQuery();
|
||||
abstract protected function loadCommentForDone($id);
|
||||
abstract protected function loadCommentByPHID($phid);
|
||||
abstract protected function loadObjectOwnerPHID(
|
||||
PhabricatorInlineComment $inline);
|
||||
abstract protected function deleteComment(
|
||||
|
@ -172,7 +170,7 @@ abstract class PhabricatorInlineCommentController
|
|||
|
||||
$is_delete = ($op == 'delete' || $op == 'refdelete');
|
||||
|
||||
$inline = $this->loadCommentForEdit($this->getCommentID());
|
||||
$inline = $this->loadCommentByIDForEdit($this->getCommentID());
|
||||
|
||||
if ($is_delete) {
|
||||
$this->deleteComment($inline);
|
||||
|
@ -182,7 +180,7 @@ abstract class PhabricatorInlineCommentController
|
|||
|
||||
return $this->buildEmptyResponse();
|
||||
case 'edit':
|
||||
$inline = $this->loadCommentForEdit($this->getCommentID());
|
||||
$inline = $this->loadCommentByIDForEdit($this->getCommentID());
|
||||
$text = $this->getCommentText();
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
|
@ -228,7 +226,7 @@ abstract class PhabricatorInlineCommentController
|
|||
|
||||
return $this->newInlineResponse($inline, $view);
|
||||
case 'cancel':
|
||||
$inline = $this->loadCommentForEdit($this->getCommentID());
|
||||
$inline = $this->loadCommentByIDForEdit($this->getCommentID());
|
||||
|
||||
$inline->setIsEditing(false);
|
||||
|
||||
|
@ -251,7 +249,7 @@ abstract class PhabricatorInlineCommentController
|
|||
|
||||
return $this->buildEmptyResponse();
|
||||
case 'draft':
|
||||
$inline = $this->loadCommentForEdit($this->getCommentID());
|
||||
$inline = $this->loadCommentByIDForEdit($this->getCommentID());
|
||||
|
||||
$versioned_draft = PhabricatorVersionedDraft::loadOrCreateDraft(
|
||||
$inline->getPHID(),
|
||||
|
@ -442,5 +440,58 @@ abstract class PhabricatorInlineCommentController
|
|||
$viewer->getPHID());
|
||||
}
|
||||
|
||||
final protected function loadCommentByID($id) {
|
||||
$query = $this->newInlineCommentQuery()
|
||||
->withIDs(array($id));
|
||||
|
||||
return $this->loadCommentByQuery($query);
|
||||
}
|
||||
|
||||
final protected function loadCommentByPHID($phid) {
|
||||
$query = $this->newInlineCommentQuery()
|
||||
->withPHIDs(array($phid));
|
||||
|
||||
return $this->loadCommentByQuery($query);
|
||||
}
|
||||
|
||||
final protected function loadCommentByIDForEdit($id) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$query = $this->newInlineCommentQuery()
|
||||
->withIDs(array($id));
|
||||
|
||||
$inline = $this->loadCommentByQuery($query);
|
||||
|
||||
if (!$inline) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Unable to load inline "%s".',
|
||||
$id));
|
||||
}
|
||||
|
||||
if (!$this->canEditInlineComment($viewer, $inline)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Inline comment "%s" is not editable.',
|
||||
$id));
|
||||
}
|
||||
|
||||
return $inline;
|
||||
}
|
||||
|
||||
private function loadCommentByQuery(
|
||||
PhabricatorDiffInlineCommentQuery $query) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$inline = $query
|
||||
->setViewer($viewer)
|
||||
->executeOne();
|
||||
|
||||
if ($inline) {
|
||||
$inline = $inline->newInlineCommentObject();
|
||||
}
|
||||
|
||||
return $inline;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue