From 7214101bd598b0d81c7e6279daf6230791092e87 Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 18 Mar 2008 17:08:15 +0000 Subject: [PATCH] MDL-10990 forum perf revisited - reply and post discussion buttons now back for guests; merged from MOODLE_19_STABLE --- mod/forum/discuss.php | 2 +- mod/forum/lib.php | 47 +++++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index 558dfa6459..fd3d5bd7a9 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -153,7 +153,7 @@ } $canreply = false; - if (isguestuser() or !isloggedin()) { + if (isguestuser() or !isloggedin() or has_capability('moodle/legacy:guest', $modcontext, NULL, false)) { // allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link $canreply = ($forum->type != 'news'); // no reply in news forums diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 07bf154fe8..22bcf3f902 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3835,16 +3835,26 @@ function forum_user_can_post_discussion($forum, $currentgroup=-1, $groupmode=-1, // $forum is an object global $USER, $SESSION, $COURSE; - if (!$cm) { - debugging('missing cm', DEBUG_DEVELOPER); - if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) { - error('Course Module ID was incorrect'); - } + // shortcut - guest and not-logged-in users can not post + if (isguestuser() or !isloggedin()) { + return false; } + 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); } @@ -3893,6 +3903,15 @@ 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) { @@ -3904,21 +3923,18 @@ 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'; } - 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; + return has_capability($capname, $context, $user->id, false); } @@ -4106,7 +4122,8 @@ 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' && has_capability('moodle/legacy:guest', $context, NULL, false)) ) { + ($forum->type != 'news' + and (isguestuser() or !isloggedin() or has_capability('moodle/legacy:guest', $context, NULL, false))) ) { echo '
'; echo "
wwwroot/mod/forum/post.php\">"; -- 2.39.5