From 5e29bd67e67275ffc27ceacca9d2e45632cf91dd Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 5 May 2021 09:59:02 +0200 Subject: [PATCH] MDL-71513 mobile: Fix last access visibility --- admin/tool/mobile/lib.php | 46 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/admin/tool/mobile/lib.php b/admin/tool/mobile/lib.php index 6b9dbf3df2a..dab02d43c35 100644 --- a/admin/tool/mobile/lib.php +++ b/admin/tool/mobile/lib.php @@ -170,32 +170,34 @@ function tool_mobile_myprofile_navigation(\core_user\output\myprofile\tree $tree } // Check if the user is using the app, encouraging him to use it otherwise. - $usertoken = tool_mobile_get_token($user->id); - $mobilestrconnected = null; - $mobilelastaccess = null; + if ($iscurrentuser || is_siteadmin()) { + $usertoken = tool_mobile_get_token($user->id); + $mobilestrconnected = null; + $mobilelastaccess = null; - if ($usertoken) { - $mobilestrconnected = get_string('lastsiteaccess'); - if ($usertoken->lastaccess) { - $mobilelastaccess = userdate($usertoken->lastaccess) . "  (" . format_time(time() - $usertoken->lastaccess) . ")"; - // Logout link. - $validtoken = empty($usertoken->validuntil) || time() < $usertoken->validuntil; - if ($iscurrentuser && $validtoken) { - $url = new moodle_url('/'.$CFG->admin.'/tool/mobile/logout.php', ['sesskey' => sesskey()]); - $logoutlink = html_writer::link($url, get_string('logout')); - $mobilelastaccess .= "  ($logoutlink)"; + if ($usertoken) { + $mobilestrconnected = get_string('lastsiteaccess'); + if ($usertoken->lastaccess) { + $mobilelastaccess = userdate($usertoken->lastaccess) . "  (" . format_time(time() - $usertoken->lastaccess) . ")"; + // Logout link. + $validtoken = empty($usertoken->validuntil) || time() < $usertoken->validuntil; + if ($iscurrentuser && $validtoken) { + $url = new moodle_url('/'.$CFG->admin.'/tool/mobile/logout.php', ['sesskey' => sesskey()]); + $logoutlink = html_writer::link($url, get_string('logout')); + $mobilelastaccess .= "  ($logoutlink)"; + } + } else { + // We should not reach this point. + $mobilelastaccess = get_string("never"); } - } else { - // We should not reach this point. - $mobilelastaccess = get_string("never"); + } else if ($url = tool_mobile_create_app_download_url()) { + $mobilestrconnected = get_string('mobileappenabled', 'tool_mobile', $url->out()); } - } else if ($url = tool_mobile_create_app_download_url()) { - $mobilestrconnected = get_string('mobileappenabled', 'tool_mobile', $url->out()); - } - if ($mobilestrconnected) { - $newnodes[] = new core_user\output\myprofile\node('mobile', 'mobileappnode', $mobilestrconnected, null, null, - $mobilelastaccess); + if ($mobilestrconnected) { + $newnodes[] = new core_user\output\myprofile\node('mobile', 'mobileappnode', $mobilestrconnected, null, null, + $mobilelastaccess); + } } // Add nodes, if any.