Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lang/en.json6
-rw-r--r--plugins/UsersManager/Controller.php9
-rw-r--r--plugins/UsersManager/LastSeenTimeLogger.php74
-rw-r--r--plugins/UsersManager/UsersManager.php9
-rw-r--r--plugins/UsersManager/templates/index.twig6
m---------tests/PHPUnit/UI0
6 files changed, 100 insertions, 4 deletions
diff --git a/lang/en.json b/lang/en.json
index 1a42e8e49c..ef1477d6ee 100644
--- a/lang/en.json
+++ b/lang/en.json
@@ -436,7 +436,8 @@
"ViewDocumentationFor": "View documentation for %1$s",
"WellDone": "Well done!",
"All": "All",
- "Segment": "Segment"
+ "Segment": "Segment",
+ "TimeAgo": "%s ago"
},
"Actions": {
"PluginDescription": "Reports about the page views, the outlinks and downloads. Outlinks and Downloads tracking is automatic! You can also track your internal website's Search Engine.",
@@ -2218,7 +2219,8 @@
"ExceptionAccessValues": "The parameter access must have one of the following values : [ %s ]",
"ExceptionPasswordMD5HashExpected": "UsersManager.getTokenAuth is expecting a MD5-hashed password (32 chars long string). Please call the md5() function on the password before calling this method.",
"InjectedHostCannotChangePwd": "You are currently visiting with an unknown host (%1$s). You cannot change your password until this problem is fixed.",
- "EmailYourAdministrator": "%1$sE-mail your administrator about this problem%2$s."
+ "EmailYourAdministrator": "%1$sE-mail your administrator about this problem%2$s.",
+ "LastSeen": "Last seen"
},
"VisitFrequency": {
"PluginDescription": "Reports various statistics about the Returning Visitor versus the First time visitor.",
diff --git a/plugins/UsersManager/Controller.php b/plugins/UsersManager/Controller.php
index b482086767..9f3f8047b4 100644
--- a/plugins/UsersManager/Controller.php
+++ b/plugins/UsersManager/Controller.php
@@ -19,6 +19,7 @@ use Piwik\Site;
use Piwik\Tracker\IgnoreCookie;
use Piwik\Url;
use Piwik\View;
+use Piwik\MetricsFormatter;
/**
*
@@ -80,9 +81,15 @@ class Controller extends \Piwik\Plugin\ControllerAdmin
$usersAliasByLogin = array();
if (Piwik::isUserHasSomeAdminAccess()) {
+ $view->showLastSeen = true;
+
$users = APIUsersManager::getInstance()->getUsers();
- foreach ($users as $user) {
+ foreach ($users as &$user) {
$usersAliasByLogin[$user['login']] = $user['alias'];
+
+ $lastSeen = LastSeenTimeLogger::getLastSeenTimeForUser($user['login']);
+ $user['last_seen'] = $lastSeen == 0
+ ? false : MetricsFormatter::getPrettyTimeFromSeconds(time() - $lastSeen);
}
if (Piwik::hasUserSuperUserAccess()) {
diff --git a/plugins/UsersManager/LastSeenTimeLogger.php b/plugins/UsersManager/LastSeenTimeLogger.php
new file mode 100644
index 0000000000..80ae2e4cd6
--- /dev/null
+++ b/plugins/UsersManager/LastSeenTimeLogger.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik\Plugins\UsersManager;
+
+use Piwik\Piwik;
+use Piwik\Common;
+use Piwik\Option;
+
+/**
+ * Class that logs the time the current user is accessing the current resource (which
+ * is 'now') so it can be retrieved later.
+ */
+class LastSeenTimeLogger
+{
+ const OPTION_PREFIX = 'UsersManager.lastSeen.';
+
+ /**
+ * The amount of time in seconds that a last seen value is considered valid. We don't want
+ * to update the database for every request made by every user, so we only do it if the time
+ * has been at least this many seconds from the last known time.
+ */
+ const LAST_TIME_SAVE_DELTA = 300;
+
+ /**
+ * Saves the current time for a user as an option if the current request is for something
+ * in the reporting UI, the current user is not anonymous and the time hasn't been saved
+ * in the last 5 minutes.
+ */
+ public function logCurrentUserLastSeenTime()
+ {
+ $module = Common::getRequestVar('module', false);
+ $action = Common::getRequestVar('action', false);
+ $currentUserLogin = Piwik::getCurrentUserLogin();
+
+ // only log time for non-anonymous visits to the reporting UI
+ if ($module == 'API'
+ || $module == 'Proxy'
+ || $currentUserLogin == 'anonymous'
+ ) {
+ return;
+ }
+
+ // get the last known time
+ $optionName = self::OPTION_PREFIX . $currentUserLogin;
+ $lastSeen = Option::get($optionName);
+
+ // do not log if last known time is less than N minutes from now (so we don't make too many
+ // queries)
+ if ($lastSeen == 0
+ || time() - $lastSeen <= self::LAST_TIME_SAVE_DELTA
+ ) {
+ return;
+ }
+
+ // log last seen time (Note: autoload is important so the Option::get above does not result in
+ // a separate query)
+ Option::set($optionName, time(), $autoload = 1);
+ }
+
+ /**
+ * Returns the time a user was last seen or `false` if the user has never logged in.
+ */
+ public static function getLastSeenTimeForUser($userName)
+ {
+ $optionName = self::OPTION_PREFIX . $userName;
+ return Option::get($optionName);
+ }
+} \ No newline at end of file
diff --git a/plugins/UsersManager/UsersManager.php b/plugins/UsersManager/UsersManager.php
index c7aff72cb5..b16ceed54a 100644
--- a/plugins/UsersManager/UsersManager.php
+++ b/plugins/UsersManager/UsersManager.php
@@ -35,10 +35,17 @@ class UsersManager extends \Piwik\Plugin
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'SitesManager.deleteSite.end' => 'deleteSite',
'Tracker.Cache.getSiteAttributes' => 'recordAdminUsersInCache',
- 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys'
+ 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
+ 'Platform.initialized' => 'onPlatformInitialized'
);
}
+ public function onPlatformInitialized()
+ {
+ $lastSeenTimeLogger = new LastSeenTimeLogger();
+ $lastSeenTimeLogger->logCurrentUserLastSeenTime();
+ }
+
/**
* Hooks when a website tracker cache is flushed (website/user updated, cache deleted, or empty cache)
* Will record in the tracker config file the list of Admin token_auth for this website. This
diff --git a/plugins/UsersManager/templates/index.twig b/plugins/UsersManager/templates/index.twig
index 45fdeeeb40..4f943c5dfd 100644
--- a/plugins/UsersManager/templates/index.twig
+++ b/plugins/UsersManager/templates/index.twig
@@ -119,6 +119,9 @@
<th>{{ 'UsersManager_Email'|translate }}</th>
<th>{{ 'UsersManager_Alias'|translate }}</th>
<th>token_auth</th>
+ {% if showLastSeen is defined and showLastSeen %}
+ <th>{{ 'UsersManager_LastSeen'|translate }}</th>
+ {% endif %}
<th>{{ 'General_Edit'|translate }}</th>
<th>{{ 'General_Delete'|translate }}</th>
</tr>
@@ -133,6 +136,9 @@
<td id="email" class="editable">{{ user.email }}</td>
<td id="alias" class="editable">{{ user.alias|raw }}</td>
<td id="token_auth">{{ user.token_auth }}</td>
+ {% if user.last_seen is defined %}
+ <td id="last_seen">{% if user.last_seen is empty %}-{% else %}{{ 'General_TimeAgo'|translate(user.last_seen)|raw }}{% endif %}</td>
+ {% endif %}
<td>
<span class="edituser link_but" id="row{{ i }}">
<img title="{{ 'General_Edit'|translate }}" src='plugins/Zeitgeist/images/ico_edit.png'/>
diff --git a/tests/PHPUnit/UI b/tests/PHPUnit/UI
-Subproject 0141c79445887952e5d823f4f64c6a2cea83c61
+Subproject 9c277816272f93d74309c6ff1d54ec72954e386