mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Replace "loadDraftAndPublishedComments()" with a Query
Summary: Ref T13513. Continue marching toward coherent query pathways for all access to inline comments. Test Plan: - Viewed a commit and a path within that commit, as a user with unpublished inlines and a different user. - Saw appropriate inlines in all cases (published inlines, plus undeleted unpublished inlines authored by the current viewer). - Grepped for "loadDraftAndPublishedComments()". Maniphest Tasks: T13513 Differential Revision: https://secure.phabricator.com/D21228
This commit is contained in:
parent
c1f1345cc0
commit
d0593a5a78
4 changed files with 93 additions and 30 deletions
|
@ -89,29 +89,6 @@ final class PhabricatorAuditInlineComment
|
||||||
return self::buildProxies($inlines);
|
return self::buildProxies($inlines);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function loadDraftAndPublishedComments(
|
|
||||||
PhabricatorUser $viewer,
|
|
||||||
$commit_phid,
|
|
||||||
$path_id = null) {
|
|
||||||
|
|
||||||
if ($path_id === null) {
|
|
||||||
$inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere(
|
|
||||||
'commitPHID = %s AND (transactionPHID IS NOT NULL OR authorPHID = %s)
|
|
||||||
AND pathID IS NOT NULL',
|
|
||||||
$commit_phid,
|
|
||||||
$viewer->getPHID());
|
|
||||||
} else {
|
|
||||||
$inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere(
|
|
||||||
'commitPHID = %s AND pathID = %d AND
|
|
||||||
((authorPHID = %s AND isDeleted = 0) OR transactionPHID IS NOT NULL)',
|
|
||||||
$commit_phid,
|
|
||||||
$path_id,
|
|
||||||
$viewer->getPHID());
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::buildProxies($inlines);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function buildProxies(array $inlines) {
|
private static function buildProxies(array $inlines) {
|
||||||
$results = array();
|
$results = array();
|
||||||
foreach ($inlines as $key => $inline) {
|
foreach ($inlines as $key => $inline) {
|
||||||
|
|
|
@ -414,9 +414,14 @@ final class DiffusionCommitController extends DiffusionController {
|
||||||
$visible_changesets = $changesets;
|
$visible_changesets = $changesets;
|
||||||
} else {
|
} else {
|
||||||
$visible_changesets = array();
|
$visible_changesets = array();
|
||||||
$inlines = PhabricatorAuditInlineComment::loadDraftAndPublishedComments(
|
|
||||||
$viewer,
|
$inlines = id(new DiffusionDiffInlineCommentQuery())
|
||||||
$commit->getPHID());
|
->setViewer($viewer)
|
||||||
|
->withCommitPHIDs(array($commit->getPHID()))
|
||||||
|
->withVisibleComments(true)
|
||||||
|
->execute();
|
||||||
|
$inlines = mpull($inlines, 'newInlineCommentObject');
|
||||||
|
|
||||||
$path_ids = mpull($inlines, null, 'getPathID');
|
$path_ids = mpull($inlines, null, 'getPathID');
|
||||||
foreach ($changesets as $key => $changeset) {
|
foreach ($changesets as $key => $changeset) {
|
||||||
if (array_key_exists($changeset->getID(), $path_ids)) {
|
if (array_key_exists($changeset->getID(), $path_ids)) {
|
||||||
|
|
|
@ -99,10 +99,13 @@ final class DiffusionDiffController extends DiffusionController {
|
||||||
($viewer->getPHID() == $commit->getAuthorPHID()));
|
($viewer->getPHID() == $commit->getAuthorPHID()));
|
||||||
$parser->setObjectOwnerPHID($commit->getAuthorPHID());
|
$parser->setObjectOwnerPHID($commit->getAuthorPHID());
|
||||||
|
|
||||||
$inlines = PhabricatorAuditInlineComment::loadDraftAndPublishedComments(
|
$inlines = id(new DiffusionDiffInlineCommentQuery())
|
||||||
$viewer,
|
->setViewer($viewer)
|
||||||
$commit->getPHID(),
|
->withCommitPHIDs(array($commit->getPHID()))
|
||||||
$path_id);
|
->withPathIDs(array($path_id))
|
||||||
|
->withVisibleComments(true)
|
||||||
|
->execute();
|
||||||
|
$inlines = mpull($inlines, 'newInlineCommentObject');
|
||||||
|
|
||||||
if ($inlines) {
|
if ($inlines) {
|
||||||
foreach ($inlines as $inline) {
|
foreach ($inlines as $inline) {
|
||||||
|
|
|
@ -5,6 +5,8 @@ abstract class PhabricatorDiffInlineCommentQuery
|
||||||
|
|
||||||
private $fixedStates;
|
private $fixedStates;
|
||||||
private $needReplyToComments;
|
private $needReplyToComments;
|
||||||
|
private $visibleComments;
|
||||||
|
private $publishableComments;
|
||||||
|
|
||||||
abstract protected function buildInlineCommentWhereClauseParts(
|
abstract protected function buildInlineCommentWhereClauseParts(
|
||||||
AphrontDatabaseConnection $conn);
|
AphrontDatabaseConnection $conn);
|
||||||
|
@ -20,6 +22,16 @@ abstract class PhabricatorDiffInlineCommentQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withVisibleComments($with_visible) {
|
||||||
|
$this->visibleComments = $with_visible;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withPublishableComments($with_publishable) {
|
||||||
|
$this->publishableComments = $with_publishable;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||||
$where = parent::buildWhereClauseParts($conn);
|
$where = parent::buildWhereClauseParts($conn);
|
||||||
$alias = $this->getPrimaryTableAlias();
|
$alias = $this->getPrimaryTableAlias();
|
||||||
|
@ -36,6 +48,72 @@ abstract class PhabricatorDiffInlineCommentQuery
|
||||||
$this->fixedStates);
|
$this->fixedStates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$show_published = false;
|
||||||
|
$show_publishable = false;
|
||||||
|
|
||||||
|
if ($this->visibleComments !== null) {
|
||||||
|
if (!$this->visibleComments) {
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'Querying for comments that are not visible is '.
|
||||||
|
'not supported.'));
|
||||||
|
}
|
||||||
|
$show_published = true;
|
||||||
|
$show_publishable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->publishableComments !== null) {
|
||||||
|
if (!$this->publishableComments) {
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'Querying for comments that are not publishable is '.
|
||||||
|
'not supported.'));
|
||||||
|
}
|
||||||
|
$show_publishable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($show_publishable || $show_published) {
|
||||||
|
$clauses = array();
|
||||||
|
|
||||||
|
if ($show_published) {
|
||||||
|
// Published comments are always visible.
|
||||||
|
$clauses[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'%T.transactionPHID IS NOT NULL',
|
||||||
|
$alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($show_publishable) {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
$viewer_phid = $viewer->getPHID();
|
||||||
|
|
||||||
|
// If the viewer has a PHID, unpublished comments they authored and
|
||||||
|
// have not deleted are visible.
|
||||||
|
if ($viewer_phid) {
|
||||||
|
$clauses[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'%T.authorPHID = %s
|
||||||
|
AND %T.isDeleted = 0
|
||||||
|
AND %T.transactionPHID IS NULL ',
|
||||||
|
$alias,
|
||||||
|
$viewer_phid,
|
||||||
|
$alias,
|
||||||
|
$alias);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We can end up with a known-empty query if we (for example) query for
|
||||||
|
// publishable comments and the viewer is logged-out.
|
||||||
|
if (!$clauses) {
|
||||||
|
throw new PhabricatorEmptyQueryException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'%LO',
|
||||||
|
$clauses);
|
||||||
|
}
|
||||||
|
|
||||||
return $where;
|
return $where;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue