Quiz overview report doesn't show enrolled user's attempts when users lack mod/quiz:reviewmyattempts permission

Quiz overview report doesn't show enrolled user's attempts when users lack mod/quiz:reviewmyattempts permission

by Peter Miller -
Number of replies: 6

I host a site for a client running Moodle 3.7.5 and I've run into this quirk:

They feel strongly that user's should not be able to review their quiz attempts, but this causes them to no show up in the overview report when filtering for enrolled users.

I understand why this is happening: the report filters out users lacking the 'mod/quiz:reviewmyattempts' permission. I'm just confused as to WHY they are filtered out on that permission as opposed to mod/quiz:attempt or on their actual enrollment status. The behavior feels very unintuitive to me and I'm inclined to modify the behavior on this site, but I'd like to figure out why filtering was done this way before I change anything.

I've searched through the forums to see if I could find any discussion on that, but I've so far come up short. Any insight would be appreciated.


Average of ratings: -
In reply to Peter Miller

Re: Quiz overview report doesn't show enrolled user's attempts when users lack mod/quiz:reviewmyattempts permission

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
In reply to Tim Hunt

Re: Quiz overview report doesn't show enrolled user's attempts when users lack mod/quiz:reviewmyattempts permission

by Peter Miller -

Thanks for putting me on the right path, I stepped through the get_with_capability_join code and I figured out what's going on.

The client didn't just remove the review permission, they set it to prevent.

https://github.com/moodle/moodle/blob/master/lib/accesslib.php#L7645
When it's looping over the role capabilities for each context, it sets the $access variable to allow for the student role to allow, and then overwrites that allow to a prevent when it processes the review permission.

This seems to imply that, when determining access per role with multiple capabilities set, it will set the access level to the record in the db with the highest ID. To test this, I swapped so attempt was set to prevent and reviewmyattempts was set to allow and the message about 'No students enrolled in this course yet' went away.

I should be able to resolve my issue by changing the permission from prevent to not set. Just wanted to share what I found.

In reply to Peter Miller

Re: Quiz overview report doesn't show enrolled user's attempts when users lack mod/quiz:reviewmyattempts permission

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Your message here talks about 'prevent', but the code you linked to has specific logic for CAP_PROHIBIT. The two concepts are different. Which is it?

Context ids are not significant. What is significant is the tree structure of contexts which is most clearly seen by looking at context.path. (However, since parent contexts probably have to be created before child contexts, it is probably the case that parents have smaller ids than children when you look in your DB, but this should never be used as the basis of any logic.)

http://aosabook.org/en/moodle.html has a technical description of how the rules system is supposed to work.

Anyway, it seems there is a bug. Steps to reproduce:

  1. Go to the quiz report for a quiz (e.g. https://qa.moodledemo.net/mod/quiz/report.php?id=30&mode=overview)
  2. Note that some students are shown
  3. In another tab, open the Permissions setting for that quiz (e.g. https://qa.moodledemo.net/admin/roles/permissions.php?contextid=9063)
  4. Remove one of the mod/quiz:reviewmyattempts or mod/quiz:attempt capabilities, but not both. 
  5. Reload the quiz report.

Expected result: the students are not shown.

Actual result: 'No students enrolled in this course yet' message.

I created MDL-68402 for this.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Quiz overview report doesn't show enrolled user's attempts when users lack mod/quiz:reviewmyattempts permission

by Peter Miller -
Sorry, I was careless with my verbiage -- it was prevent. I fixed the issue for the client by unsetting the permission.

Tim -- you were incredibly helpful! Thank you!
In reply to Peter Miller

Re: Quiz overview report doesn't show enrolled user's attempts when users lack mod/quiz:reviewmyattempts permission

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well, I am stuck at home thanks to COVID-19, so at least fixing this bug gave me a fun puzzle to solve. (I have already scrambled and solved all my rubiks cubes.)
In reply to Tim Hunt

Re: Quiz overview report doesn't show enrolled user's attempts when users lack mod/quiz:reviewmyattempts permission

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

If you need another fun puzzle to solve, I have that one, still, that you've given me advice on before regarding adding/playing audio files into MooTyper. 😁