2013-01-25 02:23:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class ConpherenceThreadQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
2013-04-19 01:56:38 +02:00
|
|
|
const TRANSACTION_LIMIT = 100;
|
2013-04-19 01:54:06 +02:00
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
private $phids;
|
|
|
|
private $ids;
|
|
|
|
private $needWidgetData;
|
2013-04-08 20:13:35 +02:00
|
|
|
private $needTransactions;
|
|
|
|
private $needParticipantCache;
|
|
|
|
private $needFilePHIDs;
|
2013-04-19 01:54:06 +02:00
|
|
|
private $afterTransactionID;
|
|
|
|
private $beforeTransactionID;
|
|
|
|
private $transactionLimit;
|
2013-02-06 23:03:52 +01:00
|
|
|
|
2013-04-08 20:13:35 +02:00
|
|
|
public function needFilePHIDs($need_file_phids) {
|
|
|
|
$this->needFilePHIDs = $need_file_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function needParticipantCache($participant_cache) {
|
|
|
|
$this->needParticipantCache = $participant_cache;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
public function needWidgetData($need_widget_data) {
|
|
|
|
$this->needWidgetData = $need_widget_data;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-04-08 20:13:35 +02:00
|
|
|
public function needTransactions($need_transactions) {
|
|
|
|
$this->needTransactions = $need_transactions;
|
2013-04-02 15:44:55 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-04-19 01:54:06 +02:00
|
|
|
public function setAfterTransactionID($id) {
|
|
|
|
$this->afterTransactionID = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setBeforeTransactionID($id) {
|
|
|
|
$this->beforeTransactionID = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTransactionLimit($transaction_limit) {
|
|
|
|
$this->transactionLimit = $transaction_limit;
|
2013-04-02 19:34:24 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-04-19 01:54:06 +02:00
|
|
|
public function getTransactionLimit() {
|
|
|
|
return $this->transactionLimit;
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:28:02 +01:00
|
|
|
protected function loadPage() {
|
2013-01-25 02:23:05 +01:00
|
|
|
$table = new ConpherenceThread();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT conpherence_thread.* FROM %T conpherence_thread %Q %Q %Q',
|
|
|
|
$table->getTableName(),
|
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
|
|
|
$conpherences = $table->loadAllFromArray($data);
|
|
|
|
|
|
|
|
if ($conpherences) {
|
|
|
|
$conpherences = mpull($conpherences, null, 'getPHID');
|
2013-04-08 20:13:35 +02:00
|
|
|
$this->loadParticipantsAndInitHandles($conpherences);
|
|
|
|
if ($this->needParticipantCache) {
|
|
|
|
$this->loadCoreHandles($conpherences, 'getRecentParticipantPHIDs');
|
|
|
|
} else if ($this->needWidgetData) {
|
|
|
|
$this->loadCoreHandles($conpherences, 'getParticipantPHIDs');
|
|
|
|
}
|
|
|
|
if ($this->needTransactions) {
|
2013-04-02 15:44:55 +02:00
|
|
|
$this->loadTransactionsAndHandles($conpherences);
|
|
|
|
}
|
2013-04-08 20:13:35 +02:00
|
|
|
if ($this->needFilePHIDs || $this->needWidgetData) {
|
|
|
|
$this->loadFilePHIDs($conpherences);
|
|
|
|
}
|
2013-01-25 02:23:05 +01:00
|
|
|
if ($this->needWidgetData) {
|
|
|
|
$this->loadWidgetData($conpherences);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $conpherences;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildWhereClause($conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
|
|
|
if ($this->ids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->phids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
2013-04-08 20:13:35 +02:00
|
|
|
private function loadParticipantsAndInitHandles(array $conpherences) {
|
2013-01-25 02:23:05 +01:00
|
|
|
$participants = id(new ConpherenceParticipant())
|
|
|
|
->loadAllWhere('conpherencePHID IN (%Ls)', array_keys($conpherences));
|
|
|
|
$map = mgroup($participants, 'getConpherencePHID');
|
2014-03-11 00:21:28 +01:00
|
|
|
|
|
|
|
foreach ($conpherences as $current_conpherence) {
|
|
|
|
$conpherence_phid = $current_conpherence->getPHID();
|
|
|
|
|
|
|
|
$conpherence_participants = idx(
|
|
|
|
$map,
|
|
|
|
$conpherence_phid,
|
|
|
|
array());
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
$conpherence_participants = mpull(
|
|
|
|
$conpherence_participants,
|
|
|
|
null,
|
2013-02-19 22:33:10 +01:00
|
|
|
'getParticipantPHID');
|
2014-03-11 00:21:28 +01:00
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
$current_conpherence->attachParticipants($conpherence_participants);
|
2013-04-08 20:13:35 +02:00
|
|
|
$current_conpherence->attachHandles(array());
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-04-08 20:13:35 +02:00
|
|
|
private function loadCoreHandles(
|
|
|
|
array $conpherences,
|
|
|
|
$method) {
|
|
|
|
|
|
|
|
$handle_phids = array();
|
|
|
|
foreach ($conpherences as $conpherence) {
|
|
|
|
$handle_phids[$conpherence->getPHID()] =
|
|
|
|
$conpherence->$method();
|
|
|
|
}
|
|
|
|
$flat_phids = array_mergev($handle_phids);
|
2013-09-11 21:27:28 +02:00
|
|
|
$handles = id(new PhabricatorHandleQuery())
|
2013-04-08 20:13:35 +02:00
|
|
|
->setViewer($this->getViewer())
|
2013-09-11 21:27:28 +02:00
|
|
|
->withPHIDs($flat_phids)
|
|
|
|
->execute();
|
2013-04-08 20:13:35 +02:00
|
|
|
foreach ($handle_phids as $conpherence_phid => $phids) {
|
|
|
|
$conpherence = $conpherences[$conpherence_phid];
|
|
|
|
$conpherence->attachHandles(array_select_keys($handles, $phids));
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
private function loadTransactionsAndHandles(array $conpherences) {
|
2013-04-19 01:54:06 +02:00
|
|
|
$query = id(new ConpherenceTransactionQuery())
|
2013-01-25 02:23:05 +01:00
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withObjectPHIDs(array_keys($conpherences))
|
2013-04-19 01:54:06 +02:00
|
|
|
->needHandles(true);
|
|
|
|
|
|
|
|
// We have to flip these for the underyling query class. The semantics of
|
|
|
|
// paging are tricky business.
|
|
|
|
if ($this->afterTransactionID) {
|
|
|
|
$query->setBeforeID($this->afterTransactionID);
|
|
|
|
} else if ($this->beforeTransactionID) {
|
|
|
|
$query->setAfterID($this->beforeTransactionID);
|
|
|
|
}
|
|
|
|
if ($this->getTransactionLimit()) {
|
|
|
|
// fetch an extra for "show older" scenarios
|
|
|
|
$query->setLimit($this->getTransactionLimit() + 1);
|
|
|
|
}
|
|
|
|
$transactions = $query->execute();
|
2013-01-25 02:23:05 +01:00
|
|
|
$transactions = mgroup($transactions, 'getObjectPHID');
|
|
|
|
foreach ($conpherences as $phid => $conpherence) {
|
2014-03-11 00:21:28 +01:00
|
|
|
$current_transactions = idx($transactions, $phid, array());
|
2013-01-25 02:23:05 +01:00
|
|
|
$handles = array();
|
|
|
|
foreach ($current_transactions as $transaction) {
|
|
|
|
$handles += $transaction->getHandles();
|
|
|
|
}
|
2013-04-08 20:13:35 +02:00
|
|
|
$conpherence->attachHandles($conpherence->getHandles() + $handles);
|
2014-03-11 00:21:28 +01:00
|
|
|
$conpherence->attachTransactions($current_transactions);
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function loadFilePHIDs(array $conpherences) {
|
|
|
|
$edge_type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_FILE;
|
|
|
|
$file_edges = id(new PhabricatorEdgeQuery())
|
|
|
|
->withSourcePHIDs(array_keys($conpherences))
|
|
|
|
->withEdgeTypes(array($edge_type))
|
|
|
|
->execute();
|
|
|
|
foreach ($file_edges as $conpherence_phid => $data) {
|
|
|
|
$conpherence = $conpherences[$conpherence_phid];
|
|
|
|
$conpherence->attachFilePHIDs(array_keys($data[$edge_type]));
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function loadWidgetData(array $conpherences) {
|
|
|
|
$participant_phids = array();
|
|
|
|
$file_phids = array();
|
|
|
|
foreach ($conpherences as $conpherence) {
|
|
|
|
$participant_phids[] = array_keys($conpherence->getParticipants());
|
|
|
|
$file_phids[] = $conpherence->getFilePHIDs();
|
|
|
|
}
|
|
|
|
$participant_phids = array_mergev($participant_phids);
|
|
|
|
$file_phids = array_mergev($file_phids);
|
|
|
|
|
2014-02-25 22:43:31 +01:00
|
|
|
$epochs = CalendarTimeUtil::getCalendarEventEpochs(
|
2013-06-04 00:40:00 +02:00
|
|
|
$this->getViewer());
|
|
|
|
$start_epoch = $epochs['start_epoch'];
|
|
|
|
$end_epoch = $epochs['end_epoch'];
|
2014-02-06 19:07:42 +01:00
|
|
|
$statuses = id(new PhabricatorCalendarEventQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withInvitedPHIDs($participant_phids)
|
|
|
|
->withDateRange($start_epoch, $end_epoch)
|
|
|
|
->execute();
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
$statuses = mgroup($statuses, 'getUserPHID');
|
|
|
|
|
|
|
|
// attached files
|
|
|
|
$files = array();
|
2013-03-16 07:41:36 +01:00
|
|
|
$file_author_phids = array();
|
|
|
|
$authors = array();
|
2013-01-25 02:23:05 +01:00
|
|
|
if ($file_phids) {
|
|
|
|
$files = id(new PhabricatorFileQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs($file_phids)
|
|
|
|
->execute();
|
|
|
|
$files = mpull($files, null, 'getPHID');
|
2013-03-16 07:41:36 +01:00
|
|
|
$file_author_phids = mpull($files, 'getAuthorPHID', 'getPHID');
|
2013-09-11 21:27:28 +02:00
|
|
|
$authors = id(new PhabricatorHandleQuery())
|
2013-03-16 07:41:36 +01:00
|
|
|
->setViewer($this->getViewer())
|
2013-09-11 21:27:28 +02:00
|
|
|
->withPHIDs($file_author_phids)
|
|
|
|
->execute();
|
2013-03-16 07:41:36 +01:00
|
|
|
$authors = mpull($authors, null, 'getPHID');
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($conpherences as $phid => $conpherence) {
|
|
|
|
$participant_phids = array_keys($conpherence->getParticipants());
|
2013-02-05 04:01:46 +01:00
|
|
|
$statuses = array_select_keys($statuses, $participant_phids);
|
|
|
|
$statuses = array_mergev($statuses);
|
|
|
|
$statuses = msort($statuses, 'getDateFrom');
|
2013-03-16 07:41:36 +01:00
|
|
|
|
|
|
|
$conpherence_files = array();
|
|
|
|
$files_authors = array();
|
|
|
|
foreach ($conpherence->getFilePHIDs() as $curr_phid) {
|
2013-03-17 22:36:22 +01:00
|
|
|
$curr_file = idx($files, $curr_phid);
|
|
|
|
if (!$curr_file) {
|
|
|
|
// this file was deleted or user doesn't have permission to see it
|
|
|
|
// this is generally weird
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$conpherence_files[$curr_phid] = $curr_file;
|
2013-03-16 07:41:36 +01:00
|
|
|
// some files don't have authors so be careful
|
|
|
|
$current_author = null;
|
|
|
|
$current_author_phid = idx($file_author_phids, $curr_phid);
|
|
|
|
if ($current_author_phid) {
|
|
|
|
$current_author = $authors[$current_author_phid];
|
|
|
|
}
|
|
|
|
$files_authors[$curr_phid] = $current_author;
|
|
|
|
}
|
2013-01-25 02:23:05 +01:00
|
|
|
$widget_data = array(
|
2013-02-05 04:01:46 +01:00
|
|
|
'statuses' => $statuses,
|
2013-03-16 07:41:36 +01:00
|
|
|
'files' => $conpherence_files,
|
2014-10-07 15:01:04 +02:00
|
|
|
'files_authors' => $files_authors,
|
2013-01-25 02:23:05 +01:00
|
|
|
);
|
|
|
|
$conpherence->attachWidgetData($widget_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
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 'PhabricatorConpherenceApplication';
|
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-01-25 02:23:05 +01:00
|
|
|
}
|