Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2889489
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/applications/audit/storage/PhabricatorAuditInlineComment.php b/src/applications/audit/storage/PhabricatorAuditInlineComment.php
index 905694b24a..0a3a0400cf 100644
--- a/src/applications/audit/storage/PhabricatorAuditInlineComment.php
+++ b/src/applications/audit/storage/PhabricatorAuditInlineComment.php
@@ -1,115 +1,72 @@
<?php
final class PhabricatorAuditInlineComment
extends PhabricatorInlineComment {
protected function newStorageObject() {
return new PhabricatorAuditTransactionComment();
}
public function getControllerURI() {
return urisprintf(
'/diffusion/inline/edit/%s/',
$this->getCommitPHID());
}
public function supportsHiding() {
return false;
}
public function isHidden() {
return false;
}
public function getTransactionCommentForSave() {
$content_source = PhabricatorContentSource::newForSource(
PhabricatorOldWorldContentSource::SOURCECONST);
$this->getStorageObject()
->setViewPolicy('public')
->setEditPolicy($this->getAuthorPHID())
->setContentSource($content_source)
->setCommentVersion(1);
return $this->getStorageObject();
}
- public static function loadID($id) {
- $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere(
- 'id = %d',
- $id);
- if (!$inlines) {
- return null;
- }
-
- return head(self::buildProxies($inlines));
- }
-
- public static function loadPHID($phid) {
- $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere(
- 'phid = %s',
- $phid);
- if (!$inlines) {
- return null;
- }
- return head(self::buildProxies($inlines));
- }
-
- public static function loadPublishedComments(
- PhabricatorUser $viewer,
- $commit_phid) {
-
- $inlines = id(new DiffusionDiffInlineCommentQuery())
- ->setViewer($viewer)
- ->withCommitPHIDs(array($commit_phid))
- ->withHasTransaction(true)
- ->execute();
-
- return self::buildProxies($inlines);
- }
-
- private static function buildProxies(array $inlines) {
- $results = array();
- foreach ($inlines as $key => $inline) {
- $results[$key] = self::newFromModernComment(
- $inline);
- }
- return $results;
- }
-
public static function newFromModernComment(
PhabricatorAuditTransactionComment $comment) {
$obj = new PhabricatorAuditInlineComment();
$obj->setStorageObject($comment);
return $obj;
}
public function setPathID($id) {
$this->getStorageObject()->setPathID($id);
return $this;
}
public function getPathID() {
return $this->getStorageObject()->getPathID();
}
public function setCommitPHID($commit_phid) {
$this->getStorageObject()->setCommitPHID($commit_phid);
return $this;
}
public function getCommitPHID() {
return $this->getStorageObject()->getCommitPHID();
}
public function setChangesetID($id) {
return $this->setPathID($id);
}
public function getChangesetID() {
return $this->getPathID();
}
}
diff --git a/src/applications/diffusion/controller/DiffusionInlineCommentController.php b/src/applications/diffusion/controller/DiffusionInlineCommentController.php
index 33e2903799..9d9538ecd7 100644
--- a/src/applications/diffusion/controller/DiffusionInlineCommentController.php
+++ b/src/applications/diffusion/controller/DiffusionInlineCommentController.php
@@ -1,139 +1,159 @@
<?php
final class DiffusionInlineCommentController
extends PhabricatorInlineCommentController {
private function getCommitPHID() {
return $this->getRequest()->getURIData('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() {
$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(pht('Invalid path ID!'));
}
return id(new PhabricatorAuditInlineComment())
->setCommitPHID($commit->getPHID())
->setPathID($path_id);
}
protected function loadComment($id) {
- return PhabricatorAuditInlineComment::loadID($id);
+ $viewer = $this->getViewer();
+ $inline = id(new DiffusionDiffInlineCommentQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($id))
+ ->executeOne();
+
+ if ($inline) {
+ $inline = $inline->newInlineCommentObject();
+ }
+
+ return $inline;
}
protected function loadCommentByPHID($phid) {
- return PhabricatorAuditInlineComment::loadPHID($phid);
+ $viewer = $this->getViewer();
+ $inline = id(new DiffusionDiffInlineCommentQuery())
+ ->setViewer($viewer)
+ ->withPHIDs(array($phid))
+ ->executeOne();
+
+ if ($inline) {
+ $inline = $inline->newInlineCommentObject();
+ }
+
+ return $inline;
}
protected function loadCommentForEdit($id) {
$viewer = $this->getViewer();
$inline = $this->loadComment($id);
if (!$this->canEditInlineComment($viewer, $inline)) {
throw new Exception(pht('That comment is not editable!'));
}
return $inline;
}
protected function loadCommentForDone($id) {
$viewer = $this->getViewer();
$inline = $this->loadComment($id);
if (!$inline) {
throw new Exception(pht('Failed to load comment "%d".', $id));
}
$commit = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withPHIDs(array($inline->getCommitPHID()))
->executeOne();
if (!$commit) {
throw new Exception(pht('Failed to load commit.'));
}
$owner_phid = $commit->getAuthorPHID();
$viewer_phid = $viewer->getPHID();
$viewer_is_owner = ($owner_phid && ($owner_phid == $viewer_phid));
$viewer_is_author = ($viewer_phid == $inline->getAuthorPHID());
$is_draft = $inline->isDraft();
if ($viewer_is_owner) {
// You can mark inlines on your own commits as "Done".
} else if ($viewer_is_author && $is_draft) {
// You can mark your own unsubmitted inlines as "Done".
} else {
throw new Exception(
pht(
'You can not mark this comment as complete: you did not author '.
'the commit and the comment is not a draft you wrote.'));
}
return $inline;
}
private function canEditInlineComment(
PhabricatorUser $viewer,
PhabricatorAuditInlineComment $inline) {
// Only the author may edit a comment.
if ($inline->getAuthorPHID() != $viewer->getPHID()) {
return false;
}
// Saved comments may not be edited.
if ($inline->getTransactionPHID()) {
return false;
}
// Inline must be attached to the active revision.
if ($inline->getCommitPHID() != $this->getCommitPHID()) {
return false;
}
return true;
}
protected function deleteComment(PhabricatorInlineComment $inline) {
$inline->setIsDeleted(1)->save();
}
protected function undeleteComment(
PhabricatorInlineComment $inline) {
$inline->setIsDeleted(0)->save();
}
protected function saveComment(PhabricatorInlineComment $inline) {
return $inline->save();
}
protected function loadObjectOwnerPHID(
PhabricatorInlineComment $inline) {
return $this->loadCommit()->getAuthorPHID();
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Jan 19 2025, 12:14 (4 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1124445
Default Alt Text
(7 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment