Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/people/view/PhabricatorUserLogView.php
12256 views
1
<?php
2
3
final class PhabricatorUserLogView extends AphrontView {
4
5
private $logs;
6
private $searchBaseURI;
7
8
public function setSearchBaseURI($search_base_uri) {
9
$this->searchBaseURI = $search_base_uri;
10
return $this;
11
}
12
13
public function setLogs(array $logs) {
14
assert_instances_of($logs, 'PhabricatorUserLog');
15
$this->logs = $logs;
16
return $this;
17
}
18
19
public function render() {
20
$logs = $this->logs;
21
$viewer = $this->getUser();
22
23
$phids = array();
24
foreach ($logs as $log) {
25
$phids[] = $log->getActorPHID();
26
$phids[] = $log->getUserPHID();
27
}
28
$handles = $viewer->loadHandles($phids);
29
30
$types = PhabricatorUserLogType::getAllLogTypes();
31
$types = mpull($types, 'getLogTypeName', 'getLogTypeKey');
32
33
$base_uri = $this->searchBaseURI;
34
35
$viewer_phid = $viewer->getPHID();
36
37
$rows = array();
38
foreach ($logs as $log) {
39
// Events such as "Login Failure" will not have an associated session.
40
$session = $log->getSession();
41
if ($session === null) {
42
$session = '';
43
}
44
$session = substr($session, 0, 6);
45
46
$actor_phid = $log->getActorPHID();
47
$user_phid = $log->getUserPHID();
48
49
$remote_address = $log->getRemoteAddressForViewer($viewer);
50
if ($remote_address !== null) {
51
if ($base_uri) {
52
$remote_address = phutil_tag(
53
'a',
54
array(
55
'href' => $base_uri.'?ip='.$remote_address.'#R',
56
),
57
$remote_address);
58
}
59
}
60
61
$action = $log->getAction();
62
$action_name = idx($types, $action, $action);
63
64
if ($actor_phid) {
65
$actor_name = $handles[$actor_phid]->renderLink();
66
} else {
67
$actor_name = null;
68
}
69
70
if ($user_phid) {
71
$user_name = $handles[$user_phid]->renderLink();
72
} else {
73
$user_name = null;
74
}
75
76
$action_link = phutil_tag(
77
'a',
78
array(
79
'href' => $log->getURI(),
80
),
81
$action_name);
82
83
$rows[] = array(
84
$log->getID(),
85
$action_link,
86
$actor_name,
87
$user_name,
88
$remote_address,
89
$session,
90
phabricator_date($log->getDateCreated(), $viewer),
91
phabricator_time($log->getDateCreated(), $viewer),
92
);
93
}
94
95
$table = new AphrontTableView($rows);
96
$table->setHeaders(
97
array(
98
pht('ID'),
99
pht('Action'),
100
pht('Actor'),
101
pht('User'),
102
pht('IP'),
103
pht('Session'),
104
pht('Date'),
105
pht('Time'),
106
));
107
$table->setColumnClasses(
108
array(
109
'',
110
'wide',
111
'',
112
'',
113
'',
114
'n',
115
'',
116
'right',
117
));
118
119
return $table;
120
}
121
}
122
123