From 0ef74b27bef176a29f6814ba9a21fd2ba46e8c49 Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Wed, 19 Jul 2017 16:31:52 +0100 Subject: [PATCH 1/2] MDL-59195 assignsubmission_comments: fix permission checks --- mod/assign/submission/comments/lib.php | 9 --------- mod/assign/submission/comments/locallib.php | 1 - 2 files changed, 10 deletions(-) diff --git a/mod/assign/submission/comments/lib.php b/mod/assign/submission/comments/lib.php index 09666b0ca16..71caab65319 100644 --- a/mod/assign/submission/comments/lib.php +++ b/mod/assign/submission/comments/lib.php @@ -48,15 +48,6 @@ function assignsubmission_comments_comment_validate(stdClass $options) { if ($assignment->get_instance()->id != $submission->assignment) { throw new comment_exception('invalidcontext'); } - $canview = false; - if ($submission->userid) { - $canview = $assignment->can_view_submission($submission->userid); - } else { - $canview = $assignment->can_view_group_submission($submission->groupid); - } - if (!$canview) { - throw new comment_exception('nopermissiontocomment'); - } return true; } diff --git a/mod/assign/submission/comments/locallib.php b/mod/assign/submission/comments/locallib.php index 16ac94d7c81..d3b4a3b9849 100644 --- a/mod/assign/submission/comments/locallib.php +++ b/mod/assign/submission/comments/locallib.php @@ -69,7 +69,6 @@ class assign_submission_comments extends assign_submission_plugin { $options->displaycancel = true; $comment = new comment($options); - $comment->set_view_permission(true); $o = $this->assignment->get_renderer()->container($comment->output(true), 'commentscontainer'); return $o; From 0d5f10d1ff364555286eda63fe008e69d10e34b9 Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Mon, 21 Aug 2017 10:20:06 +0100 Subject: [PATCH 2/2] MDL-59195 mod_assign: add behat tests for comments error --- .../behat/assign_comments_no_error.feature | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 mod/assign/tests/behat/assign_comments_no_error.feature diff --git a/mod/assign/tests/behat/assign_comments_no_error.feature b/mod/assign/tests/behat/assign_comments_no_error.feature new file mode 100644 index 00000000000..96e6fb3ceb6 --- /dev/null +++ b/mod/assign/tests/behat/assign_comments_no_error.feature @@ -0,0 +1,26 @@ +@mod @mod_assign +Feature: Switch role does not cause an error message in assignsubmission_comments + + Background: + Given the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "users" exist: + | username | + | teacher1 | + And the following "course enrolments" exist: + | course | user | role | + | C1 | teacher1 | editingteacher | + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I turn editing mode on + And I add a "Assignment" to section "1" and I fill the form with: + | Assignment name | Test assignment | + | Description | This is the description text | + | Students submit in groups | Yes | + + Scenario: I switch role to student and an error doesn't occur + When I follow "Switch role to..." in the user menu + And I press "Student" + And I follow "Test assignment" + Then I should see "This is the description text"