Hi,
we've encountered the following issue:
Since the refactoring of the calendar with Moodle 3.4, switching the role to a student (or any other role that does not obtain the capability moodle/course:viewhiddencourses) in a hidden course leads to an error if the block block_calendar_upcoming or block_calendar_month are added to the course.
Those are the strack traces:
// Calendar Month
|
Debug info:
|
Error code: nopermissions
|
Stack trace:
|
line 816 of /lib/accesslib.php: required_capability_exception thrown
|
line 1066 of /calendar/lib.php: call to require_capability()
|
line 53 of /blocks/calendar_month/block_calendar_month.php: call to calendar_information::create()
|
line 288 of /blocks/moodleblock.class.php: call to block_calendar_month->get_content()
|
line 230 of /blocks/moodleblock.class.php: call to block_base->formatted_contents()
|
line 1211 of /lib/blocklib.php: call to block_base->get_content_for_output()
|
line 1263 of /lib/blocklib.php: call to block_manager->create_block_contents()
|
line 374 of /lib/blocklib.php: call to block_manager->ensure_content_created()
|
line 3912 of /lib/outputrenderers.php: call to block_manager->region_has_content()
|
line 40 of /theme/boost/layout/columns2.php: call to core_renderer->blocks()
|
line 1261 of /lib/outputrenderers.php: call to include()
|
line 1191 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
|
line 244 of /course/view.php: call to core_renderer->header()
|
|
// Calendar upcoming
|
Debug info:
|
Error code: nopermissions
|
Stack trace:
|
line 816 of /lib/accesslib.php: required_capability_exception thrown
|
line 1066 of /calendar/lib.php: call to require_capability()
|
line 52 of /blocks/calendar_upcoming/block_calendar_upcoming.php: call to calendar_information::create()
|
line 288 of /blocks/moodleblock.class.php: call to block_calendar_upcoming->get_content()
|
line 230 of /blocks/moodleblock.class.php: call to block_base->formatted_contents()
|
line 1211 of /lib/blocklib.php: call to block_base->get_content_for_output()
|
line 1263 of /lib/blocklib.php: call to block_manager->create_block_contents()
|
line 374 of /lib/blocklib.php: call to block_manager->ensure_content_created()
|
line 3912 of /lib/outputrenderers.php: call to block_manager->region_has_content()
|
line 40 of /theme/boost/layout/columns2.php: call to core_renderer->blocks()
|
line 1261 of /lib/outputrenderers.php: call to include()
|
line 1191 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
|
line 244 of /course/view.php: call to core_renderer->header()
|
In this case the teacher cannot switch the role in this course and he just get the error message "Sorry, but you do not currently have permissions to do that (View hidden courses)".
Steps to reproduce:
- Login as admin and create a new course with visibility hidden and enrol user A as a teacher in this course
- Logout and login as user A and open this course
- Switch the role to a role that does not obtain moodle/course:viewhiddencourses (usually student)
=> See that the role switching worked and switch back to your own role - Turn editing on
- Add the block "Calendar" to the course
- Switch the role to student again
=> See the error with the notice "Sorry, but you do not currently have permissions to do that (View hidden courses)" - Go back to the course and try to get back to your initial role. If you have problems, logout and login as user A again
- Delete the block "Calendar" from the course
- Add the block "Upcoming events"
Switch the role to student again
=> See the error with the notice "Sorry, but you do not currently have permissions to do that (View hidden courses)"
Best, Kathrin
The code with the requires_capability that leads to this side effect is in this commit:
https://github.com/moodle/moodle/commit/7b7bf31d4c86189199a50197b391fe0611be8a2e