From: moodler Date: Fri, 29 Feb 2008 15:28:03 +0000 (+0000) Subject: Merged MDL-10990 (5) revert in 1.9 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7d225563bd123cdd86e5c6d1930c2bcf6f97ee83;p=moodle.git Merged MDL-10990 (5) revert in 1.9 --- diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 3f01ace3ba..9f06e5c3b0 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3823,26 +3823,16 @@ function forum_user_can_post_discussion($forum, $currentgroup=-1, $groupmode=-1, // $forum is an object global $USER, $SESSION, $COURSE; - // shortcut - guest and not-logged-in users can not post - if (isguestuser() or !isloggedin()) { - return false; + if (!$cm) { + debugging('missing cm', DEBUG_DEVELOPER); + if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) { + error('Course Module ID was incorrect'); + } } - if (!$context) { - if (!$cm) { - debugging('missing cm', DEBUG_DEVELOPER); - if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) { - error('Course Module ID was incorrect'); - } - } $context = get_context_instance(CONTEXT_MODULE, $cm->id); } - // normal users with temporary guest access can not add discussions - if (has_capability('moodle/legacy:guest', $context, $USER->id, false)) { - return false; - } - if ($currentgroup == -1) { $currentgroup = get_current_group($cm->course); } @@ -3891,15 +3881,6 @@ function forum_user_can_post_discussion($forum, $currentgroup=-1, $groupmode=-1, * @param $user - user object */ function forum_user_can_post($forum, $user=NULL, $cm=NULL, $context=NULL) { - global $USER; - if (empty($user)) { - $user = $USER; - } - - // shortcut - guest and not-logged-in users can not post - if (isguestuser($user) or empty($user->id)) { - return false; - } if (!$context) { if (!$cm) { @@ -3911,18 +3892,21 @@ function forum_user_can_post($forum, $user=NULL, $cm=NULL, $context=NULL) { $context = get_context_instance(CONTEXT_MODULE, $cm->id); } - // normal users with temporary guest access can not post - if (has_capability('moodle/legacy:guest', $context, $user->id, false)) { - return false; - } - if ($forum->type == 'news') { $capname = 'mod/forum:replynews'; } else { $capname = 'mod/forum:replypost'; } - return has_capability($capname, $context, $user->id, false); + if (!empty($user)) { + $canreply = has_capability($capname, $context, $user->id, false) + && !has_capability('moodle/legacy:guest', $context, $user->id, false); + } else { + $canreply = has_capability($capname, $context, NULL, false) + && !has_capability('moodle/legacy:guest', $context, NULL, false); + } + + return $canreply; } @@ -4110,7 +4094,7 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=5, $dis // and the current user is a guest. if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context) || - ($forum->type != 'news' and (isguestuser() or !isloggedin())) ) { + ($forum->type != 'news' && has_capability('moodle/legacy:guest', $context, NULL, false)) ) { echo '
'; echo "
wwwroot/mod/forum/post.php\">";