2012-02-17 19:21:38 +01:00
|
|
|
<?php
|
|
|
|
|
2012-09-13 19:15:08 +02:00
|
|
|
final class PhabricatorChatLogQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
2012-06-02 23:00:08 +02:00
|
|
|
|
2013-02-22 15:59:17 +01:00
|
|
|
private $channelIDs;
|
2012-06-02 23:00:08 +02:00
|
|
|
private $maximumEpoch;
|
2012-02-17 19:21:38 +01:00
|
|
|
|
2013-02-22 15:59:17 +01:00
|
|
|
public function withChannelIDs(array $channel_ids) {
|
|
|
|
$this->channelIDs = $channel_ids;
|
2012-02-17 19:21:38 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-06-02 23:00:08 +02:00
|
|
|
public function withMaximumEpoch($epoch) {
|
|
|
|
$this->maximumEpoch = $epoch;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:28:02 +01:00
|
|
|
protected function loadPage() {
|
2012-03-28 01:53:47 +02:00
|
|
|
$table = new PhabricatorChatLogEvent();
|
2012-02-17 19:21:38 +01:00
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
2012-06-02 23:00:08 +02:00
|
|
|
'SELECT * FROM %T e %Q %Q %Q',
|
2012-02-17 19:21:38 +01:00
|
|
|
$table->getTableName(),
|
2012-06-02 23:00:08 +02:00
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
2012-02-17 19:21:38 +01:00
|
|
|
|
|
|
|
$logs = $table->loadAllFromArray($data);
|
|
|
|
|
Allow policy-aware queries to prefilter results
Summary:
Provides a simple way for policy-aware queries to pre-filter results without needing to maintain separate cursors, and fixes a bunch of filter-related edge cases.
- For reverse-paged cursor queries, we previously reversed each individual set of results. If the final result set is built out of multiple pages, it's in the wrong order overall, with each page in the correct order in sequence. Instead, reverse everything at the end. This also simplifies construction of queries.
- `AphrontCursorPagerView` would always render a "<< First" link when paging backward, even if we were on the first page of results.
- Add a filtering hook to let queries perform in-application pre-policy filtering as simply as possible (i.e., without maintaing their own cursors over the result sets).
Test Plan: Made feed randomly prefilter half the results, and paged forward and backward. Observed correct result ordering, pagination, and next/previous links.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D3787
2012-10-23 21:01:11 +02:00
|
|
|
return $logs;
|
2012-02-17 19:21:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function buildWhereClause($conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
2012-06-02 23:00:08 +02:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
|
|
|
if ($this->maximumEpoch) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'epoch <= %d',
|
|
|
|
$this->maximumEpoch);
|
|
|
|
}
|
|
|
|
|
2013-02-22 15:59:17 +01:00
|
|
|
if ($this->channelIDs) {
|
2012-02-17 19:21:38 +01:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2013-02-22 15:59:17 +01:00
|
|
|
'channelID IN (%Ld)',
|
|
|
|
$this->channelIDs);
|
2012-02-17 19:21:38 +01:00
|
|
|
}
|
|
|
|
|
2012-04-05 02:51:16 +02:00
|
|
|
return $this->formatWhereClause($where);
|
2012-02-17 19:21:38 +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() {
|
2013-10-22 22:47:47 +02:00
|
|
|
return 'PhabricatorApplicationChatLog';
|
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
|
|
|
}
|
|
|
|
|
2012-02-17 19:21:38 +01:00
|
|
|
}
|