* @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(),
$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);
$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.