1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-10 14:51:06 +01:00

Support export of user activity logs

Summary:
Depends on D18966. Ref T13049. Adds export support to user activity logs.

These don't have PHIDs. We could add them, but just make the "phid" column test if the objects have PHIDs or not for now.

Test Plan:
  - Exported user activity logs, got sensible output (with no PHIDs).
  - Exported some users to make sure I didn't break PHIDs, got an export with PHIDs.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13049

Differential Revision: https://secure.phabricator.com/D18967
This commit is contained in:
epriestley 2018-01-30 06:27:36 -08:00
parent 91108cf838
commit a5b8be0316
3 changed files with 119 additions and 7 deletions

View file

@ -42,8 +42,9 @@ final class PhabricatorPeopleApplication extends PhabricatorApplication {
return array(
'/people/' => array(
$this->getQueryRoutePattern() => 'PhabricatorPeopleListController',
'logs/(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorPeopleLogsController',
'logs/' => array(
$this->getQueryRoutePattern() => 'PhabricatorPeopleLogsController',
),
'invite/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorPeopleInviteListController',

View file

@ -128,4 +128,102 @@ final class PhabricatorPeopleLogSearchEngine
return id(new PhabricatorApplicationSearchResultView())
->setTable($table);
}
protected function newExportFields() {
$viewer = $this->requireViewer();
$fields = array(
$fields[] = id(new PhabricatorPHIDExportField())
->setKey('actorPHID')
->setLabel(pht('Actor PHID')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('actor')
->setLabel(pht('Actor')),
$fields[] = id(new PhabricatorPHIDExportField())
->setKey('userPHID')
->setLabel(pht('User PHID')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('user')
->setLabel(pht('User')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('action')
->setLabel(pht('Action')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('actionName')
->setLabel(pht('Action Name')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('session')
->setLabel(pht('Session')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('old')
->setLabel(pht('Old Value')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('new')
->setLabel(pht('New Value')),
);
if ($viewer->getIsAdmin()) {
$fields[] = id(new PhabricatorStringExportField())
->setKey('remoteAddress')
->setLabel(pht('Remote Address'));
}
return $fields;
}
protected function newExportData(array $logs) {
$viewer = $this->requireViewer();
$phids = array();
foreach ($logs as $log) {
$phids[] = $log->getUserPHID();
$phids[] = $log->getActorPHID();
}
$handles = $viewer->loadHandles($phids);
$action_map = PhabricatorUserLog::getActionTypeMap();
$export = array();
foreach ($logs as $log) {
$user_phid = $log->getUserPHID();
if ($user_phid) {
$user_name = $handles[$user_phid]->getName();
} else {
$user_name = null;
}
$actor_phid = $log->getActorPHID();
if ($actor_phid) {
$actor_name = $handles[$actor_phid]->getName();
} else {
$actor_name = null;
}
$action = $log->getAction();
$action_name = idx($action_map, $action, pht('Unknown ("%s")', $action));
$map = array(
'actorPHID' => $actor_phid,
'actor' => $actor_name,
'userPHID' => $user_phid,
'user' => $user_name,
'action' => $action,
'actionName' => $action_name,
'session' => substr($log->getSession(), 0, 6),
'old' => $log->getOldValue(),
'new' => $log->getNewValue(),
);
if ($viewer->getIsAdmin()) {
$map['remoteAddress'] = $log->getRemoteAddr();
}
$export[] = $map;
}
return $export;
}
}

View file

@ -1455,15 +1455,20 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
}
final public function newExportFieldList() {
$object = $this->newResultObject();
$builtin_fields = array(
id(new PhabricatorIDExportField())
->setKey('id')
->setLabel(pht('ID')),
id(new PhabricatorPHIDExportField())
->setKey('phid')
->setLabel(pht('PHID')),
);
if ($object->getConfigOption(LiskDAO::CONFIG_AUX_PHID)) {
$builtin_fields[] = id(new PhabricatorPHIDExportField())
->setKey('phid')
->setLabel(pht('PHID'));
}
$fields = mpull($builtin_fields, null, 'getKey');
$export_fields = $this->newExportFields();
@ -1507,15 +1512,23 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
}
final public function newExport(array $objects) {
$object = $this->newResultObject();
$has_phid = $object->getConfigOption(LiskDAO::CONFIG_AUX_PHID);
$objects = array_values($objects);
$n = count($objects);
$maps = array();
foreach ($objects as $object) {
$maps[] = array(
$map = array(
'id' => $object->getID(),
'phid' => $object->getPHID(),
);
if ($has_phid) {
$map['phid'] = $object->getPHID();
}
$maps[] = $map;
}
$export_data = $this->newExportData($objects);