2013-10-05 00:17:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class HeraldTranscriptQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $ids;
|
2014-02-21 21:51:25 +01:00
|
|
|
private $objectPHIDs;
|
2013-10-05 00:17:18 +02:00
|
|
|
private $needPartialRecords;
|
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-02-21 21:51:25 +01:00
|
|
|
public function withObjectPHIDs(array $phids) {
|
|
|
|
$this->objectPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-10-05 00:17:18 +02:00
|
|
|
public function needPartialRecords($need_partial) {
|
|
|
|
$this->needPartialRecords = $need_partial;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-01-13 20:56:07 +01:00
|
|
|
protected function loadPage() {
|
2013-10-05 00:17:18 +02:00
|
|
|
$transcript = new HeraldTranscript();
|
|
|
|
$conn_r = $transcript->establishConnection('r');
|
|
|
|
|
|
|
|
// NOTE: Transcripts include a potentially enormous amount of serialized
|
|
|
|
// data, so we're loading only some of the fields here if the caller asked
|
|
|
|
// for partial records.
|
|
|
|
|
|
|
|
if ($this->needPartialRecords) {
|
|
|
|
$fields = implode(
|
|
|
|
', ',
|
|
|
|
array(
|
|
|
|
'id',
|
|
|
|
'phid',
|
|
|
|
'objectPHID',
|
|
|
|
'time',
|
|
|
|
'duration',
|
|
|
|
'dryRun',
|
|
|
|
'host',
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
$fields = '*';
|
|
|
|
}
|
|
|
|
|
|
|
|
$rows = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT %Q FROM %T t %Q %Q %Q',
|
|
|
|
$fields,
|
|
|
|
$transcript->getTableName(),
|
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
|
|
|
$transcripts = $transcript->loadAllFromArray($rows);
|
|
|
|
|
|
|
|
if ($this->needPartialRecords) {
|
|
|
|
// Make sure nothing tries to write these; they aren't complete.
|
|
|
|
foreach ($transcripts as $transcript) {
|
|
|
|
$transcript->makeEphemeral();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $transcripts;
|
|
|
|
}
|
|
|
|
|
2015-01-13 20:56:07 +01:00
|
|
|
protected function willFilterPage(array $transcripts) {
|
2013-10-05 00:17:18 +02:00
|
|
|
$phids = mpull($transcripts, 'getObjectPHID');
|
|
|
|
|
|
|
|
$objects = id(new PhabricatorObjectQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs($phids)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
foreach ($transcripts as $key => $transcript) {
|
|
|
|
if (empty($objects[$transcript->getObjectPHID()])) {
|
|
|
|
$this->didRejectResult($transcript);
|
|
|
|
unset($transcripts[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $transcripts;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
|
|
|
if ($this->ids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2014-02-21 21:51:25 +01:00
|
|
|
if ($this->objectPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'objectPHID in (%Ls)',
|
|
|
|
$this->objectPHIDs);
|
|
|
|
}
|
|
|
|
|
2013-10-05 00:17:18 +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() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorHeraldApplication';
|
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-10-05 00:17:18 +02:00
|
|
|
|
|
|
|
}
|