Summary:
Ref T1460. This just barely works, but throwing it up in case any of it sounds mechanically crazy before we build integrations/UI/etc.
Specifically, these are the behaviors:
- You can mark your own draft comments as "done" before you submit them. The intent is to let reviewers mark their stuff advisory/minor/not-important before they submit it, to hint to authors that they don't expect the feedback to necessarily be addressed (maybe it's a joke, maybe it's just discussion, maybe it's "consider..").
- You can mark others' published comments as "done" if you're the revision/commit author. The intent is to keep this lightweight by not requiring an audit trail of who marked what done when. If anyone could mark anything done, we'd have to have some way to show who marked stuff.
- When you mark stuff done (or unmark it), it goes into a "draft" state, where you see the change but others don't see it yet. The intent is twofold:
- Be consistent with how inlines work.
- Allow us to publish a "epriestley updated this revision + epriestley marked 15 inlines as done" story later if we want. This seems more useful than publishing 15 "epriestley marked one thing as done" stories.
- The actual bit where done-ness publishes isn't implemented.
- UI is bare bones.
- No integration with the rest of the UI yet.
Test Plan: Clicked some checkboxes.
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: paulshen, chasemp, epriestley
Maniphest Tasks: T1460
Differential Revision: https://secure.phabricator.com/D12033
143 lines
3.7 KiB
PHP
143 lines
3.7 KiB
PHP
<?php
|
|
|
|
final class DifferentialInlineCommentEditController
|
|
extends PhabricatorInlineCommentController {
|
|
|
|
private $revisionID;
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$this->revisionID = $data['id'];
|
|
}
|
|
|
|
protected function createComment() {
|
|
|
|
// 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 (!id(new DifferentialChangeset())->load($changeset_id)) {
|
|
throw new Exception('Invalid changeset ID!');
|
|
}
|
|
|
|
return id(new DifferentialInlineComment())
|
|
->setRevision($revision)
|
|
->setChangesetID($changeset_id);
|
|
}
|
|
|
|
protected function loadComment($id) {
|
|
return id(new DifferentialInlineCommentQuery())
|
|
->withIDs(array($id))
|
|
->executeOne();
|
|
}
|
|
|
|
protected function loadCommentByPHID($phid) {
|
|
return id(new DifferentialInlineCommentQuery())
|
|
->withPHIDs(array($phid))
|
|
->executeOne();
|
|
}
|
|
|
|
protected function loadCommentForEdit($id) {
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
|
|
$inline = $this->loadComment($id);
|
|
if (!$this->canEditInlineComment($user, $inline)) {
|
|
throw new Exception('That comment is not editable!');
|
|
}
|
|
return $inline;
|
|
}
|
|
|
|
protected function loadCommentForDone($id) {
|
|
$request = $this->getRequest();
|
|
$viewer = $request->getUser();
|
|
|
|
$inline = $this->loadComment($id);
|
|
if (!$inline) {
|
|
throw new Exception(pht('Unable to load inline "%d".', $id));
|
|
}
|
|
|
|
$changeset = id(new DifferentialChangesetQuery())
|
|
->setViewer($viewer)
|
|
->withIDs(array($inline->getChangesetID()))
|
|
->executeOne();
|
|
if (!$changeset) {
|
|
throw new Exception(pht('Unable to load changeset.'));
|
|
}
|
|
|
|
$diff = id(new DifferentialDiffQuery())
|
|
->setViewer($viewer)
|
|
->withIDs(array($changeset->getDiffID()))
|
|
->executeOne();
|
|
if (!$diff) {
|
|
throw new Exception(pht('Unable to load diff.'));
|
|
}
|
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
->setViewer($viewer)
|
|
->withIDs(array($diff->getRevisionID()))
|
|
->executeOne();
|
|
if (!$revision) {
|
|
throw new Exception(pht('Unable to load revision.'));
|
|
}
|
|
|
|
if ($revision->getAuthorPHID() !== $viewer->getPHID()) {
|
|
throw new Exception(pht('You are not the revision owner.'));
|
|
}
|
|
|
|
return $inline;
|
|
}
|
|
|
|
private function canEditInlineComment(
|
|
PhabricatorUser $user,
|
|
DifferentialInlineComment $inline) {
|
|
|
|
// Only the author may edit a comment.
|
|
if ($inline->getAuthorPHID() != $user->getPHID()) {
|
|
return false;
|
|
}
|
|
|
|
// Saved comments may not be edited, for now, although the schema now
|
|
// supports it.
|
|
if (!$inline->isDraft()) {
|
|
return false;
|
|
}
|
|
|
|
// Inline must be attached to the active revision.
|
|
if ($inline->getRevisionID() != $this->revisionID) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
protected function deleteComment(PhabricatorInlineCommentInterface $inline) {
|
|
$inline->openTransaction();
|
|
DifferentialDraft::deleteHasDraft(
|
|
$inline->getAuthorPHID(),
|
|
$inline->getRevisionPHID(),
|
|
$inline->getPHID());
|
|
$inline->delete();
|
|
$inline->saveTransaction();
|
|
}
|
|
|
|
protected function saveComment(PhabricatorInlineCommentInterface $inline) {
|
|
$inline->openTransaction();
|
|
$inline->save();
|
|
DifferentialDraft::markHasDraft(
|
|
$inline->getAuthorPHID(),
|
|
$inline->getRevisionPHID(),
|
|
$inline->getPHID());
|
|
$inline->saveTransaction();
|
|
}
|
|
}
|