From 02660c64ff66e5febf1caa0a507318fe3a26098d Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 14 Mar 2017 15:43:11 +0100 Subject: [PATCH] MDL-58259 mod_forum: Check if attachments allowed If the current user is not allowed to submit attachments with a post, and attachments are incldued, they are now dropped. --- mod/forum/externallib.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mod/forum/externallib.php b/mod/forum/externallib.php index 64b16ab6314..04cf218e524 100644 --- a/mod/forum/externallib.php +++ b/mod/forum/externallib.php @@ -824,6 +824,13 @@ class mod_forum_external extends external_api { throw new moodle_exception('nopostforum', 'forum'); } + if (!empty($options['attachmentsid'])) { + // Ensure that the user has permissions to create attachments. + if (!has_capability('mod/forum:createattachment', $context)) { + $options['attachmentsid'] = 0; + } + } + $thresholdwarning = forum_check_throttling($forum, $cm); forum_check_blocking_threshold($thresholdwarning); @@ -1004,6 +1011,13 @@ class mod_forum_external extends external_api { throw new moodle_exception('cannotcreatediscussion', 'forum'); } + if (!empty($options['attachmentsid'])) { + // Ensure that the user has permissions to create attachments. + if (!has_capability('mod/forum:createattachment', $context)) { + $options['attachmentsid'] = 0; + } + } + $thresholdwarning = forum_check_throttling($forum, $cm); forum_check_blocking_threshold($thresholdwarning);