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

This commit is contained in:
Mark Nelson 2013-04-24 12:57:33 +08:00
parent 50cc49ba04
commit 34e2987118
2 changed files with 26 additions and 6 deletions

View File

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

@ -688,6 +688,9 @@ if ($fromform = $mform_post->get_data()) {
} 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 @@ if ($fromform = $mform_post->get_data()) {
}
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 ($forum->type == 'qanda'
// 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)) {