Skip to content

Commit

Permalink
MDL-9376, disallow student to see the other users posts in max editin…
Browse files Browse the repository at this point in the history
…g time, credits to Vlas Voloshin and Charles Fulton
  • Loading branch information
Dongsheng Cai committed Mar 11, 2011
1 parent c096042 commit 67fc4f0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mod/forum/lang/en/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
$string['forum:addnews'] = 'Add news';
$string['forumauthorhidden'] = 'Author (hidden)';
$string['forumblockingalmosttoomanyposts'] = 'You are approaching the posting threshold. You have posted {$a->numposts} times in the last {$a->blockperiod} and the limit is {$a->blockafter} posts.';
$string['forumbodyhidden'] = 'This post cannot be viewed by you, probably because you have not posted in the discussion yet.';
$string['forumbodyhidden'] = 'This post cannot be viewed by you, probably because you have not posted in the discussion or the maximum editing time hasn\'t passed yet.';
$string['forum:createattachment'] = 'Create attachments';
$string['forum:deleteanypost'] = 'Delete any posts (anytime)';
$string['forum:deleteownpost'] = 'Delete own posts (within deadline)';
Expand Down
31 changes: 27 additions & 4 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@ function forum_cron() {
// oops - this user should not receive anything from this course
continue;
}
// Don't send email if the forum is Q&A and the user has not posted
if ($forum->type == 'qanda' && !forum_get_user_posted_time($discussion->id, $userto->id)) {
mtrace('Did not email '.$userto->id.' because user has not posted in discussion');
continue;
}

// Get info about the sending user
if (array_key_exists($post->userid, $users)) { // we might know him/her already
Expand Down Expand Up @@ -4640,8 +4645,25 @@ function forum_user_has_posted($forumid, $did, $userid) {
WHERE p.userid = :userid AND d.forum = :forumid";
return $DB->record_exists_sql($sql, array('forumid'=>$forumid,'userid'=>$userid));
} else {
return $DB->record_exists('forum_posts', array('discussion'=>$did,'userid'=>$userid));
return $DB->record_exists('forum_posts', array('discussion'=>$did,'userid'=>$userid));
}
}

/**
* Returns creation time of the first user's post in given discussion
* @global object $DB
* @param int $did Discussion id
* @param int $userid User id
* @return int|bool post creation time stamp or return false
*/
function forum_get_user_posted_time($did, $userid) {
global $DB;

$posttime = $DB->get_field('forum_posts', 'MIN(created)', array('userid'=>$userid, 'discussion'=>$did));
if (empty($posttime)) {
return false;
}
return $posttime;
}

/**
Expand Down Expand Up @@ -4893,7 +4915,7 @@ function forum_user_can_see_discussion($forum, $discussion, $context, $user=NULL
* @return bool
*/
function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NULL) {
global $USER, $DB;
global $CFG, $USER, $DB;

// retrieve objects (yuk)
if (is_numeric($forum)) {
Expand Down Expand Up @@ -4954,9 +4976,10 @@ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NUL
if ($forum->type == 'qanda') {
$firstpost = forum_get_firstpost_from_discussion($discussion->id);
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$userfirstpost = forum_get_user_posted_time($discussion->id, $user->id);

return (forum_user_has_posted($forum->id,$discussion->id,$user->id) ||
$firstpost->id == $post->id ||
return (($userfirstpost !== false && (time() - $userfirstpost >= $CFG->maxeditingtime)) ||
$firstpost->id == $post->id || $post->userid == $user->id || $firstpost->userid == $user->id ||
has_capability('mod/forum:viewqandawithoutposting', $modcontext, $user->id, false));
}
return true;
Expand Down

0 comments on commit 67fc4f0

Please sign in to comment.