Permalink
Browse files

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

  • Loading branch information...
1 parent b4e47db commit 601071fb1043724d82825467ba4bebe27a39f43b @stronk7 stronk7 committed Sep 19, 2012
Showing with 11 additions and 5 deletions.
  1. +11 −5 mod/forum/lib.php
View
16 mod/forum/lib.php
@@ -4544,8 +4544,9 @@ function forum_is_subscribed($userid, $forum) {
$forum = $DB->get_record('forum', array('id' => $forum));
}
// If forum is force subscribed and has allowforcesubscribe, then user is subscribed.
- if (forum_is_forcesubscribed($forum) &&
- has_capability('mod/forum:allowforcesubscribe', context_module::instance($forum->id), $userid)) {
+ $cm = get_coursemodule_from_instance('forum', $forum->id);
+ if (forum_is_forcesubscribed($forum) && $cm &&
+ has_capability('mod/forum:allowforcesubscribe', context_module::instance($cm->id), $userid)) {
return true;
}
return $DB->record_exists("forum_subscriptions", array("userid" => $userid, "forum" => $forum->id));
@@ -6038,16 +6039,21 @@ function forum_user_role_assigned($cp) {
return;
}
- $sql = "SELECT f.id
+ $sql = "SELECT f.id, cm.id AS cmid
FROM {forum} f
+ JOIN {course_modules} cm ON (cm.instance = f.id)
+ JOIN {modules} m ON (m.id = cm.module)
LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = :userid)
- WHERE f.course = :courseid AND f.forcesubscribe = :initial AND fs.id IS NULL";
+ WHERE f.course = :courseid
+ AND f.forcesubscribe = :initial
+ AND m.name = 'forum'
+ AND fs.id IS NULL";
$params = array('courseid'=>$context->instanceid, 'userid'=>$cp->userid, 'initial'=>FORUM_INITIALSUBSCRIBE);
$forums = $DB->get_records_sql($sql, $params);
foreach ($forums as $forum) {
// If user doesn't have allowforcesubscribe capability then don't subscribe.
- if (has_capability('mod/forum:allowforcesubscribe', context_module::instance($forum->id), $cp->userid)) {
+ if (has_capability('mod/forum:allowforcesubscribe', context_module::instance($forum->cmid), $cp->userid)) {
forum_subscribe($cp->userid, $forum->id);
}
}

0 comments on commit 601071f

Please sign in to comment.