Merge branch 'MDL-64745-master-1' of git://github.com/mihailges/moodle

This commit is contained in:
Jake Dallimore
2019-10-09 15:58:50 +08:00
9 changed files with 214 additions and 26 deletions
+9 -7
View File
@@ -129,14 +129,16 @@ class block_online_users extends block_base {
$this->content->text .= $OUTPUT->user_picture($user, array('size'=>16, 'alttext'=>false, 'link'=>false)) .$user->fullname.'</a></div>';
if ($USER->id == $user->id) {
$action = ($user->uservisibility != null && $user->uservisibility == 0) ? 'show' : 'hide';
$anchortagcontents = $OUTPUT->pix_icon('t/' . $action,
get_string('online_status:' . $action, 'block_online_users'));
$anchortag = html_writer::link("", $anchortagcontents,
array('title' => get_string('online_status:' . $action, 'block_online_users'),
'data-action' => $action, 'data-userid' => $user->id, 'id' => 'change-user-visibility'));
if ($CFG->block_online_users_onlinestatushiding) {
$action = ($user->uservisibility != null && $user->uservisibility == 0) ? 'show' : 'hide';
$anchortagcontents = $OUTPUT->pix_icon('t/' . $action,
get_string('online_status:' . $action, 'block_online_users'));
$anchortag = html_writer::link("", $anchortagcontents,
array('title' => get_string('online_status:' . $action, 'block_online_users'),
'data-action' => $action, 'data-userid' => $user->id, 'id' => 'change-user-visibility'));
$this->content->text .= '<div class="uservisibility">' . $anchortag . '</div>';
$this->content->text .= '<div class="uservisibility">' . $anchortag . '</div>';
}
} else {
if ($canshowicon) { // Only when logged in and messaging active etc.
$anchortagcontents = $OUTPUT->pix_icon('t/message', get_string('messageselectadd'));
+16 -15
View File
@@ -67,7 +67,7 @@ class fetcher {
* @param int $courseid The course id to check
*/
protected function set_sql($currentgroup, $now, $timetoshowusers, $context, $sitelevel, $courseid) {
global $USER, $DB;
global $USER, $DB, $CFG;
$timefrom = 100 * floor(($now - $timetoshowusers) / 100); // Round to nearest 100 seconds for better query cache.
@@ -76,7 +76,14 @@ class fetcher {
$groupby = "";
$lastaccess = ", lastaccess";
$timeaccess = ", ul.timeaccess AS lastaccess";
$uservisibility = ", up.value AS uservisibility";
$uservisibility = "";
$uservisibilityselect = "";
if ($CFG->block_online_users_onlinestatushiding) {
$uservisibility = ", up.value AS uservisibility";
$uservisibilityselect = "AND (" . $DB->sql_cast_char2int('up.value') . " = 1
OR up.value IS NULL
OR u.id = :userid)";
}
$params = array();
$userfields = \user_picture::fields('u', array('username'));
@@ -88,7 +95,9 @@ class fetcher {
$groupby = "GROUP BY $userfields";
$lastaccess = ", MAX(u.lastaccess) AS lastaccess";
$timeaccess = ", MAX(ul.timeaccess) AS lastaccess";
$uservisibility = ", MAX(up.value) AS uservisibility";
if ($CFG->block_online_users_onlinestatushiding) {
$uservisibility = ", MAX(up.value) AS uservisibility";
}
$params['currentgroup'] = $currentgroup;
}
@@ -105,9 +114,7 @@ class fetcher {
WHERE u.lastaccess > :timefrom
AND u.lastaccess <= :now
AND u.deleted = 0
AND (" . $DB->sql_cast_char2int('up.value') . " = 1
OR up.value IS NULL
OR u.id = :userid)
$uservisibilityselect
$groupselect $groupby
ORDER BY lastaccess DESC ";
@@ -118,9 +125,7 @@ class fetcher {
WHERE u.lastaccess > :timefrom
AND u.lastaccess <= :now
AND u.deleted = 0
AND (" . $DB->sql_cast_char2int('up.value') . " = 1
OR up.value IS NULL
OR u.id = :userid)
$uservisibilityselect
$groupselect";
} else {
// Course level - show only enrolled users for now.
@@ -138,9 +143,7 @@ class fetcher {
AND ul.courseid = :courseid
AND ul.timeaccess <= :now
AND u.deleted = 0
AND (" . $DB->sql_cast_char2int('up.value') . " = 1
OR up.value IS NULL
OR u.id = :userid)
$uservisibilityselect
$groupselect $groupby
ORDER BY lastaccess DESC";
@@ -154,9 +157,7 @@ class fetcher {
AND ul.courseid = :courseid
AND ul.timeaccess <= :now
AND u.deleted = 0
AND (" . $DB->sql_cast_char2int('up.value') . " = 1
OR up.value IS NULL
OR u.id = :userid)
$uservisibilityselect
$groupselect";
$params['courseid'] = $courseid;
@@ -23,7 +23,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['onlinestatushiding_desc'] = 'If enabled, users have the option to hide their online status from other users.';
$string['configtimetosee'] = 'Number of minutes determining the period of inactivity after which a user is no longer considered to be online.';
$string['onlinestatushiding'] = 'Online status hiding';
$string['nouser'] = 'No online users';
$string['numuser'] = '{$a} online user';
$string['numusers'] = '{$a} online users';
+4
View File
@@ -27,5 +27,9 @@ defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configtext('block_online_users_timetosee', get_string('timetosee', 'block_online_users'),
get_string('configtimetosee', 'block_online_users'), 5, PARAM_INT));
$settings->add(new admin_setting_configcheckbox('block_online_users_onlinestatushiding',
get_string('onlinestatushiding', 'block_online_users'),
get_string('onlinestatushiding_desc', 'block_online_users'), 1));
}
@@ -42,7 +42,9 @@ Feature: The online users block allow you to see who is currently online
@javascript
Scenario: Hide/show user's online status from/to other users in the online users block on course page
Given I log in as "teacher1"
Given the following config values are set as admin:
| block_online_users_onlinestatushiding | 1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Online users" block
And I log out
@@ -71,3 +73,45 @@ Feature: The online users block allow you to see who is currently online
Then I should see "2 online users" in the "Online users" "block"
And I should see "Teacher 1" in the "Online users" "block"
And I should see "Student 1" in the "Online users" "block"
@javascript
Scenario: Hide/show icon is not visible in the online users block on course page when the setting is disabled
Given the following config values are set as admin:
| block_online_users_onlinestatushiding | 1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Online users" block
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And "Hide" "icon" should exist in the ".block.block_online_users" "css_element"
And I log out
And the following config values are set as admin:
| block_online_users_onlinestatushiding | 0 |
When I log in as "student1"
Then I should see "Student 1" in the "Online users" "block"
And "Hide" "icon" should not exist in the ".block.block_online_users" "css_element"
@javascript
Scenario: User is displayed in the online users block on course page when visibility setting is disabled,
ignoring the previously set visibility state
Given the following config values are set as admin:
| block_online_users_onlinestatushiding | 1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Online users" block
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And "Hide" "icon" should exist in the "#change-user-visibility" "css_element"
And I click on "#change-user-visibility" "css_element"
And I wait "1" seconds
And "Show" "icon" should exist in the "#change-user-visibility" "css_element"
And I log out
And the following config values are set as admin:
| block_online_users_onlinestatushiding | 0 |
And I log in as "teacher1"
When I am on "Course 1" course homepage
Then I should see "2 online users" in the "Online users" "block"
And I should see "Teacher 1" in the "Online users" "block"
And I should see "Student 1" in the "Online users" "block"
@@ -29,7 +29,9 @@ Feature: The online users block allow you to see who is currently online on dash
@javascript
Scenario: Hide/show user's online status from/to other users in the online users block on dashboard
Given I log in as "student1"
Given the following config values are set as admin:
| block_online_users_onlinestatushiding | 1 |
And I log in as "student1"
And I should see "1 online user" in the "Online users" "block"
And I should see "Student 1" in the "Online users" "block"
And "Hide" "icon" should exist in the "#change-user-visibility" "css_element"
@@ -52,3 +54,44 @@ Feature: The online users block allow you to see who is currently online on dash
Then I should see "2 online users" in the "Online users" "block"
And I should see "Student 2" in the "Online users" "block"
And I should see "Student 1" in the "Online users" "block"
@javascript
Scenario: Hide/show icon is not visible in the online users block when the setting is disabled
Given the following config values are set as admin:
| block_online_users_onlinestatushiding | 1 |
And I log in as "student1"
And I should see "1 online user" in the "Online users" "block"
And I should see "Student 1" in the "Online users" "block"
And "Hide" "icon" should exist in the ".block.block_online_users" "css_element"
And I log out
And the following config values are set as admin:
| block_online_users_onlinestatushiding | 0 |
When I log in as "student1"
Then I should see "1 online user" in the "Online users" "block"
And I should see "Student 1" in the "Online users" "block"
And "Hide" "icon" should not exist in the ".block.block_online_users" "css_element"
@javascript
Scenario: User is displayed in the online users block when visibility setting is disabled,
ignoring the previously set visibility state
Given the following config values are set as admin:
| block_online_users_onlinestatushiding | 1 |
And I log in as "student1"
And I should see "1 online user" in the "Online users" "block"
And I should see "Student 1" in the "Online users" "block"
And "Hide" "icon" should exist in the "#change-user-visibility" "css_element"
And I click on "#change-user-visibility" "css_element"
And I wait "1" seconds
And "Show" "icon" should exist in the "#change-user-visibility" "css_element"
And I log out
And I log in as "student2"
And I should see "1 online user" in the "Online users" "block"
And I should see "Student 2" in the "Online users" "block"
And I should not see "Student 1" in the "Online users" "block"
And I log out
And the following config values are set as admin:
| block_online_users_onlinestatushiding | 0 |
When I log in as "student2"
Then I should see "2 online users" in the "Online users" "block"
And I should see "Student 2" in the "Online users" "block"
And I should see "Student 1" in the "Online users" "block"
@@ -52,7 +52,9 @@ Feature: The online users block allow you to see who is currently online on fron
@javascript
Scenario: Hide/show user's online status from/to other users in the online users block on front page
Given I log in as "admin"
Given the following config values are set as admin:
| block_online_users_onlinestatushiding | 1 |
And I log in as "admin"
And I am on site homepage
And I navigate to "Turn editing on" in current page administration
And I add the "Online users" block
@@ -84,3 +86,55 @@ Feature: The online users block allow you to see who is currently online on fron
And I should see "Admin" in the "Online users" "block"
And I should see "Student 2" in the "Online users" "block"
And I should see "Student 1" in the "Online users" "block"
@javascript
Scenario: Hide/show icon is not visible in the online users block on front page when the setting is disabled
Given the following config values are set as admin:
| block_online_users_onlinestatushiding | 1 |
And I log in as "admin"
And I am on site homepage
And I navigate to "Turn editing on" in current page administration
And I add the "Online users" block
And I log out
And I log in as "student1"
And I am on site homepage
And "Hide" "icon" should exist in the ".block.block_online_users" "css_element"
And I log out
And the following config values are set as admin:
| block_online_users_onlinestatushiding | 0 |
When I log in as "student1"
Then I should see "Student 1" in the "Online users" "block"
And "Hide" "icon" should not exist in the ".block.block_online_users" "css_element"
@javascript
Scenario: User is displayed in the online users block on front page when visibility setting is disabled,
ignoring the previously set visibility state
Given the following config values are set as admin:
| block_online_users_onlinestatushiding | 1 |
And I log in as "admin"
And I am on site homepage
And I navigate to "Turn editing on" in current page administration
And I add the "Online users" block
And I log out
And I log in as "student1"
And I am on site homepage
And "Hide" "icon" should exist in the "#change-user-visibility" "css_element"
And I click on "#change-user-visibility" "css_element"
And I wait "1" seconds
And "Show" "icon" should exist in the "#change-user-visibility" "css_element"
And I log out
And I log in as "student2"
And I am on site homepage
And I should see "2 online user" in the "Online users" "block"
And I should see "Admin" in the "Online users" "block"
And I should see "Student 2" in the "Online users" "block"
And I should not see "Student 1" in the "Online users" "block"
And I log out
And the following config values are set as admin:
| block_online_users_onlinestatushiding | 0 |
And I log in as "student2"
When I am on site homepage
Then I should see "3 online users" in the "Online users" "block"
And I should see "Admin" in the "Online users" "block"
And I should see "Student 2" in the "Online users" "block"
And I should see "Student 1" in the "Online users" "block"
@@ -155,6 +155,8 @@ class block_online_users_testcase extends advanced_testcase {
public function test_user_visibility_course1_group1_members() {
global $CFG;
// Enable users to set their visibility to others in the online users block.
$CFG->block_online_users_onlinestatushiding = true;
$groupid = $this->data['group1']->id;
$now = time();
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
@@ -190,6 +192,18 @@ class block_online_users_testcase extends advanced_testcase {
// User1 should not be displayed in the online users block.
$this->assertEquals(2, $usercount);
$this->assertFalse(array_key_exists($user1->id, $users));
// Disable users to set their visibility to others in the online users block.
// All users should be displayed now and the visibility status of a users should be ignored,
// as the capability of setting the visibility to other user has been disabled.
$CFG->block_online_users_onlinestatushiding = false;
// Test if the fetcher gets all the users including user1.
$onlineusers = new fetcher($groupid, $now, $timetoshowusers, $context, false, $courseid);
$users = $onlineusers->get_users();
$usercount = $onlineusers->count_users();
// User1 should be displayed in the online users block.
$this->assertEquals(3, $usercount);
$this->assertTrue(array_key_exists($user1->id, $users));
}
/**
@@ -234,6 +248,18 @@ class block_online_users_testcase extends advanced_testcase {
// User1 should not be displayed in the online users block.
$this->assertEquals(8, $usercount);
$this->assertFalse(array_key_exists($user1->id, $users));
// Disable users to set their visibility to others in the online users block.
// All users should be displayed now and the visibility status of a users should be ignored,
// as the capability of setting the visibility to other user has been disabled.
$CFG->block_online_users_onlinestatushiding = false;
// Test if the fetcher gets all the users including user1.
$onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $context, false, $courseid);
$users = $onlineusers->get_users();
$usercount = $onlineusers->count_users();
// User1 should be displayed in the online users block.
$this->assertEquals(9, $usercount);
$this->assertTrue(array_key_exists($user1->id, $users));
}
/**
@@ -277,5 +303,17 @@ class block_online_users_testcase extends advanced_testcase {
// User1 should not be displayed in the online users block.
$this->assertEquals(11, $usercount);
$this->assertFalse(array_key_exists($user1->id, $users));
// Disable users to set their visibility to others in the online users block.
// All users should be displayed now and the visibility status of a users should be ignored,
// as the capability of setting the visibility to other user has been disabled.
$CFG->block_online_users_onlinestatushiding = false;
// Test if the fetcher gets all the users including user1.
$onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $context, true);
$users = $onlineusers->get_users();
$usercount = $onlineusers->count_users();
// User1 should be displayed in the online users block.
$this->assertEquals(12, $usercount);
$this->assertTrue(array_key_exists($user1->id, $users));
}
}
+1 -1
View File
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2019052000; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2019052001; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2019051100; // Requires this Moodle version
$plugin->component = 'block_online_users'; // Full name of the plugin (used for diagnostics)