2012-12-11 22:59:20 +01:00
|
|
|
<?php
|
|
|
|
|
2015-03-09 20:15:54 +01:00
|
|
|
abstract class PhabricatorApplicationTransactionCommentQuery
|
2012-12-11 22:59:20 +01:00
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
2015-03-09 20:15:54 +01:00
|
|
|
private $ids;
|
|
|
|
private $authorPHIDs;
|
2012-12-11 22:59:20 +01:00
|
|
|
private $phids;
|
|
|
|
private $transactionPHIDs;
|
2015-03-09 20:15:54 +01:00
|
|
|
private $isDeleted;
|
2015-03-09 20:40:29 +01:00
|
|
|
private $hasTransaction;
|
2015-03-09 20:15:54 +01:00
|
|
|
|
|
|
|
abstract protected function getTemplate();
|
2012-12-11 22:59:20 +01:00
|
|
|
|
2015-03-09 20:15:54 +01:00
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
2012-12-11 22:59:20 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-12-11 23:01:51 +01:00
|
|
|
public function withTransactionPHIDs(array $transaction_phids) {
|
2012-12-11 22:59:20 +01:00
|
|
|
$this->transactionPHIDs = $transaction_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-03-09 20:15:54 +01:00
|
|
|
public function withAuthorPHIDs(array $phids) {
|
|
|
|
$this->authorPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-03-09 20:40:29 +01:00
|
|
|
public function withIsDeleted($deleted) {
|
2015-03-09 20:15:54 +01:00
|
|
|
$this->isDeleted = $deleted;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-03-09 20:40:29 +01:00
|
|
|
public function withHasTransaction($has_transaction) {
|
|
|
|
$this->hasTransaction = $has_transaction;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:28:02 +01:00
|
|
|
protected function loadPage() {
|
2015-03-09 20:15:54 +01:00
|
|
|
$table = $this->getTemplate();
|
2012-12-11 22:59:20 +01:00
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
2015-03-09 20:15:54 +01:00
|
|
|
'SELECT * FROM %T xcomment %Q %Q %Q',
|
2012-12-11 22:59:20 +01:00
|
|
|
$table->getTableName(),
|
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
|
|
|
return $table->loadAllFromArray($data);
|
|
|
|
}
|
|
|
|
|
2015-03-09 20:40:29 +01:00
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
return $this->formatWhereClause($this->buildWhereClauseComponents($conn_r));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildWhereClauseComponents(
|
|
|
|
AphrontDatabaseConnection $conn_r) {
|
|
|
|
|
2012-12-11 22:59:20 +01:00
|
|
|
$where = array();
|
|
|
|
|
2015-03-09 20:15:54 +01:00
|
|
|
if ($this->ids !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'xcomment.id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->phids !== null) {
|
2012-12-11 22:59:20 +01:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-03-09 20:15:54 +01:00
|
|
|
'xcomment.phid IN (%Ls)',
|
2012-12-11 22:59:20 +01:00
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2015-03-09 20:15:54 +01:00
|
|
|
if ($this->authorPHIDs !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'xcomment.authorPHID IN (%Ls)',
|
|
|
|
$this->authorPHIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->transactionPHIDs !== null) {
|
2012-12-11 22:59:20 +01:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-03-09 20:15:54 +01:00
|
|
|
'xcomment.transactionPHID IN (%Ls)',
|
2012-12-11 22:59:20 +01:00
|
|
|
$this->transactionPHIDs);
|
|
|
|
}
|
|
|
|
|
2015-03-09 20:15:54 +01:00
|
|
|
if ($this->isDeleted !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'xcomment.isDeleted = %d',
|
|
|
|
(int)$this->isDeleted);
|
|
|
|
}
|
|
|
|
|
2015-03-09 20:40:29 +01:00
|
|
|
if ($this->hasTransaction !== null) {
|
|
|
|
if ($this->hasTransaction) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'xcomment.transactionPHID IS NOT NULL');
|
|
|
|
} else {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'xcomment.transactionPHID IS NULL');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $where;
|
2012-12-11 22:59:20 +01: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-22 02:20:27 +02:00
|
|
|
public function getQueryApplicationClass() {
|
|
|
|
// TODO: Figure out the app via the template?
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-11 22:59:20 +01:00
|
|
|
}
|