From 628336f639039488151e47743e7abc304d268f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 15:06:33 +0200 Subject: [PATCH] MDL-78708 core_courseformat: Fix activity icon link shown without access In course page activity icon was showing as a link even when the user does not have access to the activity. This commit fixes this behaviour checking if activity is visible for the user and showing the icon without link if not. --- .../output/local/content/cm/cmicon.php | 1 + .../local/content/cm/cmicon.mustache | 20 +++++++++++++------ .../tests/behat/activity_icon_tooltip.feature | 13 ++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/course/format/classes/output/local/content/cm/cmicon.php b/course/format/classes/output/local/content/cm/cmicon.php index a9a86eb2062..f9363040ddc 100644 --- a/course/format/classes/output/local/content/cm/cmicon.php +++ b/course/format/classes/output/local/content/cm/cmicon.php @@ -79,6 +79,7 @@ class cmicon implements named_templatable, renderable { $iconurl = $mod->get_icon_url(); $iconclass = $iconurl->get_param('filtericon') ? '' : 'nofilter'; $data = [ + 'uservisible' => $mod->uservisible, 'url' => $mod->url, 'icon' => $iconurl, 'iconclass' => $iconclass, diff --git a/course/format/templates/local/content/cm/cmicon.mustache b/course/format/templates/local/content/cm/cmicon.mustache index 324b81ac879..4a77d7a84a3 100644 --- a/course/format/templates/local/content/cm/cmicon.mustache +++ b/course/format/templates/local/content/cm/cmicon.mustache @@ -21,6 +21,7 @@ Example context (json): { + "uservisible": true, "url": "#", "icon": "../../../pix/help.svg", "iconclass": "", @@ -30,10 +31,17 @@ } }} {{#url}} - - {{{modname}}} icon - + {{#uservisible}} + + {{{modname}}} icon + + {{/uservisible}} + {{^uservisible}} +
+ {{{modname}}} icon +
+ {{/uservisible}} {{/url}} diff --git a/course/format/tests/behat/activity_icon_tooltip.feature b/course/format/tests/behat/activity_icon_tooltip.feature index 79d58e37018..383446a7cf7 100644 --- a/course/format/tests/behat/activity_icon_tooltip.feature +++ b/course/format/tests/behat/activity_icon_tooltip.feature @@ -39,3 +39,16 @@ Feature: Activity type tooltip. Given I am on the "C1" "Course" page logged in as "student1" When I hover over the "assign icon" "link" in the "Activity sample 1" "activity" Then "body>.tooltip" "css_element" should not exist + + Scenario: Student cannot see the activity icon link if does not have access. + Given I am on the "Activity sample 2" "page activity editing" page logged in as "admin" + When I expand all fieldsets + And I press "Add restriction..." + And I click on "Date" "button" in the "Add restriction..." "dialogue" + And I set the field "direction" to "until" + And I set the field "x[year]" to "2013" + And I set the field "x[month]" to "March" + And I press "Save and return to course" + And I log out + And I am on the "C1" "Course" page logged in as "student1" + Then "page icon" "link" should not exist in the "Activity sample 2" "activity"