MDL-86011 feedback: Prevent admin answering unless enrolled as student
This commit is contained in:
@@ -613,7 +613,7 @@ class mod_feedback_completion extends mod_feedback_structure {
|
||||
global $CFG, $USER;
|
||||
|
||||
$context = context_module::instance($this->cm->id);
|
||||
if (has_capability('mod/feedback:complete', $context, $this->userid)) {
|
||||
if (has_capability('mod/feedback:complete', $context, $this->userid, false)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,3 +91,12 @@ Feature: Managing feedback questions
|
||||
And I click on "After \"(q3) I can see it in your smile\"" "link" in the "Move this question" "dialogue"
|
||||
And I click on "Move this question" "button" in the "Is it me you're looking for?" "mod_feedback > Question"
|
||||
And I click on "To the top of the list" "link" in the "Move this question" "dialogue"
|
||||
|
||||
Scenario: Admin cannot answer questions if not enrolled as student
|
||||
When I am on the "Learning experience course 1" "feedback activity" page logged in as admin
|
||||
Then I should not see "Answer the questions"
|
||||
But the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| admin | C1 | student |
|
||||
And I am on the "Learning experience course 1" "feedback activity" page logged in as admin
|
||||
And I should see "Answer the questions"
|
||||
|
||||
@@ -183,6 +183,8 @@ final class lib_test extends \advanced_testcase {
|
||||
|
||||
$now = time();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
// Enrol admin as a student so they can complete the feedback.
|
||||
$this->getDataGenerator()->enrol_user(get_admin()->id, $course->id, 'student');
|
||||
$feedback = $this->getDataGenerator()->create_module('feedback', ['course' => $course->id,
|
||||
'timeopen' => $now - DAYSECS, 'timeclose' => $now + DAYSECS]);
|
||||
$event = $this->create_action_event($course->id, $feedback->id, FEEDBACK_EVENT_TYPE_OPEN);
|
||||
@@ -294,6 +296,8 @@ final class lib_test extends \advanced_testcase {
|
||||
$this->setAdminUser();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
// Enrol admin as a student so they can complete the feedback.
|
||||
$this->getDataGenerator()->enrol_user(get_admin()->id, $course->id, 'student');
|
||||
$feedback = $this->getDataGenerator()->create_module('feedback', ['course' => $course->id,
|
||||
'timeopen' => time() + DAYSECS]);
|
||||
$event = $this->create_action_event($course->id, $feedback->id, FEEDBACK_EVENT_TYPE_OPEN);
|
||||
@@ -356,6 +360,8 @@ final class lib_test extends \advanced_testcase {
|
||||
$this->setAdminUser();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
// Enrol admin as a student so they can complete the feedback.
|
||||
$this->getDataGenerator()->enrol_user(get_admin()->id, $course->id, 'student');
|
||||
$feedback = $this->getDataGenerator()->create_module('feedback', ['course' => $course->id]);
|
||||
$event = $this->create_action_event($course->id, $feedback->id, FEEDBACK_EVENT_TYPE_OPEN);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user