1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-21 13:00:56 +01:00

Move activity log rendering to a dashboard panel

Summary:
Ref T4986. Swap this in. Two minor notes:

  - I adjusted the SearchEngine to add an additional constraint when the viewer isn't an admin. This mostly stops us from doing a bunch of unnecessary work.
  - I fixed the settings panel to paginate (currently loads all results, slow in production).

Test Plan: Viewed logs; viewed settings panel; created a dashboard panel.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4986

Differential Revision: https://secure.phabricator.com/D9136
This commit is contained in:
epriestley 2014-05-15 19:17:02 -07:00
parent 6300955661
commit e6f6a58f93
3 changed files with 59 additions and 32 deletions

View file

@ -1,7 +1,7 @@
<?php
final class PhabricatorPeopleLogsController extends PhabricatorPeopleController
implements PhabricatorApplicationSearchResultsControllerInterface {
final class PhabricatorPeopleLogsController
extends PhabricatorPeopleController {
private $queryKey;
@ -19,34 +19,6 @@ final class PhabricatorPeopleLogsController extends PhabricatorPeopleController
return $this->delegateToController($controller);
}
public function renderResultsList(
array $logs,
PhabricatorSavedQuery $query) {
assert_instances_of($logs, 'PhabricatorUserLog');
$request = $this->getRequest();
$viewer = $request->getUser();
$phids = array();
foreach ($logs as $log) {
$phids[$log->getActorPHID()] = true;
$phids[$log->getUserPHID()] = true;
}
$phids = array_keys($phids);
$handles = $this->loadViewerHandles($phids);
$table = id(new PhabricatorUserLogView())
->setUser($viewer)
->setLogs($logs)
->setSearchBaseURI($this->getApplicationURI('logs/'))
->setHandles($handles);
return id(new PHUIObjectBoxView())
->setHeaderText(pht('User Activity Logs'))
->appendChild($table);
}
public function buildSideNavView() {
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));

View file

@ -3,6 +3,10 @@
final class PhabricatorPeopleLogSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getApplicationClassName() {
return 'PhabricatorApplicationPeople';
}
public function getPageSize(PhabricatorSavedQuery $saved) {
return 500;
}
@ -36,6 +40,16 @@ final class PhabricatorPeopleLogSearchEngine
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(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
// 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()));
}
$actor_phids = $saved->getParameter('actorPHIDs', array());
if ($actor_phids) {
$query->withActorPHIDs($actor_phids);
@ -154,4 +168,38 @@ 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,
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/'));
}
return id(new PHUIObjectBoxView())
->setHeaderText(pht('User Activity Logs'))
->appendChild($table);
}
}

View file

@ -27,10 +27,13 @@ final class PhabricatorSettingsPanelActivity
$viewer = $request->getUser();
$user = $this->getUser();
$pager = id(new AphrontCursorPagerView())
->readFromRequest($request);
$logs = id(new PhabricatorPeopleLogQuery())
->setViewer($viewer)
->withRelatedPHIDs(array($user->getPHID()))
->execute();
->executeWithCursorPager($pager);
$phids = array();
foreach ($logs as $log) {
@ -56,7 +59,11 @@ final class PhabricatorSettingsPanelActivity
->setHeaderText(pht('Account Activity Logs'))
->appendChild($table);
return $panel;
$pager_box = id(new PHUIBoxView())
->addMargin(PHUI::MARGIN_LARGE)
->appendChild($pager);
return array($panel, $pager_box);
}
}