From 5a119f31f4eed7987563311db69f1dfae2941144 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Mon, 11 Nov 2019 13:42:12 +0100 Subject: [PATCH 1/2] MDL-67042 customfield: Display only fields visible to everybody When defining the available filters for the Dashboard, only the fields visible to everyone should be displayed in the Custom field filter. --- blocks/myoverview/classes/output/main.php | 4 +++- blocks/myoverview/lang/en/block_myoverview.php | 2 +- customfield/classes/api.php | 4 +++- lang/en/course.php | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/blocks/myoverview/classes/output/main.php b/blocks/myoverview/classes/output/main.php index 5f44bb31e0d..d9687ded276 100644 --- a/blocks/myoverview/classes/output/main.php +++ b/blocks/myoverview/classes/output/main.php @@ -366,7 +366,9 @@ class main implements renderable, templatable { return []; } $field = \core_customfield\field_controller::create($fieldid); - if (!$field->supports_course_grouping()) { + $isvisible = $field->get_configdata_property('visibility') == \core_course\customfield\course_handler::VISIBLETOALL; + // Only visible fields to everybody supporting course grouping will be displayed. + if (!$field->supports_course_grouping() || !$isvisible) { return []; // The field shouldn't have been selectable in the global settings, but just skip it now. } $values = $field->course_grouping_format_values($values); diff --git a/blocks/myoverview/lang/en/block_myoverview.php b/blocks/myoverview/lang/en/block_myoverview.php index 09b5aed8c58..76f83fb2146 100644 --- a/blocks/myoverview/lang/en/block_myoverview.php +++ b/blocks/myoverview/lang/en/block_myoverview.php @@ -54,7 +54,7 @@ $string['courseprogress'] = 'Course progress:'; $string['completepercent'] = '{$a}% complete'; $string['customfield'] = 'Custom field'; $string['customfiltergrouping'] = 'Field to use'; -$string['customfiltergrouping_nofields'] = 'This option requires a course custom field to be set up.'; +$string['customfiltergrouping_nofields'] = 'This option requires a course custom field to be set up and visible to everyone.'; $string['displaycategories'] = 'Display categories'; $string['displaycategories_help'] = 'Display the course category on dashboard course items including cards, list items and summary items.'; $string['favourites'] = 'Starred'; diff --git a/customfield/classes/api.php b/customfield/classes/api.php index 087a0d348c4..6ebce70d304 100644 --- a/customfield/classes/api.php +++ b/customfield/classes/api.php @@ -431,7 +431,9 @@ class api { $fields = $DB->get_records_sql($sql); foreach ($fields as $field) { $inst = field_controller::create(0, $field); - if ($inst->supports_course_grouping()) { + $isvisible = $inst->get_configdata_property('visibility') == \core_course\customfield\course_handler::VISIBLETOALL; + // Only visible fields to everybody supporting course grouping will be displayed. + if ($inst->supports_course_grouping() && $isvisible) { $ret[$inst->get('shortname')] = $inst->get('name'); } } diff --git a/lang/en/course.php b/lang/en/course.php index 7895d12e28f..38c51188ee8 100644 --- a/lang/en/course.php +++ b/lang/en/course.php @@ -35,7 +35,7 @@ $string['customfield_islocked'] = 'Locked'; $string['customfield_islocked_help'] = 'If the field is locked, only users with the capability to change locked custom fields (by default users with the default role of manager only) will be able to change it in the course settings.'; $string['customfield_notvisible'] = 'Nobody'; $string['customfield_visibility'] = 'Visible to'; -$string['customfield_visibility_help'] = 'This setting determines who can view the custom field name and value in the list of courses.'; +$string['customfield_visibility_help'] = 'This setting determines who can view the custom field name and value in the list of courses or in the available custom field filter of the Dashboard.'; $string['customfield_visibletoall'] = 'Everyone'; $string['customfield_visibletoteachers'] = 'Teachers'; $string['customfieldsettings'] = 'Common course custom fields settings'; From e49543e8e98718c0c17c2ff7eb3ac31912d4d8c7 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Mon, 11 Nov 2019 13:43:17 +0100 Subject: [PATCH 2/2] MDL-67042 customfield: Add behat tests to check hidden fields Fields with the visibility different to Everyone should be never displayed in the available filters custom field. --- .../block_myoverview_customfield.feature | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/blocks/myoverview/tests/behat/block_myoverview_customfield.feature b/blocks/myoverview/tests/behat/block_myoverview_customfield.feature index 57d0684c777..c866d5d0c22 100644 --- a/blocks/myoverview/tests/behat/block_myoverview_customfield.feature +++ b/blocks/myoverview/tests/behat/block_myoverview_customfield.feature @@ -13,14 +13,16 @@ Feature: The my overview block allows users to group courses by custom fields | Checkbox field | Course fields | checkbox | checkboxfield | | | Date field | Course fields | date | datefield | {"mindate":0, "maxdate":0} | | Select field | Course fields | select | selectfield | {"options":"Option 1\nOption 2\nOption 3\nOption 4"} | - | Text field | Course fields | text | textfield | | + | Text field | Course fields | text | textfield | {"visibility":"2"} | + | Text field 2 | Course fields | text | textfield2 | {"visibility":"2"} | + | Hidden field | Course fields | text | hiddenfield | {"visibility":"0"} | And the following "courses" exist: - | fullname | shortname | category | customfield_checkboxfield | customfield_datefield | customfield_selectfield | customfield_textfield | - | Course 1 | C1 | 0 | 1 | 981028800 | 1 | fish | - | Course 2 | C2 | 0 | 0 | 334324800 | | | - | Course 3 | C3 | 0 | 0 | 981028800 | 2 | dog | - | Course 4 | C4 | 0 | 1 | | 3 | cat | - | Course 5 | C5 | 0 | | 334411200 | 2 | fish | + | fullname | shortname | category | customfield_checkboxfield | customfield_datefield | customfield_selectfield | customfield_textfield | customfield_textfield2 | + | Course 1 | C1 | 0 | 1 | 981028800 | 1 | fish | penguin | + | Course 2 | C2 | 0 | 0 | 334324800 | | | | + | Course 3 | C3 | 0 | 0 | 981028800 | 2 | dog | | + | Course 4 | C4 | 0 | 1 | | 3 | cat | | + | Course 5 | C5 | 0 | | 334411200 | 2 | fish | penguin | And the following "course enrolments" exist: | user | course | role | | student1 | C1 | student | @@ -172,3 +174,24 @@ Feature: The my overview block allows users to group courses by custom fields And I should not see "Course 3" in the "Course overview" "block" And I should not see "Course 4" in the "Course overview" "block" And I should not see "Course 5" in the "Course overview" "block" + + Scenario: Hidden fields not displayed when configuring the custom field filters + Given I log in as "admin" + When I navigate to "Plugins > Blocks > Course overview" in site administration + And I set the field "Custom field" to "1" + Then the "Field to use" select box should not contain "Hidden field" + + Scenario: Hidden fields not displayed in the filter + Given the following config values are set as admin: + | displaygroupingcustomfield | 1 | block_myoverview | + | customfiltergrouping | textfield2 | block_myoverview | + And I log in as "admin" + And I navigate to "Courses > Course custom fields" in site administration + And I click on "Edit" "link" in the "Text field 2" "table_row" + And I set the field "Visible to" to "Nobody" + And I press "Save changes" + And I log out + When I log in as "student1" + And I click on "All (except removed from view)" "button" in the "Course overview" "block" + Then I should not see "penguin" in the "Course overview" "block" + Then I should not see "No text field" in the "Course overview" "block"