diff --git a/mod/forum/classes/local/factories/url.php b/mod/forum/classes/local/factories/url.php index f7141b3534b..c66335f8112 100644 --- a/mod/forum/classes/local/factories/url.php +++ b/mod/forum/classes/local/factories/url.php @@ -247,7 +247,7 @@ class url { * @return moodle_url */ public function get_edit_post_url_from_post(forum_entity $forum, post_entity $post) : moodle_url { - if ($forum->get_type() == 'single') { + if ($forum->get_type() == 'single' && !$post->has_parent()) { return new moodle_url('/course/modedit.php', [ 'update' => $forum->get_course_module_record()->id, 'sesskey' => sesskey(), diff --git a/mod/forum/classes/local/managers/capability.php b/mod/forum/classes/local/managers/capability.php index 5709c71293b..76ba7c127dc 100644 --- a/mod/forum/classes/local/managers/capability.php +++ b/mod/forum/classes/local/managers/capability.php @@ -420,7 +420,10 @@ class capability { $ineditingtime = !$post->has_parent() && $discussion->has_started(); break; case 'single': - return $discussion->is_first_post($post) && has_capability('moodle/course:manageactivities', $context, $user); + if ($discussion->is_first_post($post)) { + return has_capability('moodle/course:manageactivities', $context, $user); + } + break; } return ($ownpost && $ineditingtime) || has_capability('mod/forum:editanypost', $context, $user); diff --git a/mod/forum/tests/managers_capability_test.php b/mod/forum/tests/managers_capability_test.php index 9c5ffa7efed..2f8309db8fe 100644 --- a/mod/forum/tests/managers_capability_test.php +++ b/mod/forum/tests/managers_capability_test.php @@ -689,11 +689,13 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $capabilitymanager = $this->managerfactory->get_capability_manager($forum); // Create a new post that definitely isn't the first post of the discussion. + // Only the author, and a user with editanypost can edit it. $post = $this->entityfactory->get_post_from_stdclass( (object) array_merge((array) $this->postrecord, ['id' => $post->get_id() + 100]) ); - - $this->assertFalse($capabilitymanager->can_edit_post($user, $discussion, $post)); + $this->give_capability('mod/forum:editanypost'); + $this->assertTrue($capabilitymanager->can_edit_post($user, $discussion, $post)); + $this->assertFalse($capabilitymanager->can_edit_post($otheruser, $discussion, $post)); $post = $this->post; // Set the first post of the discussion to our post.