Permalink
Browse files

MDL-39303 mod_forum: prevent user from submitting when post threshold…

… reached
  • Loading branch information...
1 parent 50cc49b commit 34e29871181fba6585294aee03c93a2d96a39eb3 @markn86 markn86 committed Apr 24, 2013
Showing with 26 additions and 6 deletions.
  1. +18 −1 mod/forum/lib.php
  2. +8 −5 mod/forum/post.php
View
@@ -7098,7 +7098,7 @@ function forum_check_throttling($forum, $cm = null) {
}
if (!is_object($forum)) {
- return false; // This is broken.
+ return false; // This is broken.
}
if (!$cm) {
@@ -7154,6 +7154,23 @@ function forum_check_throttling($forum, $cm = null) {
}
}
+/**
+ * Throws an error if the user is no longer allowed to post due to reaching
+ * or exceeding the number of posts specified in 'Post threshold for blocking'
+ * setting.
+ *
+ * @param stdClass $thresholdwarning the warning information returned
+ * from the function forum_check_throttling.
+ */
+function forum_check_blocking_threshold($thresholdwarning) {
+ if (!empty($thresholdwarning) && !$thresholdwarning->canpost) {
+ print_error($thresholdwarning->errorcode,
+ $thresholdwarning->module,
+ $thresholdwarning->link,
+ $thresholdwarning->additional);
+ }
+}
+
/**
* Removes all grades from gradebook
View
@@ -688,6 +688,9 @@
} else if ($fromform->discussion) { // Adding a new post to an existing discussion
+ // Before we add this we must check that the user will not exceed the blocking threshold.
+ forum_check_blocking_threshold($thresholdwarning);
+
unset($fromform->groupid);
$message = '';
$addpost = $fromform;
@@ -736,7 +739,10 @@
}
exit;
- } else { // Adding a new discussion
+ } else { // Adding a new discussion.
+ // Before we add this we must check that the user will not exceed the blocking threshold.
+ forum_check_blocking_threshold($thresholdwarning);
+
if (!forum_user_can_post_discussion($forum, $fromform->groupid, -1, $cm, $modcontext)) {
print_error('cannotcreatediscussion', 'forum');
}
@@ -875,10 +881,7 @@
// If there is a warning message and we are not editing a post we need to handle the warning.
if (!empty($thresholdwarning) && !$edit) {
// Here we want to throw an exception if they are no longer allowed to post.
- if (!$thresholdwarning->canpost) {
- print_error($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->link,
- $thresholdwarning->additional);
- }
+ forum_check_blocking_threshold($thresholdwarning);
}
if (!empty($parent)) {

0 comments on commit 34e2987

Please sign in to comment.