Moodle

Profile 'Forum Posts' tab does not obey mod/forum:viewqandawithoutposting

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.1, 1.9.2
  • Fix Version/s: None
  • Component/s: Forum
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE

Description

In a Q and A type, a person cannot view posts until they post something of their own. When the profile view is generated, it applies this logic, but does not obey they 'View Without Posting' permission.

I've found a work around based on the way mod/forum/lib.php - forum_get_readable_forums works.
Down on line 1621, it checks to see if the user has mod/forum:viewqandawithoutposting. If they don't, to creates an empty array in $forum->onlydiscussions, then populates it with discussions they have posted in. If they do have this perm, it totally skips this step, so $forum->onlydiscussions is not set.

In mod/forum/lib.php - forum_search_posts it only checks empty($forum->onlydiscussions) or not, but not viewqandawithoutposting, so if have viewqandawithoutposting but have not posted in the discussion, you cannot see the other posts in the discussion listed there, even though you should.

The workaround I have made takes advantage of the fact that for someone without the perm, $forum->onlydiscussions is an empty array, while with someone with the perm, $forum->onlydiscussions is not set, so I changed the block starting on line 1681 from:
if ($forum->type == 'qanda') {
if (!empty($forum->onlydiscussions)) { $discussionsids = implode(',', $forum->onlydiscussions); $select[] = "(d.id IN ($discussionsids) OR p.parent = 0)"; } else { $select[] = "p.parent = 0"; }
}

to (only 5th line changes):
if ($forum->type == 'qanda') {
if (!empty($forum->onlydiscussions)) { $discussionsids = implode(',', $forum->onlydiscussions); $select[] = "(d.id IN ($discussionsids) OR p.parent = 0)"; } } elseif (isset($forum->onlydiscussions)) { $select[] = "p.parent = 0"; }
}

This seems like there should be a cleaner solution, but i dont know.

Issue Links

Activity

Hide
Ann Adamcik added a comment -

It might be a bit more straightforward to just check for the mod/forum:viewqandawithoutposting capability when building the select. A patch is attached.

Show
Ann Adamcik added a comment - It might be a bit more straightforward to just check for the mod/forum:viewqandawithoutposting capability when building the select. A patch is attached.
Hide
Dongsheng Cai added a comment -

I committed this patch, thanks Ann and Eric

Show
Dongsheng Cai added a comment - I committed this patch, thanks Ann and Eric
Hide
Michael Penney added a comment -

Was the patch committed in 1.9.2, 1.9.4 or what version?

Show
Michael Penney added a comment - Was the patch committed in 1.9.2, 1.9.4 or what version?

People

Vote (6)
Watch (6)

Dates

  • Created:
    Updated:
    Resolved: