Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/query/PhabricatorPeopleLogSearchEngine.php
| Show All 9 Lines | final class PhabricatorPeopleLogSearchEngine | ||||
| public function getApplicationClassName() { | public function getApplicationClassName() { | ||||
| return 'PhabricatorPeopleApplication'; | return 'PhabricatorPeopleApplication'; | ||||
| } | } | ||||
| public function getPageSize(PhabricatorSavedQuery $saved) { | public function getPageSize(PhabricatorSavedQuery $saved) { | ||||
| return 500; | return 500; | ||||
| } | } | ||||
| public function buildSavedQueryFromRequest(AphrontRequest $request) { | public function newQuery() { | ||||
| $saved = new PhabricatorSavedQuery(); | $query = new PhabricatorPeopleLogQuery(); | ||||
| $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()); | |||||
| // NOTE: If the viewer isn't an administrator, always restrict the query to | // 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 | // related records. This echoes the policy logic of these logs. This is | ||||
| // mostly a performance optimization, to prevent us from having to pull | // 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 | // large numbers of logs that the user will not be able to see and filter | ||||
| // them in-process. | // them in-process. | ||||
| $viewer = $this->requireViewer(); | $viewer = $this->requireViewer(); | ||||
| if (!$viewer->getIsAdmin()) { | if (!$viewer->getIsAdmin()) { | ||||
| $query->withRelatedPHIDs(array($viewer->getPHID())); | $query->withRelatedPHIDs(array($viewer->getPHID())); | ||||
| } | } | ||||
| $actor_phids = $saved->getParameter('actorPHIDs', array()); | return $query; | ||||
| if ($actor_phids) { | } | ||||
| $query->withActorPHIDs($actor_phids); | |||||
| protected function buildQueryFromParameters(array $map) { | |||||
| $query = $this->newQuery(); | |||||
| if ($map['userPHIDs']) { | |||||
| $query->withUserPHIDs($map['userPHIDs']); | |||||
| } | } | ||||
| $user_phids = $saved->getParameter('userPHIDs', array()); | if ($map['actorPHIDs']) { | ||||
| if ($user_phids) { | $query->withActorPHIDs($map['actorPHIDs']); | ||||
| $query->withUserPHIDs($user_phids); | |||||
| } | } | ||||
| $actions = $saved->getParameter('actions', array()); | if ($map['actions']) { | ||||
| if ($actions) { | $query->withActions($map['actions']); | ||||
| $query->withActions($actions); | |||||
| } | } | ||||
| $remote_prefix = $saved->getParameter('ip'); | if (strlen($map['ip'])) { | ||||
| if (strlen($remote_prefix)) { | $query->withRemoteAddressPrefix($map['ip']); | ||||
| $query->withRemoteAddressprefix($remote_prefix); | |||||
| } | } | ||||
| $sessions = $saved->getParameter('sessions', array()); | if ($map['sessions']) { | ||||
| if ($sessions) { | $query->withSessionKeys($map['sessions']); | ||||
| $query->withSessionKeys($sessions); | |||||
| } | } | ||||
| return $query; | return $query; | ||||
| } | } | ||||
| public function buildSearchForm( | protected function buildCustomSearchFields() { | ||||
| AphrontFormView $form, | return array( | ||||
| PhabricatorSavedQuery $saved) { | id(new PhabricatorUsersSearchField()) | ||||
| ->setKey('userPHIDs') | |||||
| $actor_phids = $saved->getParameter('actorPHIDs', array()); | ->setAliases(array('users', 'user', 'userPHID')) | ||||
| $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 | |||||
| ->appendControl( | |||||
| id(new AphrontFormTokenizerControl()) | |||||
| ->setDatasource(new PhabricatorPeopleDatasource()) | |||||
| ->setName('actors') | |||||
| ->setLabel(pht('Actors')) | |||||
| ->setValue($actor_phids)) | |||||
| ->appendControl( | |||||
| id(new AphrontFormTokenizerControl()) | |||||
| ->setDatasource(new PhabricatorPeopleDatasource()) | |||||
| ->setName('users') | |||||
| ->setLabel(pht('Users')) | ->setLabel(pht('Users')) | ||||
| ->setValue($user_phids)) | ->setDescription(pht('Search for activity affecting specific users.')), | ||||
| ->appendChild($action_control) | id(new PhabricatorUsersSearchField()) | ||||
| ->appendChild( | ->setKey('actorPHIDs') | ||||
| id(new AphrontFormTextControl()) | ->setAliases(array('actors', 'actor', 'actorPHID')) | ||||
| ->setLabel(pht('Actors')) | |||||
| ->setDescription(pht('Search for activity by specific users.')), | |||||
| id(new PhabricatorSearchCheckboxesField()) | |||||
| ->setKey('actions') | |||||
| ->setLabel(pht('Actions')) | |||||
| ->setDescription(pht('Search for particular types of activity.')) | |||||
| ->setOptions(PhabricatorUserLog::getActionTypeMap()), | |||||
| id(new PhabricatorSearchTextField()) | |||||
| ->setKey('ip') | |||||
| ->setLabel(pht('Filter IP')) | ->setLabel(pht('Filter IP')) | ||||
| ->setName('ip') | ->setDescription(pht('Search for actions by remote address.')), | ||||
| ->setValue($remote_prefix)) | id(new PhabricatorSearchStringListField()) | ||||
| ->appendChild( | ->setKey('sessions') | ||||
| id(new AphrontFormTextControl()) | |||||
| ->setLabel(pht('Sessions')) | ->setLabel(pht('Sessions')) | ||||
| ->setName('sessions') | ->setDescription(pht('Search for activity in particular sessions.')), | ||||
| ->setValue(implode(', ', $sessions))); | ); | ||||
| } | } | ||||
| protected function getURI($path) { | protected function getURI($path) { | ||||
| return '/people/logs/'.$path; | return '/people/logs/'.$path; | ||||
| } | } | ||||
| protected function getBuiltinQueryNames() { | protected function getBuiltinQueryNames() { | ||||
| $names = array( | $names = array( | ||||
| Show All 10 Lines | public function buildSavedQueryFromBuiltin($query_key) { | ||||
| switch ($query_key) { | switch ($query_key) { | ||||
| case 'all': | case 'all': | ||||
| return $query; | return $query; | ||||
| } | } | ||||
| return parent::buildSavedQueryFromBuiltin($query_key); | return parent::buildSavedQueryFromBuiltin($query_key); | ||||
| } | } | ||||
| 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( | protected function renderResultList( | ||||
| array $logs, | array $logs, | ||||
| PhabricatorSavedQuery $query, | PhabricatorSavedQuery $query, | ||||
| array $handles) { | array $handles) { | ||||
| assert_instances_of($logs, 'PhabricatorUserLog'); | assert_instances_of($logs, 'PhabricatorUserLog'); | ||||
| $viewer = $this->requireViewer(); | $viewer = $this->requireViewer(); | ||||
| $table = id(new PhabricatorUserLogView()) | $table = id(new PhabricatorUserLogView()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setLogs($logs) | ->setLogs($logs); | ||||
| ->setHandles($handles); | |||||
| if ($viewer->getIsAdmin()) { | if ($viewer->getIsAdmin()) { | ||||
| $table->setSearchBaseURI($this->getApplicationURI('logs/')); | $table->setSearchBaseURI($this->getApplicationURI('logs/')); | ||||
| } | } | ||||
| $result = new PhabricatorApplicationSearchResultView(); | return id(new PhabricatorApplicationSearchResultView()) | ||||
| $result->setTable($table); | ->setTable($table); | ||||
| return $result; | |||||
| } | } | ||||
| } | } | ||||