1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 20:10:55 +01:00

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:
epriestley 2015-03-27 17:08:31 -07:00
parent b560014577
commit a17542ab28
12 changed files with 141 additions and 82 deletions

View file

@ -11,7 +11,7 @@ return array(
'core.pkg.js' => '75599122', 'core.pkg.js' => '75599122',
'darkconsole.pkg.js' => '8ab24e01', 'darkconsole.pkg.js' => '8ab24e01',
'differential.pkg.css' => '571b1cc1', 'differential.pkg.css' => '571b1cc1',
'differential.pkg.js' => 'e324301d', 'differential.pkg.js' => 'c0506961',
'diffusion.pkg.css' => '591664fa', 'diffusion.pkg.css' => '591664fa',
'diffusion.pkg.js' => 'bfc0737b', 'diffusion.pkg.js' => 'bfc0737b',
'maniphest.pkg.css' => '68d4dd3d', 'maniphest.pkg.css' => '68d4dd3d',
@ -57,7 +57,7 @@ return array(
'rsrc/css/application/differential/add-comment.css' => 'c47f8c40', 'rsrc/css/application/differential/add-comment.css' => 'c47f8c40',
'rsrc/css/application/differential/changeset-view.css' => 'f36406b1', 'rsrc/css/application/differential/changeset-view.css' => 'f36406b1',
'rsrc/css/application/differential/core.css' => '7ac3cabc', 'rsrc/css/application/differential/core.css' => '7ac3cabc',
'rsrc/css/application/differential/phui-inline-comment.css' => '17e89126', 'rsrc/css/application/differential/phui-inline-comment.css' => 'a96c315d',
'rsrc/css/application/differential/results-table.css' => '181aa9d9', 'rsrc/css/application/differential/results-table.css' => '181aa9d9',
'rsrc/css/application/differential/revision-comment.css' => '024dda6b', 'rsrc/css/application/differential/revision-comment.css' => '024dda6b',
'rsrc/css/application/differential/revision-history.css' => '0e8eb855', 'rsrc/css/application/differential/revision-history.css' => '0e8eb855',
@ -365,7 +365,7 @@ return array(
'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '453c5375', 'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '453c5375',
'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => 'd4eecc63', 'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => 'd4eecc63',
'rsrc/js/application/differential/ChangesetViewManager.js' => '58562350', 'rsrc/js/application/differential/ChangesetViewManager.js' => '58562350',
'rsrc/js/application/differential/DifferentialInlineCommentEditor.js' => 'b3412377', 'rsrc/js/application/differential/DifferentialInlineCommentEditor.js' => '2529c82d',
'rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js' => 'e10f8e18', 'rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js' => 'e10f8e18',
'rsrc/js/application/differential/behavior-comment-jump.js' => '4fdb476d', 'rsrc/js/application/differential/behavior-comment-jump.js' => '4fdb476d',
'rsrc/js/application/differential/behavior-comment-preview.js' => '8e1389b5', 'rsrc/js/application/differential/behavior-comment-preview.js' => '8e1389b5',
@ -523,7 +523,7 @@ return array(
'conpherence-widget-pane-css' => '1979ee8c', 'conpherence-widget-pane-css' => '1979ee8c',
'differential-changeset-view-css' => 'f36406b1', 'differential-changeset-view-css' => 'f36406b1',
'differential-core-view-css' => '7ac3cabc', 'differential-core-view-css' => '7ac3cabc',
'differential-inline-comment-editor' => 'b3412377', 'differential-inline-comment-editor' => '2529c82d',
'differential-results-table-css' => '181aa9d9', 'differential-results-table-css' => '181aa9d9',
'differential-revision-add-comment-css' => 'c47f8c40', 'differential-revision-add-comment-css' => 'c47f8c40',
'differential-revision-comment-css' => '024dda6b', 'differential-revision-comment-css' => '024dda6b',
@ -790,7 +790,7 @@ return array(
'phui-image-mask-css' => '5a8b09c8', 'phui-image-mask-css' => '5a8b09c8',
'phui-info-panel-css' => '27ea50a1', 'phui-info-panel-css' => '27ea50a1',
'phui-info-view-css' => 'c6f0aef8', 'phui-info-view-css' => 'c6f0aef8',
'phui-inline-comment-view-css' => '17e89126', 'phui-inline-comment-view-css' => 'a96c315d',
'phui-list-view-css' => '2e25ebfb', 'phui-list-view-css' => '2e25ebfb',
'phui-object-box-css' => 'd68ce5dc', 'phui-object-box-css' => 'd68ce5dc',
'phui-object-item-list-view-css' => '9db65899', 'phui-object-item-list-view-css' => '9db65899',
@ -995,6 +995,14 @@ return array(
'javelin-workflow', 'javelin-workflow',
'javelin-util', 'javelin-util',
), ),
'2529c82d' => array(
'javelin-dom',
'javelin-util',
'javelin-stratcom',
'javelin-install',
'javelin-request',
'javelin-workflow',
),
'2818f5ce' => array( '2818f5ce' => array(
'javelin-install', 'javelin-install',
'javelin-util', 'javelin-util',
@ -1652,14 +1660,6 @@ return array(
'javelin-uri', 'javelin-uri',
'javelin-request', 'javelin-request',
), ),
'b3412377' => array(
'javelin-dom',
'javelin-util',
'javelin-stratcom',
'javelin-install',
'javelin-request',
'javelin-workflow',
),
'b3a4b884' => array( 'b3a4b884' => array(
'javelin-behavior', 'javelin-behavior',
'phabricator-prefab', 'phabricator-prefab',

View file

@ -3,28 +3,31 @@
final class DifferentialInlineCommentEditController final class DifferentialInlineCommentEditController
extends PhabricatorInlineCommentController { extends PhabricatorInlineCommentController {
private $revisionID; private function getRevisionID() {
return $this->getRequest()->getURIData('id');
public function willProcessRequest(array $data) {
$this->revisionID = $data['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()) $revision = id(new DifferentialRevisionQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($revision_id)) ->withIDs(array($revision_id))
->executeOne(); ->executeOne();
if (!$revision) {
if (!$revision) { throw new Exception(pht('Invalid revision ID "%s".', $revision_id));
throw new Exception('Invalid 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)) { if (!id(new DifferentialChangeset())->load($changeset_id)) {
throw new Exception('Invalid changeset ID!'); throw new Exception('Invalid changeset ID!');
} }
@ -113,7 +116,7 @@ final class DifferentialInlineCommentEditController
} }
// Inline must be attached to the active revision. // Inline must be attached to the active revision.
if ($inline->getRevisionID() != $this->revisionID) { if ($inline->getRevisionID() != $this->getRevisionID()) {
return false; return false;
} }
@ -139,4 +142,10 @@ final class DifferentialInlineCommentEditController
$inline->getPHID()); $inline->getPHID());
$inline->saveTransaction(); $inline->saveTransaction();
} }
protected function loadObjectOwnerPHID(
PhabricatorInlineCommentInterface $inline) {
return $this->loadRevision()->getAuthorPHID();
}
} }

View file

@ -3,20 +3,30 @@
final class DifferentialInlineCommentPreviewController final class DifferentialInlineCommentPreviewController
extends PhabricatorInlineCommentPreviewController { extends PhabricatorInlineCommentPreviewController {
private $revisionID;
public function willProcessRequest(array $data) {
$this->revisionID = $data['id'];
}
protected function loadInlineComments() { protected function loadInlineComments() {
$user = $this->getRequest()->getUser(); $viewer = $this->getViewer();
$inlines = id(new DifferentialInlineCommentQuery()) return id(new DifferentialInlineCommentQuery())
->withDraftComments($user->getPHID(), $this->revisionID) ->withDraftComments($viewer->getPHID(), $this->getRevisionID())
->execute(); ->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');
}
} }

View file

@ -459,6 +459,7 @@ abstract class DifferentialChangesetHTMLRenderer
$allow_done = !$comment->isDraft() && $this->getCanMarkDone(); $allow_done = !$comment->isDraft() && $this->getCanMarkDone();
return id(new PHUIDiffInlineCommentDetailView()) return id(new PHUIDiffInlineCommentDetailView())
->setUser($user)
->setInlineComment($comment) ->setInlineComment($comment)
->setIsOnRight($on_right) ->setIsOnRight($on_right)
->setHandles($this->getHandles()) ->setHandles($this->getHandles())

View file

@ -845,7 +845,11 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
$rows = array(); $rows = array();
foreach ($inlines as $inline) { foreach ($inlines as $inline) {
// TODO: This should use modern scaffolding code.
$inline_view = id(new PHUIDiffInlineCommentDetailView()) $inline_view = id(new PHUIDiffInlineCommentDetailView())
->setUser($this->getViewer())
->setMarkupEngine($engine) ->setMarkupEngine($engine)
->setInlineComment($inline) ->setInlineComment($inline)
->render(); ->render();

View file

@ -3,39 +3,41 @@
final class DiffusionInlineCommentController final class DiffusionInlineCommentController
extends PhabricatorInlineCommentController { extends PhabricatorInlineCommentController {
private $commitPHID; private function getCommitPHID() {
return $this->getRequest()->getURIData('phid');
}
public function willProcessRequest(array $data) { private function loadCommit() {
$this->commitPHID = $data['phid']; $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() { protected function createComment() {
$commit = $this->loadCommit();
// 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!');
}
// TODO: Write a real PathQuery object? // TODO: Write a real PathQuery object?
$path_id = $this->getChangesetID();
$path = queryfx_one( $path = queryfx_one(
id(new PhabricatorRepository())->establishConnection('r'), id(new PhabricatorRepository())->establishConnection('r'),
'SELECT path FROM %T WHERE id = %d', 'SELECT path FROM %T WHERE id = %d',
PhabricatorRepository::TABLE_PATH, PhabricatorRepository::TABLE_PATH,
$path_id); $path_id);
if (!$path) { if (!$path) {
throw new Exception('Invalid path ID!'); throw new Exception('Invalid path ID!');
} }
return id(new PhabricatorAuditInlineComment()) return id(new PhabricatorAuditInlineComment())
->setCommitPHID($commit_phid) ->setCommitPHID($commit->getPHID())
->setPathID($path_id); ->setPathID($path_id);
} }
@ -98,7 +100,7 @@ final class DiffusionInlineCommentController
} }
// Inline must be attached to the active revision. // Inline must be attached to the active revision.
if ($inline->getCommitPHID() != $this->commitPHID) { if ($inline->getCommitPHID() != $this->getCommitPHID()) {
return false; return false;
} }
@ -113,4 +115,10 @@ final class DiffusionInlineCommentController
return $inline->save(); return $inline->save();
} }
protected function loadObjectOwnerPHID(
PhabricatorInlineCommentInterface $inline) {
return $this->loadCommit()->getAuthorPHID();
}
} }

View file

@ -3,19 +3,30 @@
final class DiffusionInlineCommentPreviewController final class DiffusionInlineCommentPreviewController
extends PhabricatorInlineCommentPreviewController { extends PhabricatorInlineCommentPreviewController {
private $commitPHID;
public function willProcessRequest(array $data) {
$this->commitPHID = $data['phid'];
}
protected function loadInlineComments() { protected function loadInlineComments() {
$user = $this->getRequest()->getUser(); $viewer = $this->getViewer();
$inlines = PhabricatorAuditInlineComment::loadDraftComments( return PhabricatorAuditInlineComment::loadDraftComments(
$user, $viewer,
$this->commitPHID); $this->getCommitPHID());
return $inlines;
} }
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');
}
} }

View file

@ -8,6 +8,8 @@ abstract class PhabricatorInlineCommentController
abstract protected function loadCommentForEdit($id); abstract protected function loadCommentForEdit($id);
abstract protected function loadCommentForDone($id); abstract protected function loadCommentForDone($id);
abstract protected function loadCommentByPHID($phid); abstract protected function loadCommentByPHID($phid);
abstract protected function loadObjectOwnerPHID(
PhabricatorInlineCommentInterface $inline);
abstract protected function deleteComment( abstract protected function deleteComment(
PhabricatorInlineCommentInterface $inline); PhabricatorInlineCommentInterface $inline);
abstract protected function saveComment( abstract protected function saveComment(
@ -88,6 +90,7 @@ abstract class PhabricatorInlineCommentController
} }
$inline = $this->loadCommentForDone($this->getCommentID()); $inline = $this->loadCommentForDone($this->getCommentID());
$is_draft_state = false;
switch ($inline->getFixedState()) { switch ($inline->getFixedState()) {
case PhabricatorInlineCommentInterface::STATE_DRAFT: case PhabricatorInlineCommentInterface::STATE_DRAFT:
$next_state = PhabricatorInlineCommentInterface::STATE_UNDONE; $next_state = PhabricatorInlineCommentInterface::STATE_UNDONE;
@ -97,16 +100,22 @@ abstract class PhabricatorInlineCommentController
break; break;
case PhabricatorInlineCommentInterface::STATE_DONE: case PhabricatorInlineCommentInterface::STATE_DONE:
$next_state = PhabricatorInlineCommentInterface::STATE_UNDRAFT; $next_state = PhabricatorInlineCommentInterface::STATE_UNDRAFT;
$is_draft_state = true;
break; break;
default: default:
case PhabricatorInlineCommentInterface::STATE_UNDONE: case PhabricatorInlineCommentInterface::STATE_UNDONE:
$next_state = PhabricatorInlineCommentInterface::STATE_DRAFT; $next_state = PhabricatorInlineCommentInterface::STATE_DRAFT;
$is_draft_state = true;
break; break;
} }
$inline->setFixedState($next_state)->save(); $inline->setFixedState($next_state)->save();
return $this->buildEmptyResponse(); return id(new AphrontAjaxResponse())
->setContent(
array(
'draftState' => $is_draft_state,
));
case 'delete': case 'delete':
case 'undelete': case 'undelete':
case 'refdelete': case 'refdelete':
@ -306,12 +315,10 @@ abstract class PhabricatorInlineCommentController
$phids = array($user->getPHID()); $phids = array($user->getPHID());
$handles = $this->loadViewerHandles($phids); $handles = $this->loadViewerHandles($phids);
$object_owner_phid = $this->loadObjectOwnerPHID($inline);
// TODO: This is not correct, but figuring it out is a little bit
// involved and it only affects drafts.
$object_owner_phid = null;
$view = id(new PHUIDiffInlineCommentDetailView()) $view = id(new PHUIDiffInlineCommentDetailView())
->setUser($user)
->setInlineComment($inline) ->setInlineComment($inline)
->setIsOnRight($on_right) ->setIsOnRight($on_right)
->setMarkupEngine($engine) ->setMarkupEngine($engine)

View file

@ -4,6 +4,7 @@ abstract class PhabricatorInlineCommentPreviewController
extends PhabricatorController { extends PhabricatorController {
abstract protected function loadInlineComments(); abstract protected function loadInlineComments();
abstract protected function loadObjectOwnerPHID();
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
@ -23,13 +24,12 @@ abstract class PhabricatorInlineCommentPreviewController
$phids = array($viewer->getPHID()); $phids = array($viewer->getPHID());
$handles = $this->loadViewerHandles($phids); $handles = $this->loadViewerHandles($phids);
$object_owner_phid = $this->loadObjectOwnerPHID();
$views = array(); $views = array();
foreach ($inlines as $inline) { foreach ($inlines as $inline) {
// TODO: This is incorrect, but figuring it out is somewhat involved.
$object_owner_phid = null;
$view = id(new PHUIDiffInlineCommentDetailView()) $view = id(new PHUIDiffInlineCommentDetailView())
->setUser($viewer)
->setInlineComment($inline) ->setInlineComment($inline)
->setMarkupEngine($engine) ->setMarkupEngine($engine)
->setHandles($handles) ->setHandles($handles)

View file

@ -130,9 +130,14 @@ final class PHUIDiffInlineCommentDetailView
if ($inline->getReplyToCommentPHID()) { if ($inline->getReplyToCommentPHID()) {
$classes[] = 'inline-comment-is-reply'; $classes[] = 'inline-comment-is-reply';
} }
// Might break?
if ($this->getCanMarkDone()) { $viewer_phid = $this->getUser()->getPHID();
$classes[] = 'viewer-is-diff-author'; $owner_phid = $this->getObjectOwnerPHID();
if ($viewer_phid) {
if ($viewer_phid == $owner_phid) {
$classes[] = 'viewer-is-object-owner';
}
} }
$action_buttons = new PHUIButtonBarView(); $action_buttons = new PHUIButtonBarView();

View file

@ -244,6 +244,11 @@
cursor: pointer; cursor: pointer;
} }
.inline-state-is-draft .differential-inline-done-label {
/* TODO: Placeholder style. */
border-style: dashed;
}
.differential-inline-done-label .differential-inline-done { .differential-inline-done-label .differential-inline-done {
margin: 0 6px 0 0; margin: 0 6px 0 0;
display: inline; display: inline;

View file

@ -301,7 +301,7 @@ JX.install('DifferentialInlineCommentEditor', {
}; };
new JX.Workflow(this._uri, data) new JX.Workflow(this._uri, data)
.setHandler(JX.bind(this, function() { .setHandler(JX.bind(this, function(r) {
checkbox.checked = !checkbox.checked; checkbox.checked = !checkbox.checked;
var comment = JX.DOM.findAbove( var comment = JX.DOM.findAbove(
@ -309,8 +309,7 @@ JX.install('DifferentialInlineCommentEditor', {
'div', 'div',
'differential-inline-comment'); 'differential-inline-comment');
JX.DOM.alterClass(comment, 'inline-is-done', !!checkbox.checked); JX.DOM.alterClass(comment, 'inline-is-done', !!checkbox.checked);
JX.DOM.alterClass(comment, 'inline-state-is-draft', r.draftState);
// TODO: Dynamically update the "inline-state-is-draft" class.
this._didUpdate(); this._didUpdate();
})) }))