Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-33166 forum: fetch cmid to be used by capability checks.

  • Loading branch information...
commit 601071fb1043724d82825467ba4bebe27a39f43b 1 parent b4e47db
Eloy Lafuente (stronk7) authored September 19, 2012

Showing 1 changed file with 11 additions and 5 deletions. Show diff stats Hide diff stats

  1. 16  mod/forum/lib.php
16  mod/forum/lib.php
@@ -4544,8 +4544,9 @@ function forum_is_subscribed($userid, $forum) {
4544 4544
         $forum = $DB->get_record('forum', array('id' => $forum));
4545 4545
     }
4546 4546
     // If forum is force subscribed and has allowforcesubscribe, then user is subscribed.
4547  
-    if (forum_is_forcesubscribed($forum) &&
4548  
-            has_capability('mod/forum:allowforcesubscribe', context_module::instance($forum->id), $userid)) {
  4547
+    $cm = get_coursemodule_from_instance('forum', $forum->id);
  4548
+    if (forum_is_forcesubscribed($forum) && $cm &&
  4549
+            has_capability('mod/forum:allowforcesubscribe', context_module::instance($cm->id), $userid)) {
4549 4550
         return true;
4550 4551
     }
4551 4552
     return $DB->record_exists("forum_subscriptions", array("userid" => $userid, "forum" => $forum->id));
@@ -6038,16 +6039,21 @@ function forum_user_role_assigned($cp) {
6038 6039
         return;
6039 6040
     }
6040 6041
 
6041  
-    $sql = "SELECT f.id
  6042
+    $sql = "SELECT f.id, cm.id AS cmid
6042 6043
               FROM {forum} f
  6044
+              JOIN {course_modules} cm ON (cm.instance = f.id)
  6045
+              JOIN {modules} m ON (m.id = cm.module)
6043 6046
          LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = :userid)
6044  
-             WHERE f.course = :courseid AND f.forcesubscribe = :initial AND fs.id IS NULL";
  6047
+             WHERE f.course = :courseid
  6048
+               AND f.forcesubscribe = :initial
  6049
+               AND m.name = 'forum'
  6050
+               AND fs.id IS NULL";
6045 6051
     $params = array('courseid'=>$context->instanceid, 'userid'=>$cp->userid, 'initial'=>FORUM_INITIALSUBSCRIBE);
6046 6052
 
6047 6053
     $forums = $DB->get_records_sql($sql, $params);
6048 6054
     foreach ($forums as $forum) {
6049 6055
         // If user doesn't have allowforcesubscribe capability then don't subscribe.
6050  
-        if (has_capability('mod/forum:allowforcesubscribe', context_module::instance($forum->id), $cp->userid)) {
  6056
+        if (has_capability('mod/forum:allowforcesubscribe', context_module::instance($forum->cmid), $cp->userid)) {
6051 6057
             forum_subscribe($cp->userid, $forum->id);
6052 6058
         }
6053 6059
     }

0 notes on commit 601071f

Please sign in to comment.
Something went wrong with that request. Please try again.