Touch up PHP/JS interactions for inline comments
Summary: Ref T1460. Overall: - Pass `objectOwnerPHID` consistently. - Pass viewer consistently. - Set the correct draft state for checkboxes on the client. Test Plan: - Made inline comments in Differential. - Made inline comments in Diffusion. Reviewers: chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T1460 Differential Revision: https://secure.phabricator.com/D12186
This commit is contained in:
@@ -3,28 +3,31 @@
|
||||
final class DifferentialInlineCommentEditController
|
||||
extends PhabricatorInlineCommentController {
|
||||
|
||||
private $revisionID;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->revisionID = $data['id'];
|
||||
private function getRevisionID() {
|
||||
return $this->getRequest()->getURIData('id');
|
||||
}
|
||||
|
||||
protected function createComment() {
|
||||
private function loadRevision() {
|
||||
$viewer = $this->getViewer();
|
||||
$revision_id = $this->getRevisionID();
|
||||
|
||||
// Verify revision and changeset correspond to actual objects.
|
||||
$revision_id = $this->revisionID;
|
||||
$changeset_id = $this->getChangesetID();
|
||||
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
$revision = id(new DifferentialRevisionQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($revision_id))
|
||||
->executeOne();
|
||||
|
||||
if (!$revision) {
|
||||
throw new Exception('Invalid revision ID!');
|
||||
if (!$revision) {
|
||||
throw new Exception(pht('Invalid revision ID "%s".', $revision_id));
|
||||
}
|
||||
|
||||
return $revision;
|
||||
}
|
||||
|
||||
protected function createComment() {
|
||||
// Verify revision and changeset correspond to actual objects.
|
||||
$changeset_id = $this->getChangesetID();
|
||||
|
||||
$revision = $this->loadRevision();
|
||||
|
||||
if (!id(new DifferentialChangeset())->load($changeset_id)) {
|
||||
throw new Exception('Invalid changeset ID!');
|
||||
}
|
||||
@@ -113,7 +116,7 @@ final class DifferentialInlineCommentEditController
|
||||
}
|
||||
|
||||
// Inline must be attached to the active revision.
|
||||
if ($inline->getRevisionID() != $this->revisionID) {
|
||||
if ($inline->getRevisionID() != $this->getRevisionID()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -139,4 +142,10 @@ final class DifferentialInlineCommentEditController
|
||||
$inline->getPHID());
|
||||
$inline->saveTransaction();
|
||||
}
|
||||
|
||||
protected function loadObjectOwnerPHID(
|
||||
PhabricatorInlineCommentInterface $inline) {
|
||||
return $this->loadRevision()->getAuthorPHID();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,20 +3,30 @@
|
||||
final class DifferentialInlineCommentPreviewController
|
||||
extends PhabricatorInlineCommentPreviewController {
|
||||
|
||||
private $revisionID;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->revisionID = $data['id'];
|
||||
}
|
||||
|
||||
protected function loadInlineComments() {
|
||||
$user = $this->getRequest()->getUser();
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$inlines = id(new DifferentialInlineCommentQuery())
|
||||
->withDraftComments($user->getPHID(), $this->revisionID)
|
||||
return id(new DifferentialInlineCommentQuery())
|
||||
->withDraftComments($viewer->getPHID(), $this->getRevisionID())
|
||||
->execute();
|
||||
|
||||
return $inlines;
|
||||
}
|
||||
|
||||
protected function loadObjectOwnerPHID() {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$revision = id(new DifferentialRevisionQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($this->getRevisionID()))
|
||||
->executeOne();
|
||||
if (!$revision) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $revision->getAuthorPHID();
|
||||
}
|
||||
|
||||
|
||||
private function getRevisionID() {
|
||||
return $this->getRequest()->getURIData('id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,6 +459,7 @@ abstract class DifferentialChangesetHTMLRenderer
|
||||
$allow_done = !$comment->isDraft() && $this->getCanMarkDone();
|
||||
|
||||
return id(new PHUIDiffInlineCommentDetailView())
|
||||
->setUser($user)
|
||||
->setInlineComment($comment)
|
||||
->setIsOnRight($on_right)
|
||||
->setHandles($this->getHandles())
|
||||
|
||||
@@ -845,7 +845,11 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
||||
|
||||
$rows = array();
|
||||
foreach ($inlines as $inline) {
|
||||
|
||||
// TODO: This should use modern scaffolding code.
|
||||
|
||||
$inline_view = id(new PHUIDiffInlineCommentDetailView())
|
||||
->setUser($this->getViewer())
|
||||
->setMarkupEngine($engine)
|
||||
->setInlineComment($inline)
|
||||
->render();
|
||||
|
||||
@@ -3,39 +3,41 @@
|
||||
final class DiffusionInlineCommentController
|
||||
extends PhabricatorInlineCommentController {
|
||||
|
||||
private $commitPHID;
|
||||
private function getCommitPHID() {
|
||||
return $this->getRequest()->getURIData('phid');
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->commitPHID = $data['phid'];
|
||||
private function loadCommit() {
|
||||
$viewer = $this->getViewer();
|
||||
$commit_phid = $this->getCommitPHID();
|
||||
|
||||
$commit = id(new DiffusionCommitQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($commit_phid))
|
||||
->executeOne();
|
||||
if (!$commit) {
|
||||
throw new Exception(pht('Invalid commit PHID "%s"!', $commit_phid));
|
||||
}
|
||||
|
||||
return $commit;
|
||||
}
|
||||
|
||||
protected function createComment() {
|
||||
|
||||
// Verify commit and path correspond to actual objects.
|
||||
$commit_phid = $this->commitPHID;
|
||||
$path_id = $this->getChangesetID();
|
||||
|
||||
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
|
||||
'phid = %s',
|
||||
$commit_phid);
|
||||
if (!$commit) {
|
||||
throw new Exception('Invalid commit ID!');
|
||||
}
|
||||
$commit = $this->loadCommit();
|
||||
|
||||
// TODO: Write a real PathQuery object?
|
||||
|
||||
$path_id = $this->getChangesetID();
|
||||
$path = queryfx_one(
|
||||
id(new PhabricatorRepository())->establishConnection('r'),
|
||||
'SELECT path FROM %T WHERE id = %d',
|
||||
PhabricatorRepository::TABLE_PATH,
|
||||
$path_id);
|
||||
|
||||
if (!$path) {
|
||||
throw new Exception('Invalid path ID!');
|
||||
}
|
||||
|
||||
return id(new PhabricatorAuditInlineComment())
|
||||
->setCommitPHID($commit_phid)
|
||||
->setCommitPHID($commit->getPHID())
|
||||
->setPathID($path_id);
|
||||
}
|
||||
|
||||
@@ -98,7 +100,7 @@ final class DiffusionInlineCommentController
|
||||
}
|
||||
|
||||
// Inline must be attached to the active revision.
|
||||
if ($inline->getCommitPHID() != $this->commitPHID) {
|
||||
if ($inline->getCommitPHID() != $this->getCommitPHID()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -113,4 +115,10 @@ final class DiffusionInlineCommentController
|
||||
return $inline->save();
|
||||
}
|
||||
|
||||
protected function loadObjectOwnerPHID(
|
||||
PhabricatorInlineCommentInterface $inline) {
|
||||
return $this->loadCommit()->getAuthorPHID();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,19 +3,30 @@
|
||||
final class DiffusionInlineCommentPreviewController
|
||||
extends PhabricatorInlineCommentPreviewController {
|
||||
|
||||
private $commitPHID;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->commitPHID = $data['phid'];
|
||||
}
|
||||
|
||||
protected function loadInlineComments() {
|
||||
$user = $this->getRequest()->getUser();
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$inlines = PhabricatorAuditInlineComment::loadDraftComments(
|
||||
$user,
|
||||
$this->commitPHID);
|
||||
|
||||
return $inlines;
|
||||
return PhabricatorAuditInlineComment::loadDraftComments(
|
||||
$viewer,
|
||||
$this->getCommitPHID());
|
||||
}
|
||||
|
||||
protected function loadObjectOwnerPHID() {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$commit = id(new DiffusionCommitQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($this->getCommitPHID()))
|
||||
->executeOne();
|
||||
if (!$commit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $commit->getAuthorPHID();
|
||||
}
|
||||
|
||||
private function getCommitPHID() {
|
||||
return $this->getRequest()->getURIData('phid');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ abstract class PhabricatorInlineCommentController
|
||||
abstract protected function loadCommentForEdit($id);
|
||||
abstract protected function loadCommentForDone($id);
|
||||
abstract protected function loadCommentByPHID($phid);
|
||||
abstract protected function loadObjectOwnerPHID(
|
||||
PhabricatorInlineCommentInterface $inline);
|
||||
abstract protected function deleteComment(
|
||||
PhabricatorInlineCommentInterface $inline);
|
||||
abstract protected function saveComment(
|
||||
@@ -88,6 +90,7 @@ abstract class PhabricatorInlineCommentController
|
||||
}
|
||||
$inline = $this->loadCommentForDone($this->getCommentID());
|
||||
|
||||
$is_draft_state = false;
|
||||
switch ($inline->getFixedState()) {
|
||||
case PhabricatorInlineCommentInterface::STATE_DRAFT:
|
||||
$next_state = PhabricatorInlineCommentInterface::STATE_UNDONE;
|
||||
@@ -97,16 +100,22 @@ abstract class PhabricatorInlineCommentController
|
||||
break;
|
||||
case PhabricatorInlineCommentInterface::STATE_DONE:
|
||||
$next_state = PhabricatorInlineCommentInterface::STATE_UNDRAFT;
|
||||
$is_draft_state = true;
|
||||
break;
|
||||
default:
|
||||
case PhabricatorInlineCommentInterface::STATE_UNDONE:
|
||||
$next_state = PhabricatorInlineCommentInterface::STATE_DRAFT;
|
||||
$is_draft_state = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$inline->setFixedState($next_state)->save();
|
||||
|
||||
return $this->buildEmptyResponse();
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent(
|
||||
array(
|
||||
'draftState' => $is_draft_state,
|
||||
));
|
||||
case 'delete':
|
||||
case 'undelete':
|
||||
case 'refdelete':
|
||||
@@ -306,12 +315,10 @@ abstract class PhabricatorInlineCommentController
|
||||
$phids = array($user->getPHID());
|
||||
|
||||
$handles = $this->loadViewerHandles($phids);
|
||||
|
||||
// TODO: This is not correct, but figuring it out is a little bit
|
||||
// involved and it only affects drafts.
|
||||
$object_owner_phid = null;
|
||||
$object_owner_phid = $this->loadObjectOwnerPHID($inline);
|
||||
|
||||
$view = id(new PHUIDiffInlineCommentDetailView())
|
||||
->setUser($user)
|
||||
->setInlineComment($inline)
|
||||
->setIsOnRight($on_right)
|
||||
->setMarkupEngine($engine)
|
||||
|
||||
@@ -4,6 +4,7 @@ abstract class PhabricatorInlineCommentPreviewController
|
||||
extends PhabricatorController {
|
||||
|
||||
abstract protected function loadInlineComments();
|
||||
abstract protected function loadObjectOwnerPHID();
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
@@ -23,13 +24,12 @@ abstract class PhabricatorInlineCommentPreviewController
|
||||
|
||||
$phids = array($viewer->getPHID());
|
||||
$handles = $this->loadViewerHandles($phids);
|
||||
$object_owner_phid = $this->loadObjectOwnerPHID();
|
||||
|
||||
$views = array();
|
||||
foreach ($inlines as $inline) {
|
||||
// TODO: This is incorrect, but figuring it out is somewhat involved.
|
||||
$object_owner_phid = null;
|
||||
|
||||
$view = id(new PHUIDiffInlineCommentDetailView())
|
||||
->setUser($viewer)
|
||||
->setInlineComment($inline)
|
||||
->setMarkupEngine($engine)
|
||||
->setHandles($handles)
|
||||
|
||||
@@ -130,9 +130,14 @@ final class PHUIDiffInlineCommentDetailView
|
||||
if ($inline->getReplyToCommentPHID()) {
|
||||
$classes[] = 'inline-comment-is-reply';
|
||||
}
|
||||
// Might break?
|
||||
if ($this->getCanMarkDone()) {
|
||||
$classes[] = 'viewer-is-diff-author';
|
||||
|
||||
$viewer_phid = $this->getUser()->getPHID();
|
||||
$owner_phid = $this->getObjectOwnerPHID();
|
||||
|
||||
if ($viewer_phid) {
|
||||
if ($viewer_phid == $owner_phid) {
|
||||
$classes[] = 'viewer-is-object-owner';
|
||||
}
|
||||
}
|
||||
|
||||
$action_buttons = new PHUIButtonBarView();
|
||||
|
||||
Reference in New Issue
Block a user