mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
Upgrade user account activity logs to modern construction
Summary: Depends on D18965. Ref T13049. Move this Query and SearchEngine to be a little more modern, to prepare for Export support. Test Plan: - Used all the query fields, viewed activity logs via People and Settings. - I'm not sure the "Session" query is used/useful and may remove it before I'm done here, but I just left it in place for now. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13049 Differential Revision: https://secure.phabricator.com/D18966
This commit is contained in:
parent
b27fd05eef
commit
91108cf838
4 changed files with 71 additions and 145 deletions
|
@ -40,70 +40,61 @@ final class PhabricatorPeopleLogQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$table = new PhabricatorUserLog();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T %Q %Q %Q',
|
||||
$table->getTableName(),
|
||||
$this->buildWhereClause($conn_r),
|
||||
$this->buildOrderClause($conn_r),
|
||||
$this->buildLimitClause($conn_r));
|
||||
|
||||
return $table->loadAllFromArray($data);
|
||||
public function newResultObject() {
|
||||
return new PhabricatorUserLog();
|
||||
}
|
||||
|
||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
protected function loadPage() {
|
||||
return $this->loadStandardPage($this->newResultObject());
|
||||
}
|
||||
|
||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||
$where = parent::buildWhereClauseParts($conn);
|
||||
|
||||
if ($this->actorPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'actorPHID IN (%Ls)',
|
||||
$this->actorPHIDs);
|
||||
}
|
||||
|
||||
if ($this->userPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'userPHID IN (%Ls)',
|
||||
$this->userPHIDs);
|
||||
}
|
||||
|
||||
if ($this->relatedPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'actorPHID IN (%Ls) OR userPHID IN (%Ls)',
|
||||
$conn,
|
||||
'(actorPHID IN (%Ls) OR userPHID IN (%Ls))',
|
||||
$this->relatedPHIDs,
|
||||
$this->relatedPHIDs);
|
||||
}
|
||||
|
||||
if ($this->sessionKeys !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'session IN (%Ls)',
|
||||
$this->sessionKeys);
|
||||
}
|
||||
|
||||
if ($this->actions !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'action IN (%Ls)',
|
||||
$this->actions);
|
||||
}
|
||||
|
||||
if ($this->remoteAddressPrefix !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'remoteAddr LIKE %>',
|
||||
$this->remoteAddressPrefix);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
return $where;
|
||||
}
|
||||
|
||||
public function getQueryApplicationClass() {
|
||||
|
|
|
@ -15,34 +15,8 @@ final class PhabricatorPeopleLogSearchEngine
|
|||
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());
|
||||
public function newQuery() {
|
||||
$query = new PhabricatorPeopleLogQuery();
|
||||
|
||||
// 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
|
||||
|
@ -54,82 +28,61 @@ final class PhabricatorPeopleLogSearchEngine
|
|||
$query->withRelatedPHIDs(array($viewer->getPHID()));
|
||||
}
|
||||
|
||||
$actor_phids = $saved->getParameter('actorPHIDs', array());
|
||||
if ($actor_phids) {
|
||||
$query->withActorPHIDs($actor_phids);
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function buildQueryFromParameters(array $map) {
|
||||
$query = $this->newQuery();
|
||||
|
||||
if ($map['userPHIDs']) {
|
||||
$query->withUserPHIDs($map['userPHIDs']);
|
||||
}
|
||||
|
||||
$user_phids = $saved->getParameter('userPHIDs', array());
|
||||
if ($user_phids) {
|
||||
$query->withUserPHIDs($user_phids);
|
||||
if ($map['actorPHIDs']) {
|
||||
$query->withActorPHIDs($map['actorPHIDs']);
|
||||
}
|
||||
|
||||
$actions = $saved->getParameter('actions', array());
|
||||
if ($actions) {
|
||||
$query->withActions($actions);
|
||||
if ($map['actions']) {
|
||||
$query->withActions($map['actions']);
|
||||
}
|
||||
|
||||
$remote_prefix = $saved->getParameter('ip');
|
||||
if (strlen($remote_prefix)) {
|
||||
$query->withRemoteAddressprefix($remote_prefix);
|
||||
if (strlen($map['ip'])) {
|
||||
$query->withRemoteAddressPrefix($map['ip']);
|
||||
}
|
||||
|
||||
$sessions = $saved->getParameter('sessions', array());
|
||||
if ($sessions) {
|
||||
$query->withSessionKeys($sessions);
|
||||
if ($map['sessions']) {
|
||||
$query->withSessionKeys($map['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
|
||||
->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'))
|
||||
->setValue($user_phids))
|
||||
->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 buildCustomSearchFields() {
|
||||
return array(
|
||||
id(new PhabricatorUsersSearchField())
|
||||
->setKey('userPHIDs')
|
||||
->setAliases(array('users', 'user', 'userPHID'))
|
||||
->setLabel(pht('Users'))
|
||||
->setDescription(pht('Search for activity affecting specific users.')),
|
||||
id(new PhabricatorUsersSearchField())
|
||||
->setKey('actorPHIDs')
|
||||
->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'))
|
||||
->setDescription(pht('Search for actions by remote address.')),
|
||||
id(new PhabricatorSearchStringListField())
|
||||
->setKey('sessions')
|
||||
->setLabel(pht('Sessions'))
|
||||
->setDescription(pht('Search for activity in particular sessions.')),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
|
@ -156,19 +109,6 @@ final class PhabricatorPeopleLogSearchEngine
|
|||
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(
|
||||
array $logs,
|
||||
PhabricatorSavedQuery $query,
|
||||
|
@ -179,16 +119,13 @@ final class PhabricatorPeopleLogSearchEngine
|
|||
|
||||
$table = id(new PhabricatorUserLogView())
|
||||
->setUser($viewer)
|
||||
->setLogs($logs)
|
||||
->setHandles($handles);
|
||||
->setLogs($logs);
|
||||
|
||||
if ($viewer->getIsAdmin()) {
|
||||
$table->setSearchBaseURI($this->getApplicationURI('logs/'));
|
||||
}
|
||||
|
||||
$result = new PhabricatorApplicationSearchResultView();
|
||||
$result->setTable($table);
|
||||
|
||||
return $result;
|
||||
return id(new PhabricatorApplicationSearchResultView())
|
||||
->setTable($table);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
final class PhabricatorUserLogView extends AphrontView {
|
||||
|
||||
private $logs;
|
||||
private $handles;
|
||||
private $searchBaseURI;
|
||||
|
||||
public function setSearchBaseURI($search_base_uri) {
|
||||
|
@ -17,17 +16,17 @@ final class PhabricatorUserLogView extends AphrontView {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setHandles(array $handles) {
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
$this->handles = $handles;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$logs = $this->logs;
|
||||
$handles = $this->handles;
|
||||
$viewer = $this->getUser();
|
||||
|
||||
$phids = array();
|
||||
foreach ($logs as $log) {
|
||||
$phids[] = $log->getActorPHID();
|
||||
$phids[] = $log->getUserPHID();
|
||||
}
|
||||
$handles = $viewer->loadHandles($phids);
|
||||
|
||||
$action_map = PhabricatorUserLog::getActionTypeMap();
|
||||
$base_uri = $this->searchBaseURI;
|
||||
|
||||
|
|
|
@ -43,8 +43,7 @@ final class PhabricatorActivitySettingsPanel extends PhabricatorSettingsPanel {
|
|||
|
||||
$table = id(new PhabricatorUserLogView())
|
||||
->setUser($viewer)
|
||||
->setLogs($logs)
|
||||
->setHandles($handles);
|
||||
->setLogs($logs);
|
||||
|
||||
$panel = $this->newBox(pht('Account Activity Logs'), $table);
|
||||
|
||||
|
|
Loading…
Reference in a new issue