Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-62038

Switch role feature: Switching role to student in hidden courses cause error when calendar blocks are placed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 3.4, 3.4 regressions, 3.5
    • Fix Version/s: None
    • Component/s: Blocks, Calendar, Course
    • Labels:
      None
    • Affected Branches:
      MOODLE_34_STABLE, MOODLE_35_STABLE

      Description

      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:

      1. Login as admin and create a new course with visibility hidden and enrol user A as a teacher in this course
      2. Logout and login as user A and open this course
      3. 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
      4. Turn editing on
      5. Add the block "Calendar" to the course
      6. 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)"
      7. 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
      8. Delete the block "Calendar" from the course
      9. 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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                lucaboesch Luca Bösch
                Reporter:
                kosswa Kathrin Osswald
                Participants:
                Component watchers:
                Adrian Greeve, Mihail Geshoski, Peter Dias, Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze, Amaia Anabitarte, Bas Brands, Carlos Escobedo, Sara Arjona (@sarjona), Víctor Déniz Falcón
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: