2013-07-01 21:38:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialDiffQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $ids;
|
2013-11-06 22:59:06 +01:00
|
|
|
private $phids;
|
2013-07-01 21:38:42 +02:00
|
|
|
private $revisionIDs;
|
2013-09-17 22:55:41 +02:00
|
|
|
private $needChangesets = false;
|
|
|
|
private $needArcanistProjects = false;
|
2013-07-01 21:38:42 +02:00
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-11-06 22:59:06 +01:00
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-01 21:38:42 +02:00
|
|
|
public function withRevisionIDs(array $revision_ids) {
|
|
|
|
$this->revisionIDs = $revision_ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-09-17 22:55:41 +02:00
|
|
|
public function needChangesets($bool) {
|
|
|
|
$this->needChangesets = $bool;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function needArcanistProjects($bool) {
|
|
|
|
$this->needArcanistProjects = $bool;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-01-13 20:56:07 +01:00
|
|
|
protected function loadPage() {
|
2013-07-01 21:38:42 +02:00
|
|
|
$table = new DifferentialDiff();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT * FROM %T %Q %Q %Q',
|
|
|
|
$table->getTableName(),
|
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
|
|
|
return $table->loadAllFromArray($data);
|
|
|
|
}
|
|
|
|
|
2015-01-13 20:56:07 +01:00
|
|
|
protected function willFilterPage(array $diffs) {
|
2013-09-27 03:45:04 +02:00
|
|
|
$revision_ids = array_filter(mpull($diffs, 'getRevisionID'));
|
|
|
|
|
|
|
|
$revisions = array();
|
|
|
|
if ($revision_ids) {
|
|
|
|
$revisions = id(new DifferentialRevisionQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withIDs($revision_ids)
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($diffs as $key => $diff) {
|
|
|
|
if (!$diff->getRevisionID()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$revision = idx($revisions, $diff->getRevisionID());
|
|
|
|
if ($revision) {
|
|
|
|
$diff->attachRevision($revision);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($diffs[$key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-25 17:09:01 +02:00
|
|
|
if ($diffs && $this->needChangesets) {
|
|
|
|
$diffs = $this->loadChangesets($diffs);
|
2013-09-17 22:55:41 +02:00
|
|
|
}
|
|
|
|
|
2014-05-25 17:09:01 +02:00
|
|
|
if ($diffs && $this->needArcanistProjects) {
|
|
|
|
$diffs = $this->loadArcanistProjects($diffs);
|
2013-09-17 22:55:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $diffs;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function loadChangesets(array $diffs) {
|
2014-05-25 17:59:31 +02:00
|
|
|
id(new DifferentialChangesetQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->setParentQuery($this)
|
|
|
|
->withDiffs($diffs)
|
|
|
|
->needAttachToDiffs(true)
|
|
|
|
->needHunks(true)
|
|
|
|
->execute();
|
2014-05-25 17:09:01 +02:00
|
|
|
|
2013-09-17 22:55:41 +02:00
|
|
|
return $diffs;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function loadArcanistProjects(array $diffs) {
|
|
|
|
$phids = array_filter(mpull($diffs, 'getArcanistProjectPHID'));
|
|
|
|
$projects = array();
|
|
|
|
$project_map = array();
|
|
|
|
if ($phids) {
|
|
|
|
$projects = id(new PhabricatorRepositoryArcanistProject())
|
|
|
|
->loadAllWhere(
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
$phids);
|
|
|
|
$project_map = mpull($projects, null, 'getPHID');
|
2013-09-24 19:48:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($diffs as $diff) {
|
|
|
|
$project = null;
|
|
|
|
if ($diff->getArcanistProjectPHID()) {
|
|
|
|
$project = idx($project_map, $diff->getArcanistProjectPHID());
|
2013-09-17 22:55:41 +02:00
|
|
|
}
|
2013-09-24 19:48:40 +02:00
|
|
|
$diff->attachArcanistProject($project);
|
2013-09-17 22:55:41 +02:00
|
|
|
}
|
2013-09-24 19:48:40 +02:00
|
|
|
|
2013-09-17 22:55:41 +02:00
|
|
|
return $diffs;
|
|
|
|
}
|
|
|
|
|
2013-07-01 21:38:42 +02:00
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
|
|
|
if ($this->ids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2013-11-06 22:59:06 +01:00
|
|
|
if ($this->phids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2013-07-01 21:38:42 +02:00
|
|
|
if ($this->revisionIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'revisionID IN (%Ld)',
|
|
|
|
$this->revisionIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
Lock policy queries to their applications
Summary:
While we mostly have reasonable effective object accessibility when you lock a user out of an application, it's primarily enforced at the controller level. Users can still, e.g., load the handles of objects they can't actually see. Instead, lock the queries to the applications so that you can, e.g., never load a revision if you don't have access to Differential.
This has several parts:
- For PolicyAware queries, provide an application class name method.
- If the query specifies a class name and the user doesn't have permission to use it, fail the entire query unconditionally.
- For handles, simplify query construction and count all the PHIDs as "restricted" so we get a UI full of "restricted" instead of "unknown" handles.
Test Plan:
- Added a unit test to verify I got all the class names right.
- Browsed around, logged in/out as a normal user with public policies on and off.
- Browsed around, logged in/out as a restricted user with public policies on and off. With restrictions, saw all traces of restricted apps removed or restricted.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7367
2013-10-22 02:20:27 +02:00
|
|
|
public function getQueryApplicationClass() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorDifferentialApplication';
|
Lock policy queries to their applications
Summary:
While we mostly have reasonable effective object accessibility when you lock a user out of an application, it's primarily enforced at the controller level. Users can still, e.g., load the handles of objects they can't actually see. Instead, lock the queries to the applications so that you can, e.g., never load a revision if you don't have access to Differential.
This has several parts:
- For PolicyAware queries, provide an application class name method.
- If the query specifies a class name and the user doesn't have permission to use it, fail the entire query unconditionally.
- For handles, simplify query construction and count all the PHIDs as "restricted" so we get a UI full of "restricted" instead of "unknown" handles.
Test Plan:
- Added a unit test to verify I got all the class names right.
- Browsed around, logged in/out as a normal user with public policies on and off.
- Browsed around, logged in/out as a restricted user with public policies on and off. With restrictions, saw all traces of restricted apps removed or restricted.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7367
2013-10-22 02:20:27 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 21:38:42 +02:00
|
|
|
}
|