MDL-82963 Tag: Improve validation for users tagged with sepecified tag

This commit is contained in:
Huong Nguyen
2024-12-05 11:03:37 +08:00
committed by Jun Pataleta
parent 6807076172
commit 7c98470586
2 changed files with 44 additions and 9 deletions
+34 -8
View File
@@ -6,10 +6,13 @@ Feature: Browsing tagged items
Background:
Given the following "users" exist:
| username | firstname | lastname | email | interests |
| user1 | User | 1 | user1@example.com | Cat |
| user2 | User | 2 | user1@example.com | Cat, Dog |
| user3 | User | 3 | user1@example.com | Dog |
| username | firstname | lastname | email | interests |
| user1 | User | 1 | user1@example.com | Cat, Zebra |
| user2 | User | 2 | user2@example.com | Cat, Dog, Zebra |
| user3 | User | 3 | user3@example.com | Zebra |
| user4 | User | 4 | user4@example.com | Zebra |
| user5 | User | 5 | user5@example.com | Zebra |
| user6 | User | 6 | user6@example.com | Zebra |
And the following "courses" exist:
| fullname | shortname | tags |
| Course 1 | c1 | Cat, Dog |
@@ -19,12 +22,15 @@ Feature: Browsing tagged items
| Course 5 | c5 | Cat |
| Course 6 | c6 | Cat |
| Course 7 | c7 | Cat |
And the following config values are set as admin:
| unaddableblocks | | theme_boost|
And the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| moodle/user:viewdetails | Allow | user | System | |
Scenario: Browse tag index with javascript disabled
When I log in as "user1"
And I turn editing mode on
And the following config values are set as admin:
| unaddableblocks | | theme_boost|
# TODO MDL-57120 "Tags" link not accessible without navigation block.
And I add the "Navigation" block if not present
And I click on "Tags" "link" in the "Navigation" "block"
@@ -72,8 +78,6 @@ Feature: Browsing tagged items
Scenario: Browse tag index with javascript enabled
When I log in as "user1"
And I turn editing mode on
And the following config values are set as admin:
| unaddableblocks | | theme_boost|
# TODO MDL-57120 "Tags" link not accessible without navigation block.
And I add the "Navigation" block if not present
And I click on "Site pages" "list_item" in the "Navigation" "block"
@@ -114,3 +118,25 @@ Feature: Browsing tagged items
And I should not see "Course2"
And I should not see "Course1"
And I log out
Scenario Outline: Browse tag index and view other profiles
Given I log in as "user1"
And I turn editing mode on
And the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| moodle/user:viewdetails | <permission> | user | System | |
# TODO MDL-57120 "Tags" link not accessible without navigation block.
And I add the "Navigation" block if not present
When I click on "Tags" "link" in the "Navigation" "block"
And I follow "Zebra"
Then I should <action1> "User 2"
And I should <action1> "User 3"
And I should <action1> "User 4"
And I should <action1> "User 5"
# Pagination test.
And I should <action2> "More" in the "#tagarea-core-user" "css_element"
Examples:
| permission | action1 | action2 |
| Prevent | not see | not see |
| Allow | see | see |
+10 -1
View File
@@ -1255,15 +1255,24 @@ function user_get_tagged_users($tag, $exclusivemode = false, $fromctx = 0, $ctx
}
$perpage = $exclusivemode ? 24 : 5;
$content = '';
$totalpages = ceil($usercount / $perpage);
$excludedusers = 0;
if ($usercount) {
$userlist = $tag->get_tagged_items('core', 'user', $page * $perpage, $perpage,
'it.deleted=:notdeleted', array('notdeleted' => 0));
foreach ($userlist as $user) {
if (!user_can_view_profile($user)) {
unset($userlist[$user->id]);
$excludedusers++;
}
}
$renderer = $PAGE->get_renderer('core', 'user');
$content .= $renderer->user_list($userlist, $exclusivemode);
}
// Calculate the total number of pages.
$totalpages = ceil(($usercount - $excludedusers) / $perpage);
return new core_tag\output\tagindex($tag, 'core', 'user', $content,
$exclusivemode, $fromctx, $ctx, $rec, $page, $totalpages);
}