3 final class PhabricatorUserLog
extends PhabricatorUserDAO
4 implements PhabricatorPolicyInterface
{
11 protected $details = array();
12 protected $remoteAddr;
15 public static function initializeNewLog(
16 PhabricatorUser
$actor = null,
20 $log = new PhabricatorUserLog();
23 $log->setActorPHID($actor->getPHID());
24 if ($actor->hasSession()) {
25 $session = $actor->getSession();
27 // NOTE: This is a hash of the real session value, so it's safe to
28 // store it directly in the logs.
29 $log->setSession($session->getSessionKey());
33 $log->setUserPHID((string)$object_phid);
34 $log->setAction($action);
36 $address = PhabricatorEnv
::getRemoteAddress();
38 $log->remoteAddr
= $address->getAddress();
40 $log->remoteAddr
= '';
46 public static function loadRecentEventsFromThisIP($action, $timespan) {
47 $address = PhabricatorEnv
::getRemoteAddress();
52 return id(new PhabricatorUserLog())->loadAllWhere(
53 'action = %s AND remoteAddr = %s AND dateCreated > %d
54 ORDER BY dateCreated DESC',
56 $address->getAddress(),
57 PhabricatorTime
::getNow() - $timespan);
60 public function save() {
61 $this->details
['host'] = php_uname('n');
62 $this->details
['user_agent'] = AphrontRequest
::getHTTPHeader('User-Agent');
64 return parent
::save();
67 protected function getConfiguration() {
69 self
::CONFIG_SERIALIZATION
=> array(
70 'oldValue' => self
::SERIALIZATION_JSON
,
71 'newValue' => self
::SERIALIZATION_JSON
,
72 'details' => self
::SERIALIZATION_JSON
,
74 self
::CONFIG_COLUMN_SCHEMA
=> array(
75 'actorPHID' => 'phid?',
77 'remoteAddr' => 'text64',
78 'session' => 'text64?',
80 self
::CONFIG_KEY_SCHEMA
=> array(
82 'columns' => array('actorPHID', 'dateCreated'),
85 'columns' => array('userPHID', 'dateCreated'),
88 'columns' => array('action', 'dateCreated'),
90 'dateCreated' => array(
91 'columns' => array('dateCreated'),
93 'remoteAddr' => array(
94 'columns' => array('remoteAddr', 'dateCreated'),
97 'columns' => array('session', 'dateCreated'),
100 ) + parent
::getConfiguration();
103 public function getURI() {
104 return urisprintf('/people/logs/%s/', $this->getID());
107 public function getObjectName() {
108 return pht('Activity Log %d', $this->getID());
111 public function getRemoteAddressForViewer(PhabricatorUser
$viewer) {
112 $viewer_phid = $viewer->getPHID();
113 $actor_phid = $this->getActorPHID();
114 $user_phid = $this->getUserPHID();
118 } else if ($viewer->getIsAdmin()) {
120 } else if ($viewer_phid == $actor_phid) {
121 // You can see the address if you took the action.
123 } else if (!$actor_phid && ($viewer_phid == $user_phid)) {
124 // You can see the address if it wasn't authenticated and applied
125 // to you (partial login).
128 // You can't see the address when an administrator disables your
129 // account, since it's their address.
137 return $this->getRemoteAddr();
141 /* -( PhabricatorPolicyInterface )----------------------------------------- */
144 public function getCapabilities() {
146 PhabricatorPolicyCapability
::CAN_VIEW
,
150 public function getPolicy($capability) {
151 switch ($capability) {
152 case PhabricatorPolicyCapability
::CAN_VIEW
:
153 return PhabricatorPolicies
::POLICY_NOONE
;
157 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
158 if ($viewer->getIsAdmin()) {
162 $viewer_phid = $viewer->getPHID();
164 $user_phid = $this->getUserPHID();
165 if ($viewer_phid == $user_phid) {
169 $actor_phid = $this->getActorPHID();
170 if ($viewer_phid == $actor_phid) {
178 public function describeAutomaticCapability($capability) {
180 pht('Users can view their activity and activity that affects them.'),
181 pht('Administrators can always view all activity.'),