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).
This commit is contained in:
Sara Arjona 2023-02-01 11:29:31 +01:00
parent 67bbf6c416
commit 242060661a
5 changed files with 85 additions and 39 deletions

View File

@ -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.

View File

@ -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();

View File

@ -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:

View File

@ -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:

View File

@ -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"