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

@@ -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();
}
}