From 7824b2f6d91963db676a098bfde460642bbd7a4a Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Tue, 28 Jul 2015 12:21:34 +0800 Subject: [PATCH] MDL-50576 mod_forum: prevent posting to a non-member group Thanks Fred for the help on the issue. --- mod/forum/classes/post_form.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mod/forum/classes/post_form.php b/mod/forum/classes/post_form.php index ba064a84554..7b37a63eb27 100644 --- a/mod/forum/classes/post_form.php +++ b/mod/forum/classes/post_form.php @@ -171,15 +171,20 @@ class mod_forum_post_form extends moodleform { // Check whether the user has access to all groups in this forum from the accessallgroups cap. if ($groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $modulecontext)) { // Only allow posting to all groups if the user has access to all groups. - $groupinfo = array('0' => get_string('allparticipants')); + $groupdata[] = (object) array('id' => 0, 'name' => get_string('allparticipants')); $groupcount++; } $contextcheck = has_capability('mod/forum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount > 1; if ($contextcheck) { foreach ($groupdata as $grouptemp) { + if (!forum_user_can_post_discussion($forum, $grouptemp->id, -1, $cm, $modcontext)) { + continue; + } $groupinfo[$grouptemp->id] = $grouptemp->name; } + } + if (count($groupinfo) > 1) { $mform->addElement('select','groupinfo', get_string('group'), $groupinfo); $mform->setDefault('groupinfo', $post->groupid); $mform->setType('groupinfo', PARAM_INT);