Details
Description
For non-admins: Subscribe to all forums from /forum/index.php (all forums in a course listing) does not function and users subscriptions are not changed. The unsubscribe from all does work. .
The errors in the php log for each forum that the script tries to subscribe to are along the lines of:
[Thu Jan 15 16:20:59 2009] [error] [client 144.32.148.21] PHP Notice: Context id 113 does not have valid path, please use build_context_path()<ul style="text-align: left"><li>line 375 of lib
accesslib.php: call to debugging()</li><li>line 125 of mod\\forum
index.php: call to has_capability()</li></ul> in \\lib
weblib.php on line 6923, referer: mod/forum/index.php?id=2
[Thu Jan 15 16:20:59 2009] [error] [client 144.32.148.21] PHP Notice: Undefined property: object::$contextlevel in \\lib
accesslib.php on line 442, referer: mod/forum/index.php?id=2
[Thu Jan 15 16:20:59 2009] [error] [client 144.32.148.21] PHP Notice: Undefined property: object::$path in \\lib
accesslib.php on line 371, referer: mod/forum/index.php?id=2
I've tried this on a fresh course and a fresh 1.9.3 install, so not sure why the contexts aren't right. As suggested, tried the rebuild context script but no change. In mod/forum/index.php I can force $cansub = true; to get it to work but that would open up security loopholes. Would this be a problem then with what gets passed (i.e. $cm) to the has_capability function??
I've done a couple of scenarios with a fresh install:
1) Student role only in course = doesn't work at all.
2) Student role on homepage and in course (our normal setup) = doesn't work for homepage forums, 'subscribe to all' works only for the first learning forum in course.
3) Student role granted site-wide (i.e. from Assign System Roles) = everything works ok.
Bug created after discussion:
http://moodle.org/mod/forum/discuss.php?d=114080
Students can obviously use the individual 'yes/no' buttons next to each forum for the time being and this bug does not affect the 'subscribe to THIS forum' link in each forum.
Attachments
Issue Links
| This issue has been marked as being related by: | ||||
| MDL-15317 | Forums with restricted access have subscribers without appropriate rights |
|
|
|
I think this is the fix:
In mod/forum/index.php, around line 123:
/// Do course wide subscribe/unsubscribe
if (!is_null($subscribe) and !isguestuser() and !isguest()) {
foreach ($modinfo->instances['forum'] as $forumid=>$cm) {
$forum = $forums[$forumid];
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$cansub = false;
{ $cansub = false; }if (has_capability('mod/forum:viewdiscussion', $context)) { $cansub = true; }
if ($cansub && $cm->visible == 0 &&
!has_capability('mod/forum:managesubscriptions', $context))
...
The original code (in v1.9.4) is passing a course module to has_capability. It needs to pass the course module's context... So I used get_context_instance to retrieve the appropriate context and passed that intsead of $cm.
I'll attach my changes as a diff. I don't have Moodle CVS access... Can someone confirm this is the fix, and pull it in?
Cheers,