Browse files

Merge branch 'MDL-30377_m23' of git://github.com/markn86/moodle into …

…MOODLE_23_STABLE
  • Loading branch information...
2 parents 97c7fac + 73d13b1 commit 8fb4c6e7c375306c51921e4f429e48df52b9d9f4 @danpoltawski danpoltawski committed Nov 21, 2012
Showing with 72 additions and 15 deletions.
  1. +2 −11 mod/forum/discuss.php
  2. +1 −1 mod/forum/lang/en/forum.php
  3. +69 −3 mod/forum/lib.php
View
13 mod/forum/discuss.php
@@ -64,14 +64,6 @@
rss_add_http_header($modcontext, 'mod_forum', $forum, $rsstitle);
}
- if ($forum->type == 'news') {
- if (!($USER->id == $discussion->userid || (($discussion->timestart == 0
- || $discussion->timestart <= time())
- && ($discussion->timeend == 0 || $discussion->timeend > time())))) {
- print_error('invaliddiscussionid', 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
- }
- }
-
/// move discussion if requested
if ($move > 0 and confirm_sesskey()) {
$return = $CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->id;
@@ -140,9 +132,8 @@
print_error("notexists", 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
}
-
- if (!forum_user_can_view_post($post, $course, $cm, $forum, $discussion)) {
- print_error('nopermissiontoview', 'forum', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id");
+ if (!forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
+ print_error('noviewdiscussionspermission', 'forum', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id");
}
if ($mark == 'read' or $mark == 'unread') {
View
2 mod/forum/lang/en/forum.php
@@ -158,7 +158,7 @@
$string['forum:allowforcesubscribe'] = 'Allow force subscribe';
$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 or the maximum editing time hasn\'t passed yet.';
+$string['forumbodyhidden'] = 'This post cannot be viewed by you, probably because you have not posted in the discussion, the maximum editing time hasn\'t passed yet, the discussion has not started or the discussion has expired.';
$string['forum:createattachment'] = 'Create attachments';
$string['forum:deleteanypost'] = 'Delete any posts (anytime)';
$string['forum:deleteownpost'] = 'Delete own posts (within deadline)';
View
72 mod/forum/lib.php
@@ -5169,7 +5169,6 @@ function forum_user_can_post($forum, $discussion, $user=NULL, $cm=NULL, $course=
}
}
-
/**
* checks to see if a user can view a particular post
*
@@ -5207,6 +5206,51 @@ function forum_user_can_view_post($post, $course, $cm, $forum, $discussion, $use
return true;
}
+/**
+ * Check to ensure a user can view a timed discussion.
+ *
+ * @param object $discussion
+ * @param object $user
+ * @param object $context
+ * @return boolean returns true if they can view post, false otherwise
+ */
+function forum_user_can_see_timed_discussion($discussion, $user, $context) {
+ global $CFG;
+
+ // Check that the user can view a discussion that is normally hidden due to access times.
+ if (!empty($CFG->forum_enabletimedposts)) {
+ $time = time();
+ if (($discussion->timestart != 0 && $discussion->timestart > $time)
+ || ($discussion->timeend != 0 && $discussion->timeend < $time)) {
+ if (!has_capability('mod/forum:viewhiddentimedposts', $context, $user->id)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+/**
+ * Check to ensure a user can view a group discussion.
+ *
+ * @param object $discussion
+ * @param object $cm
+ * @param object $context
+ * @return boolean returns true if they can view post, false otherwise
+ */
+function forum_user_can_see_group_discussion($discussion, $cm, $context) {
+
+ // If it's a grouped discussion, make sure the user is a member.
+ if ($discussion->groupid > 0) {
+ $groupmode = groups_get_activity_groupmode($cm);
+ if ($groupmode == SEPARATEGROUPS) {
+ return groups_is_member($discussion->groupid) || has_capability('moodle/site:accessallgroups', $context);
+ }
+ }
+
+ return true;
+}
/**
* @global object
@@ -5238,11 +5282,22 @@ function forum_user_can_see_discussion($forum, $discussion, $context, $user=NULL
return false;
}
}
+ if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
+ print_error('invalidcoursemodule');
+ }
if (!has_capability('mod/forum:viewdiscussion', $context)) {
return false;
}
+ if (!forum_user_can_see_timed_discussion($discussion, $user, $context)) {
+ return false;
+ }
+
+ if (!forum_user_can_see_group_discussion($discussion, $cm, $context)) {
+ return false;
+ }
+
if ($forum->type == 'qanda' &&
!forum_user_has_posted($forum->id, $discussion->id, $user->id) &&
!has_capability('mod/forum:viewqandawithoutposting', $context)) {
@@ -5265,6 +5320,9 @@ function forum_user_can_see_discussion($forum, $discussion, $context, $user=NULL
function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NULL) {
global $CFG, $USER, $DB;
+ // Context used throughout function.
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+
// retrieve objects (yuk)
if (is_numeric($forum)) {
debugging('missing full forum', DEBUG_DEVELOPER);
@@ -5285,6 +5343,7 @@ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NUL
return false;
}
}
+
if (!isset($post->id) && isset($post->parent)) {
$post->id = $post->parent;
}
@@ -5300,7 +5359,7 @@ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NUL
$user = $USER;
}
- $canviewdiscussion = !empty($cm->cache->caps['mod/forum:viewdiscussion']) || has_capability('mod/forum:viewdiscussion', get_context_instance(CONTEXT_MODULE, $cm->id), $user->id);
+ $canviewdiscussion = !empty($cm->cache->caps['mod/forum:viewdiscussion']) || has_capability('mod/forum:viewdiscussion', $modcontext, $user->id);
if (!$canviewdiscussion && !has_all_capabilities(array('moodle/user:viewdetails', 'moodle/user:readuserposts'), get_context_instance(CONTEXT_USER, $post->userid))) {
return false;
}
@@ -5315,9 +5374,16 @@ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NUL
}
}
+ if (!forum_user_can_see_timed_discussion($discussion, $user, $modcontext)) {
+ return false;
+ }
+
+ if (!forum_user_can_see_group_discussion($discussion, $cm, $modcontext)) {
+ return false;
+ }
+
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 (($userfirstpost !== false && (time() - $userfirstpost >= $CFG->maxeditingtime)) ||

0 comments on commit 8fb4c6e

Please sign in to comment.