2014-04-28 02:31:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorPeopleLogSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
2014-06-12 22:22:20 +02:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Account Activity');
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:47:48 +01:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorPeopleApplication';
|
2014-05-16 04:17:02 +02:00
|
|
|
}
|
|
|
|
|
2014-04-28 02:31:35 +02:00
|
|
|
public function getPageSize(PhabricatorSavedQuery $saved) {
|
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'userPHIDs',
|
|
|
|
$this->readUsersFromRequest($request, 'users'));
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'actorPHIDs',
|
|
|
|
$this->readUsersFromRequest($request, 'actors'));
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'actions',
|
|
|
|
$this->readListFromRequest($request, 'actions'));
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'ip',
|
|
|
|
$request->getStr('ip'));
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'sessions',
|
|
|
|
$this->readListFromRequest($request, 'sessions'));
|
|
|
|
|
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
$query = id(new PhabricatorPeopleLogQuery());
|
|
|
|
|
2014-05-16 04:17:02 +02:00
|
|
|
// NOTE: If the viewer isn't an administrator, always restrict the query to
|
|
|
|
// related records. This echoes the policy logic of these logs. This is
|
|
|
|
// mostly a performance optimization, to prevent us from having to pull
|
|
|
|
// large numbers of logs that the user will not be able to see and filter
|
|
|
|
// them in-process.
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
if (!$viewer->getIsAdmin()) {
|
|
|
|
$query->withRelatedPHIDs(array($viewer->getPHID()));
|
|
|
|
}
|
|
|
|
|
2014-04-28 02:31:35 +02:00
|
|
|
$actor_phids = $saved->getParameter('actorPHIDs', array());
|
|
|
|
if ($actor_phids) {
|
|
|
|
$query->withActorPHIDs($actor_phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$user_phids = $saved->getParameter('userPHIDs', array());
|
|
|
|
if ($user_phids) {
|
|
|
|
$query->withUserPHIDs($user_phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$actions = $saved->getParameter('actions', array());
|
|
|
|
if ($actions) {
|
|
|
|
$query->withActions($actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
$remote_prefix = $saved->getParameter('ip');
|
|
|
|
if (strlen($remote_prefix)) {
|
|
|
|
$query->withRemoteAddressprefix($remote_prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
$sessions = $saved->getParameter('sessions', array());
|
|
|
|
if ($sessions) {
|
|
|
|
$query->withSessionKeys($sessions);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
|
|
|
PhabricatorSavedQuery $saved) {
|
|
|
|
|
|
|
|
$actor_phids = $saved->getParameter('actorPHIDs', array());
|
|
|
|
$user_phids = $saved->getParameter('userPHIDs', array());
|
|
|
|
|
|
|
|
$actions = $saved->getParameter('actions', array());
|
|
|
|
$remote_prefix = $saved->getParameter('ip');
|
|
|
|
$sessions = $saved->getParameter('sessions', array());
|
|
|
|
|
|
|
|
$actions = array_fuse($actions);
|
|
|
|
$action_control = id(new AphrontFormCheckboxControl())
|
|
|
|
->setLabel(pht('Actions'));
|
|
|
|
$action_types = PhabricatorUserLog::getActionTypeMap();
|
|
|
|
foreach ($action_types as $type => $label) {
|
|
|
|
$action_control->addCheckbox(
|
|
|
|
'actions[]',
|
|
|
|
$type,
|
|
|
|
$label,
|
|
|
|
isset($actions[$label]));
|
|
|
|
}
|
|
|
|
|
|
|
|
$form
|
2015-03-31 23:10:55 +02:00
|
|
|
->appendControl(
|
2014-04-28 02:31:35 +02:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:44:18 +02:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
2014-04-28 02:31:35 +02:00
|
|
|
->setName('actors')
|
|
|
|
->setLabel(pht('Actors'))
|
2015-03-31 23:10:55 +02:00
|
|
|
->setValue($actor_phids))
|
|
|
|
->appendControl(
|
2014-04-28 02:31:35 +02:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:44:18 +02:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
2014-04-28 02:31:35 +02:00
|
|
|
->setName('users')
|
|
|
|
->setLabel(pht('Users'))
|
2015-03-31 23:10:55 +02:00
|
|
|
->setValue($user_phids))
|
2014-04-28 02:31:35 +02:00
|
|
|
->appendChild($action_control)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Filter IP'))
|
|
|
|
->setName('ip')
|
|
|
|
->setValue($remote_prefix))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Sessions'))
|
|
|
|
->setName('sessions')
|
|
|
|
->setValue(implode(', ', $sessions)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/people/logs/'.$path;
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:34:51 +01:00
|
|
|
protected function getBuiltinQueryNames() {
|
2014-04-28 02:31:35 +02:00
|
|
|
$names = array(
|
|
|
|
'all' => pht('All'),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'all':
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
2014-05-16 04:17:02 +02:00
|
|
|
protected function getRequiredHandlePHIDsForResultList(
|
|
|
|
array $logs,
|
|
|
|
PhabricatorSavedQuery $query) {
|
|
|
|
|
|
|
|
$phids = array();
|
|
|
|
foreach ($logs as $log) {
|
|
|
|
$phids[$log->getActorPHID()] = true;
|
|
|
|
$phids[$log->getUserPHID()] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_keys($phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderResultList(
|
|
|
|
array $logs,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
assert_instances_of($logs, 'PhabricatorUserLog');
|
|
|
|
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
|
|
|
$table = id(new PhabricatorUserLogView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setLogs($logs)
|
|
|
|
->setHandles($handles);
|
|
|
|
|
|
|
|
if ($viewer->getIsAdmin()) {
|
|
|
|
$table->setSearchBaseURI($this->getApplicationURI('logs/'));
|
|
|
|
}
|
|
|
|
|
2015-06-19 12:46:20 +02:00
|
|
|
$result = new PhabricatorApplicationSearchResultView();
|
2015-06-29 21:28:55 +02:00
|
|
|
$result->setTable($table);
|
2015-06-19 12:46:20 +02:00
|
|
|
|
|
|
|
return $result;
|
2014-05-16 04:17:02 +02:00
|
|
|
}
|
2014-04-28 02:31:35 +02:00
|
|
|
}
|