Path: blob/master/src/applications/diffusion/controller/DiffusionInlineCommentController.php
12242 views
<?php12final class DiffusionInlineCommentController3extends PhabricatorInlineCommentController {45protected function newInlineCommentQuery() {6return new DiffusionDiffInlineCommentQuery();7}89protected function newContainerObject() {10return $this->loadCommit();11}1213private function getCommitPHID() {14return $this->getRequest()->getURIData('phid');15}1617private function loadCommit() {18$viewer = $this->getViewer();19$commit_phid = $this->getCommitPHID();2021$commit = id(new DiffusionCommitQuery())22->setViewer($viewer)23->withPHIDs(array($commit_phid))24->executeOne();25if (!$commit) {26throw new Exception(pht('Invalid commit PHID "%s"!', $commit_phid));27}2829return $commit;30}3132protected function createComment() {33$commit = $this->loadCommit();3435// TODO: Write a real PathQuery object?36$path_id = $this->getChangesetID();37$path = queryfx_one(38id(new PhabricatorRepository())->establishConnection('r'),39'SELECT path FROM %T WHERE id = %d',40PhabricatorRepository::TABLE_PATH,41$path_id);42if (!$path) {43throw new Exception(pht('Invalid path ID!'));44}4546return id(new PhabricatorAuditInlineComment())47->setCommitPHID($commit->getPHID())48->setPathID($path_id);49}5051protected function loadCommentForDone($id) {52$viewer = $this->getViewer();5354$inline = $this->loadCommentByID($id);55if (!$inline) {56throw new Exception(pht('Failed to load comment "%d".', $id));57}5859$commit = id(new DiffusionCommitQuery())60->setViewer($viewer)61->withPHIDs(array($inline->getCommitPHID()))62->executeOne();63if (!$commit) {64throw new Exception(pht('Failed to load commit.'));65}6667$owner_phid = $commit->getAuthorPHID();68$viewer_phid = $viewer->getPHID();69$viewer_is_owner = ($owner_phid && ($owner_phid == $viewer_phid));70$viewer_is_author = ($viewer_phid == $inline->getAuthorPHID());71$is_draft = $inline->isDraft();7273if ($viewer_is_owner) {74// You can mark inlines on your own commits as "Done".75} else if ($viewer_is_author && $is_draft) {76// You can mark your own unsubmitted inlines as "Done".77} else {78throw new Exception(79pht(80'You can not mark this comment as complete: you did not author '.81'the commit and the comment is not a draft you wrote.'));82}8384return $inline;85}8687protected function canEditInlineComment(88PhabricatorUser $viewer,89PhabricatorAuditInlineComment $inline) {9091// Only the author may edit a comment.92if ($inline->getAuthorPHID() != $viewer->getPHID()) {93return false;94}9596// Saved comments may not be edited.97if ($inline->getTransactionPHID()) {98return false;99}100101// Inline must be attached to the active revision.102if ($inline->getCommitPHID() != $this->getCommitPHID()) {103return false;104}105106return true;107}108109protected function loadObjectOwnerPHID(110PhabricatorInlineComment $inline) {111return $this->loadCommit()->getAuthorPHID();112}113114115}116117118