[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/controller/ -> DiffusionInlineCommentController.php (source)

   1  <?php
   2  
   3  final class DiffusionInlineCommentController
   4    extends PhabricatorInlineCommentController {
   5  
   6    private $commitPHID;
   7  
   8    public function willProcessRequest(array $data) {
   9      $this->commitPHID = $data['phid'];
  10    }
  11  
  12    protected function createComment() {
  13  
  14      // Verify commit and path correspond to actual objects.
  15      $commit_phid = $this->commitPHID;
  16      $path_id = $this->getChangesetID();
  17  
  18      $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
  19        'phid = %s',
  20        $commit_phid);
  21      if (!$commit) {
  22        throw new Exception('Invalid commit ID!');
  23      }
  24  
  25      // TODO: Write a real PathQuery object?
  26  
  27      $path = queryfx_one(
  28        id(new PhabricatorRepository())->establishConnection('r'),
  29        'SELECT path FROM %T WHERE id = %d',
  30        PhabricatorRepository::TABLE_PATH,
  31        $path_id);
  32  
  33      if (!$path) {
  34        throw new Exception('Invalid path ID!');
  35      }
  36  
  37      return id(new PhabricatorAuditInlineComment())
  38        ->setCommitPHID($commit_phid)
  39        ->setPathID($path_id);
  40    }
  41  
  42    protected function loadComment($id) {
  43      return PhabricatorAuditInlineComment::loadID($id);
  44    }
  45  
  46    protected function loadCommentForEdit($id) {
  47      $request = $this->getRequest();
  48      $user = $request->getUser();
  49  
  50      $inline = $this->loadComment($id);
  51      if (!$this->canEditInlineComment($user, $inline)) {
  52        throw new Exception('That comment is not editable!');
  53      }
  54      return $inline;
  55    }
  56  
  57    private function canEditInlineComment(
  58      PhabricatorUser $user,
  59      PhabricatorAuditInlineComment $inline) {
  60  
  61      // Only the author may edit a comment.
  62      if ($inline->getAuthorPHID() != $user->getPHID()) {
  63        return false;
  64      }
  65  
  66      // Saved comments may not be edited.
  67      if ($inline->getAuditCommentID()) {
  68        return false;
  69      }
  70  
  71      // Inline must be attached to the active revision.
  72      if ($inline->getCommitPHID() != $this->commitPHID) {
  73        return false;
  74      }
  75  
  76      return true;
  77    }
  78  
  79    protected function deleteComment(PhabricatorInlineCommentInterface $inline) {
  80      return $inline->delete();
  81    }
  82  
  83    protected function saveComment(PhabricatorInlineCommentInterface $inline) {
  84      return $inline->save();
  85    }
  86  
  87  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1