2013-07-21 18:27:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class ReleephBranchQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $ids;
|
|
|
|
private $phids;
|
2013-08-17 03:55:35 +02:00
|
|
|
private $projectIDs;
|
|
|
|
|
|
|
|
const STATUS_ALL = 'status-all';
|
|
|
|
const STATUS_OPEN = 'status-open';
|
|
|
|
private $status = self::STATUS_ALL;
|
2013-07-21 18:27:00 +02:00
|
|
|
|
2013-08-14 18:01:38 +02:00
|
|
|
private $needCutPointCommits;
|
|
|
|
|
2013-07-21 18:27:00 +02:00
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-14 18:01:38 +02:00
|
|
|
public function needCutPointCommits($need_commits) {
|
|
|
|
$this->needCutPointCommits = $need_commits;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-17 03:55:35 +02:00
|
|
|
public function withStatus($status) {
|
|
|
|
$this->status = $status;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withProjectIDs(array $ids) {
|
|
|
|
$this->projectIDs = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-21 18:27:00 +02:00
|
|
|
public function loadPage() {
|
|
|
|
$table = new ReleephBranch();
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function willFilterPage(array $branches) {
|
|
|
|
$project_ids = mpull($branches, 'getReleephProjectID');
|
|
|
|
|
2014-04-20 20:51:02 +02:00
|
|
|
$projects = id(new ReleephProductQuery())
|
2013-07-21 18:27:00 +02:00
|
|
|
->withIDs($project_ids)
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
foreach ($branches as $key => $branch) {
|
|
|
|
$project_id = $project_ids[$key];
|
|
|
|
if (isset($projects[$project_id])) {
|
|
|
|
$branch->attachProject($projects[$project_id]);
|
|
|
|
} else {
|
|
|
|
unset($branches[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 18:01:38 +02:00
|
|
|
if ($this->needCutPointCommits) {
|
|
|
|
$commit_phids = mpull($branches, 'getCutPointCommitPHID');
|
|
|
|
$commits = id(new DiffusionCommitQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs($commit_phids)
|
|
|
|
->execute();
|
|
|
|
$commits = mpull($commits, null, 'getPHID');
|
|
|
|
|
|
|
|
foreach ($branches as $branch) {
|
|
|
|
$commit = idx($commits, $branch->getCutPointCommitPHID());
|
|
|
|
$branch->attachCutPointCommit($commit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-21 18:27:00 +02:00
|
|
|
return $branches;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
|
|
|
if ($this->ids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->phids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2013-08-17 03:55:35 +02:00
|
|
|
if ($this->projectIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'releephProjectID IN (%Ld)',
|
|
|
|
$this->projectIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
$status = $this->status;
|
|
|
|
switch ($status) {
|
|
|
|
case self::STATUS_ALL:
|
|
|
|
break;
|
|
|
|
case self::STATUS_OPEN:
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'isActive = 1');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception("Unknown status constant '{$status}'!");
|
|
|
|
}
|
|
|
|
|
2013-07-21 18:27:00 +02:00
|
|
|
$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() {
|
|
|
|
return 'PhabricatorApplicationReleeph';
|
|
|
|
}
|
|
|
|
|
2013-07-21 18:27:00 +02:00
|
|
|
}
|