From 46ef76266a921025979a72b6b9419b76dcea5ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Sat, 22 Sep 2018 17:55:53 -0400 Subject: [PATCH] Allow admins to see last online text (#1540) * Allow admins to see last online text * Use viewLastSeenAt permission * Move permission to UserSerializer, removed from ForumSerializer * Remove extra comma from ForumSerializer to keep diff clean * Add permission to new seed migration --- framework/core/js/src/admin/components/PermissionGrid.js | 6 ++++++ .../2018_07_21_000100_seed_default_group_permissions.php | 1 + framework/core/src/Api/Serializer/UserSerializer.php | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/framework/core/js/src/admin/components/PermissionGrid.js b/framework/core/js/src/admin/components/PermissionGrid.js index 591141389..951ed4533 100644 --- a/framework/core/js/src/admin/components/PermissionGrid.js +++ b/framework/core/js/src/admin/components/PermissionGrid.js @@ -110,6 +110,12 @@ export default class PermissionGrid extends Component { }) }, 90); + items.add('viewLastSeenAt', { + icon: 'far fa-clock', + label: app.translator.trans('core.admin.permissions.view_last_seen_at_label'), + permission: 'user.viewLastSeenAt', + }); + return items; } diff --git a/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php b/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php index 5a82d70fe..acdbfd604 100644 --- a/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php +++ b/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php @@ -27,6 +27,7 @@ $rows = [ ['permission' => 'discussion.hidePosts', 'group_id' => Group::MODERATOR_ID], ['permission' => 'discussion.rename', 'group_id' => Group::MODERATOR_ID], ['permission' => 'discussion.viewIpsPosts', 'group_id' => Group::MODERATOR_ID], + ['permission' => 'user.viewLastSeenAt', 'group_id' => Group::MODERATOR_ID], ]; return [ diff --git a/framework/core/src/Api/Serializer/UserSerializer.php b/framework/core/src/Api/Serializer/UserSerializer.php index 95792699d..d84e01d47 100644 --- a/framework/core/src/Api/Serializer/UserSerializer.php +++ b/framework/core/src/Api/Serializer/UserSerializer.php @@ -48,7 +48,7 @@ class UserSerializer extends BasicUserSerializer 'canDelete' => $gate->allows('delete', $user), ]; - if ($user->getPreference('discloseOnline')) { + if ($user->getPreference('discloseOnline') || $this->actor->can('viewLastSeenAt', $user)) { $attributes += [ 'lastSeenAt' => $this->formatDate($user->last_seen_at) ];