From 242060661a769831f5da3b0f0249dd068861e26a Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Wed, 1 Feb 2023 11:29:31 +0100 Subject: [PATCH] MDL-70586 mod_feedback: Hide the Preview questions icon for students The Preview questions icon shouldn't be displayed unless the user can edit the feedback or access to the reports; otherwise, it's causing confusion (especially when the feedback is not opened). --- .../classes/output/standard_action_bar.php | 18 +++++-- mod/feedback/print.php | 15 +++++- mod/feedback/tests/behat/anonymous.feature | 36 ++++---------- .../tests/behat/non_anonymous.feature | 8 +--- .../tests/behat/preview_questions.feature | 47 +++++++++++++++++++ 5 files changed, 85 insertions(+), 39 deletions(-) create mode 100644 mod/feedback/tests/behat/preview_questions.feature diff --git a/mod/feedback/classes/output/standard_action_bar.php b/mod/feedback/classes/output/standard_action_bar.php index 5ecd70aab36..1c69dee62ec 100644 --- a/mod/feedback/classes/output/standard_action_bar.php +++ b/mod/feedback/classes/output/standard_action_bar.php @@ -67,12 +67,20 @@ class standard_action_bar extends base_action_bar { null, ['class' => 'btn btn-secondary']); } - $previewlnk = new moodle_url('/mod/feedback/print.php', array('id' => $this->cmid)); - if ($this->course->id) { - $previewlnk->param('courseid', $this->course->id); - } - $items['left'][]['actionlink'] = new action_link($previewlnk, get_string('previewquestions', 'feedback'), + // The preview icon should be displayed only to users with capability to edit or view reports (to include + // non-editing teachers too). + $capabilities = [ + 'mod/feedback:edititems', + 'mod/feedback:viewreports', + ]; + if (has_any_capability($capabilities, $this->context)) { + $previewlnk = new moodle_url('/mod/feedback/print.php', array('id' => $this->cmid)); + if ($this->course->id) { + $previewlnk->param('courseid', $this->course->id); + } + $items['left'][]['actionlink'] = new action_link($previewlnk, get_string('previewquestions', 'feedback'), null, ['class' => 'btn btn-secondary']); + } if ($this->viewcompletion) { // Display a link to complete feedback or resume. diff --git a/mod/feedback/print.php b/mod/feedback/print.php index e365377eeb9..112e1f2d98c 100644 --- a/mod/feedback/print.php +++ b/mod/feedback/print.php @@ -33,6 +33,20 @@ $PAGE->set_url('/mod/feedback/print.php', array('id'=>$id)); list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback'); require_course_login($course, true, $cm); +// This page should be only displayed to users with capability to edit or view reports (to include non-editing teachers too). +$context = context_module::instance($cm->id); +$capabilities = [ + 'mod/feedback:edititems', + 'mod/feedback:viewreports', +]; +if (!has_any_capability($capabilities, $context)) { + $capability = 'mod/feedback:edititems'; + if (has_capability($capability, $context)) { + $capability = 'mod/feedback:viewreports'; + } + throw new required_capability_exception($context, $capability, 'nopermissions', ''); +} + $feedback = $PAGE->activityrecord; $feedbackstructure = new mod_feedback_structure($feedback, $cm, $courseid); @@ -64,4 +78,3 @@ echo $OUTPUT->continue_button($continueurl); // Finish the page. echo $OUTPUT->footer(); - diff --git a/mod/feedback/tests/behat/anonymous.feature b/mod/feedback/tests/behat/anonymous.feature index b0cbf891d8c..228b15bec80 100644 --- a/mod/feedback/tests/behat/anonymous.feature +++ b/mod/feedback/tests/behat/anonymous.feature @@ -41,17 +41,13 @@ Feature: Anonymous feedback Scenario: Guests can see anonymous feedback on front page but can not complete When I follow "Site feedback" Then I should not see "Answer the questions" - And I follow "Preview" - And I should see "Do you like our site?" - And I press "Continue" + And I should not see "Preview questions" Scenario: Complete anonymous feedback on the front page as an authenticated user And I log in as "user1" And I am on site homepage When I follow "Site feedback" - And I follow "Preview" - And I should see "Do you like our site?" - And I press "Continue" + And I should not see "Preview questions" And I follow "Answer the questions" And I should see "Do you like our site?" And I set the following fields to these values: @@ -70,9 +66,7 @@ Feature: Anonymous feedback And I log in as "user1" And I am on site homepage When I follow "Site feedback" - And I follow "Preview" - And I should see "Do you like our site?" - And I press "Continue" + And I should not see "Preview questions" And I follow "Answer the questions" And I should see "Do you like our site?" And I set the following fields to these values: @@ -82,9 +76,7 @@ Feature: Anonymous feedback And I log in as "user2" And I am on site homepage And I follow "Site feedback" - And I follow "Preview" - And I should see "Do you like our site?" - And I press "Continue" + And I should not see "Preview questions" And I follow "Answer the questions" And I set the following fields to these values: | No | 1 | @@ -113,9 +105,7 @@ Feature: Anonymous feedback Given the following config values are set as admin: | feedback_allowfullanonymous | 1 | When I follow "Site feedback" - And I follow "Preview" - And I should see "Do you like our site?" - And I press "Continue" + And I should not see "Preview questions" And I follow "Answer the questions" And I should see "Do you like our site?" And I set the following fields to these values: @@ -134,9 +124,7 @@ Feature: Anonymous feedback | mod/feedback:viewanalysepage | Allow | And I log out When I follow "Site feedback" - And I follow "Preview" - And I should see "Do you like our site?" - And I press "Continue" + And I should not see "Preview questions" And I follow "Answer the questions" And I should see "Do you like our site?" And I set the following fields to these values: @@ -145,9 +133,7 @@ Feature: Anonymous feedback And I press "Continue" # Starting new feedback When I follow "Site feedback" - And I follow "Preview" - And I should see "Do you like our site?" - And I press "Continue" + And I should not see "Preview questions" And I follow "Answer the questions" And I should see "Do you like our site?" And I set the following fields to these values: @@ -184,9 +170,7 @@ Feature: Anonymous feedback And I log out And I am on the "Course feedback" "feedback activity" page logged in as user1 - And I follow "Preview" - Then I should see "Do you like this course?" - And I press "Continue" + And I should not see "Preview questions" And I follow "Answer the questions" And I should see "Do you like this course?" And I set the following fields to these values: @@ -194,9 +178,7 @@ Feature: Anonymous feedback And I press "Submit your answers" And I log out And I am on the "Course feedback" "feedback activity" page logged in as user2 - And I follow "Preview" - And I should see "Do you like this course?" - And I press "Continue" + And I should not see "Preview questions" And I follow "Answer the questions" And I should see "Do you like this course?" And I set the following fields to these values: diff --git a/mod/feedback/tests/behat/non_anonymous.feature b/mod/feedback/tests/behat/non_anonymous.feature index 80b1e4401e5..b25964bc722 100644 --- a/mod/feedback/tests/behat/non_anonymous.feature +++ b/mod/feedback/tests/behat/non_anonymous.feature @@ -39,15 +39,11 @@ Feature: Non anonymous feedback Scenario: Guests can see non anonymous feedback on front page but can not complete When I am on the "Site feedback" "feedback activity" page Then I should not see "Answer the questions" - And I follow "Preview" - And I should see "Do you like our site?" - And I press "Continue" + And I should not see "Preview questions" Scenario: Complete non anonymous feedback on the front page as an authenticated user When I am on the "Site feedback" "feedback activity" page logged in as user1 - And I follow "Preview" - And I should see "Do you like our site?" - And I press "Continue" + And I should not see "Preview questions" And I follow "Answer the questions" And I should see "Do you like our site?" And I set the following fields to these values: diff --git a/mod/feedback/tests/behat/preview_questions.feature b/mod/feedback/tests/behat/preview_questions.feature new file mode 100644 index 00000000000..ac9b7fa5d6b --- /dev/null +++ b/mod/feedback/tests/behat/preview_questions.feature @@ -0,0 +1,47 @@ +@mod @mod_feedback +Feature: Preview feedback questions + In order to view the feedback questions + As a teacher + I need to be able to preview them + + Background: + Given the following "users" exist: + | username | firstname | lastname | + | student | Student | User | + | editingteacher | Editing | Teacher | + | teacher | NonEditing | Teacher | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | student | C1 | student | + | editingteacher | C1 | editingteacher | + | teacher | C1 | teacher | + And the following "activities" exist: + | activity | name | course | idnumber | + | feedback | Music history | C1 | feedback0 | + And I am on the "Music history" "feedback activity" page logged in as editingteacher + And I click on "Edit questions" "link" in the "[role=main]" "css_element" + And I add a "Multiple choice" question to the feedback with: + | Question | What is your favourite instrument | + | Label | instrument1 | + | Multiple choice type | Multiple choice - single answer | + | Multiple choice values | drums\guitar\hurdygurdy | + And I log out + + Scenario: Students cannot see the Preview questions button + When I am on the "Music history" "feedback activity" page logged in as student + Then I should not see "Preview questions" + + Scenario: Non-editing teachers can see the Preview questions button + When I am on the "Music history" "feedback activity" page logged in as teacher + Then I should see "Preview questions" + And I follow "Preview questions" + And I should see "What is your favourite instrument" + + Scenario: Editing teachers can see the Preview questions button + When I am on the "Music history" "feedback activity" page logged in as editingteacher + Then I should see "Preview questions" + And I follow "Preview questions" + And I should see "What is your favourite instrument"