]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10990 forum perf revisited - reply and post discussion buttons now back for guest...
authorskodak <skodak>
Tue, 18 Mar 2008 17:08:15 +0000 (17:08 +0000)
committerskodak <skodak>
Tue, 18 Mar 2008 17:08:15 +0000 (17:08 +0000)
mod/forum/discuss.php
mod/forum/lib.php

index 558dfa6459b7ab422deaa9340df6a70bb154f96b..fd3d5bd7a9669ef858e3e43c043149d591506ef5 100644 (file)
     }
 
     $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
 
index 07bf154fe8e81a63f932e657ccd1dee6e72073a0..22bcf3f9021d9ef4c925b9519809088fb4647d83 100644 (file)
@@ -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 '<div class="singlebutton forumaddnew">';
         echo "<form id=\"newdiscussionform\" method=\"get\" action=\"$CFG->wwwroot/mod/forum/post.php\">";