3 final class DiffusionInlineCommentController
4 extends PhabricatorInlineCommentController
{
6 protected function newInlineCommentQuery() {
7 return new DiffusionDiffInlineCommentQuery();
10 protected function newContainerObject() {
11 return $this->loadCommit();
14 private function getCommitPHID() {
15 return $this->getRequest()->getURIData('phid');
18 private function loadCommit() {
19 $viewer = $this->getViewer();
20 $commit_phid = $this->getCommitPHID();
22 $commit = id(new DiffusionCommitQuery())
24 ->withPHIDs(array($commit_phid))
27 throw new Exception(pht('Invalid commit PHID "%s"!', $commit_phid));
33 protected function createComment() {
34 $commit = $this->loadCommit();
36 // TODO: Write a real PathQuery object?
37 $path_id = $this->getChangesetID();
39 id(new PhabricatorRepository())->establishConnection('r'),
40 'SELECT path FROM %T WHERE id = %d',
41 PhabricatorRepository
::TABLE_PATH
,
44 throw new Exception(pht('Invalid path ID!'));
47 return id(new PhabricatorAuditInlineComment())
48 ->setCommitPHID($commit->getPHID())
49 ->setPathID($path_id);
52 protected function loadCommentForDone($id) {
53 $viewer = $this->getViewer();
55 $inline = $this->loadCommentByID($id);
57 throw new Exception(pht('Failed to load comment "%d".', $id));
60 $commit = id(new DiffusionCommitQuery())
62 ->withPHIDs(array($inline->getCommitPHID()))
65 throw new Exception(pht('Failed to load commit.'));
68 $owner_phid = $commit->getAuthorPHID();
69 $viewer_phid = $viewer->getPHID();
70 $viewer_is_owner = ($owner_phid && ($owner_phid == $viewer_phid));
71 $viewer_is_author = ($viewer_phid == $inline->getAuthorPHID());
72 $is_draft = $inline->isDraft();
74 if ($viewer_is_owner) {
75 // You can mark inlines on your own commits as "Done".
76 } else if ($viewer_is_author && $is_draft) {
77 // You can mark your own unsubmitted inlines as "Done".
81 'You can not mark this comment as complete: you did not author '.
82 'the commit and the comment is not a draft you wrote.'));
88 protected function canEditInlineComment(
89 PhabricatorUser
$viewer,
90 PhabricatorAuditInlineComment
$inline) {
92 // Only the author may edit a comment.
93 if ($inline->getAuthorPHID() != $viewer->getPHID()) {
97 // Saved comments may not be edited.
98 if ($inline->getTransactionPHID()) {
102 // Inline must be attached to the active revision.
103 if ($inline->getCommitPHID() != $this->getCommitPHID()) {
110 protected function loadObjectOwnerPHID(
111 PhabricatorInlineComment
$inline) {
112 return $this->loadCommit()->getAuthorPHID();