MDL-65569 mod_forum: Correct rules for SSD

In a Single Simple Discussion forum, the first post can only be edited
by a user with the manageactivities capability, but all other posts
behave as normal.
This commit is contained in:
Andrew Nicols 2019-05-14 09:56:33 +08:00
parent 6a7451ff1b
commit 50b52ef4b2
3 changed files with 9 additions and 4 deletions

View File

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

View File

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

View File

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