2012-08-08 12:25:11 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorOwnersPackageQuery
|
2012-09-13 10:15:08 -07:00
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
2012-08-08 12:25:11 -07:00
|
|
|
|
2015-05-27 10:29:01 -07:00
|
|
|
private $ids;
|
2013-07-26 10:31:26 -07:00
|
|
|
private $phids;
|
2012-08-08 12:25:11 -07:00
|
|
|
private $ownerPHIDs;
|
2015-05-27 10:29:01 -07:00
|
|
|
private $repositoryPHIDs;
|
2015-06-18 17:16:37 -07:00
|
|
|
private $namePrefix;
|
2012-08-08 12:25:11 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Owners are direct owners, and members of owning projects.
|
|
|
|
*/
|
|
|
|
public function withOwnerPHIDs(array $phids) {
|
|
|
|
$this->ownerPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-26 10:31:26 -07:00
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-05-27 10:29:01 -07:00
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withRepositoryPHIDs(array $phids) {
|
|
|
|
$this->repositoryPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-06-18 17:16:37 -07:00
|
|
|
public function withNamePrefix($prefix) {
|
|
|
|
$this->namePrefix = $prefix;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newResultObject() {
|
|
|
|
return new PhabricatorOwnersPackage();
|
|
|
|
}
|
|
|
|
|
2012-08-08 12:25:11 -07:00
|
|
|
protected function loadPage() {
|
2015-06-18 17:16:37 -07:00
|
|
|
return $this->loadStandardPage(new PhabricatorOwnersPackage());
|
2012-08-08 12:25:11 -07:00
|
|
|
}
|
|
|
|
|
2015-06-18 17:16:37 -07:00
|
|
|
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
$joins = parent::buildJoinClauseParts($conn);
|
2012-08-08 12:25:11 -07:00
|
|
|
|
2015-05-27 10:29:01 -07:00
|
|
|
if ($this->ownerPHIDs !== null) {
|
2012-08-08 12:25:11 -07:00
|
|
|
$joins[] = qsprintf(
|
2015-06-18 17:16:37 -07:00
|
|
|
$conn,
|
2012-08-08 12:25:11 -07:00
|
|
|
'JOIN %T o ON o.packageID = p.id',
|
|
|
|
id(new PhabricatorOwnersOwner())->getTableName());
|
|
|
|
}
|
|
|
|
|
2015-05-27 10:29:01 -07:00
|
|
|
if ($this->repositoryPHIDs !== null) {
|
|
|
|
$joins[] = qsprintf(
|
2015-06-18 17:16:37 -07:00
|
|
|
$conn,
|
2015-05-27 10:29:01 -07:00
|
|
|
'JOIN %T rpath ON rpath.packageID = p.id',
|
|
|
|
id(new PhabricatorOwnersPath())->getTableName());
|
|
|
|
}
|
|
|
|
|
2015-06-18 17:16:37 -07:00
|
|
|
return $joins;
|
2012-08-08 12:25:11 -07:00
|
|
|
}
|
|
|
|
|
2015-06-18 17:16:37 -07:00
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
$where = parent::buildWhereClauseParts($conn);
|
2012-08-08 12:25:11 -07:00
|
|
|
|
2015-05-27 10:29:01 -07:00
|
|
|
if ($this->phids !== null) {
|
2013-07-26 10:31:26 -07:00
|
|
|
$where[] = qsprintf(
|
2015-06-18 17:16:37 -07:00
|
|
|
$conn,
|
2013-07-26 10:31:26 -07:00
|
|
|
'p.phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2015-05-27 10:29:01 -07:00
|
|
|
if ($this->ids !== null) {
|
|
|
|
$where[] = qsprintf(
|
2015-06-18 17:16:37 -07:00
|
|
|
$conn,
|
2015-05-27 10:29:01 -07:00
|
|
|
'p.id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->repositoryPHIDs !== null) {
|
|
|
|
$where[] = qsprintf(
|
2015-06-18 17:16:37 -07:00
|
|
|
$conn,
|
2015-05-27 10:29:01 -07:00
|
|
|
'rpath.repositoryPHID IN (%Ls)',
|
|
|
|
$this->repositoryPHIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->ownerPHIDs !== null) {
|
2012-08-08 12:25:11 -07:00
|
|
|
$base_phids = $this->ownerPHIDs;
|
|
|
|
|
2015-06-18 17:16:37 -07:00
|
|
|
$projects = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withMemberPHIDs($base_phids)
|
|
|
|
->execute();
|
2012-08-08 12:25:11 -07:00
|
|
|
$project_phids = mpull($projects, 'getPHID');
|
|
|
|
|
|
|
|
$all_phids = array_merge($base_phids, $project_phids);
|
|
|
|
|
|
|
|
$where[] = qsprintf(
|
2015-06-18 17:16:37 -07:00
|
|
|
$conn,
|
2012-08-08 12:25:11 -07:00
|
|
|
'o.userPHID IN (%Ls)',
|
|
|
|
$all_phids);
|
|
|
|
}
|
|
|
|
|
2015-06-18 17:16:37 -07:00
|
|
|
if (strlen($this->namePrefix)) {
|
|
|
|
// NOTE: This is a hacky mess, but this column is currently case
|
|
|
|
// sensitive and unique.
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'LOWER(p.name) LIKE %>',
|
|
|
|
phutil_utf8_strtolower($this->namePrefix));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $where;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function shouldGroupQueryResultRows() {
|
|
|
|
if ($this->repositoryPHIDs) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->ownerPHIDs) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::shouldGroupQueryResultRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBuiltinOrders() {
|
|
|
|
return array(
|
|
|
|
'name' => array(
|
|
|
|
'vector' => array('name'),
|
|
|
|
'name' => pht('Name'),
|
|
|
|
),
|
|
|
|
) + parent::getBuiltinOrders();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOrderableColumns() {
|
|
|
|
return parent::getOrderableColumns() + array(
|
|
|
|
'name' => array(
|
|
|
|
'table' => $this->getPrimaryTableAlias(),
|
|
|
|
'column' => 'name',
|
|
|
|
'type' => 'string',
|
|
|
|
'unique' => true,
|
|
|
|
'reverse' => true,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getPagingValueMap($cursor, array $keys) {
|
|
|
|
$package = $this->loadCursorObject($cursor);
|
|
|
|
return array(
|
|
|
|
'id' => $package->getID(),
|
|
|
|
'name' => $package->getName(),
|
|
|
|
);
|
2012-08-08 12:25:11 -07:00
|
|
|
}
|
|
|
|
|
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-21 17:20:27 -07:00
|
|
|
public function getQueryApplicationClass() {
|
2014-07-23 10:03:09 +10:00
|
|
|
return 'PhabricatorOwnersApplication';
|
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-21 17:20:27 -07:00
|
|
|
}
|
|
|
|
|
2015-06-18 17:16:37 -07:00
|
|
|
protected function getPrimaryTableAlias() {
|
|
|
|
return 'p';
|
|
|
|
}
|
|
|
|
|
2012-08-08 12:25:11 -07:00
|
|
|
}
|