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

Calendar API has a hidden dependency on the logged in user

XMLWordPrintable

    • MOODLE_33_STABLE, MOODLE_34_STABLE, MOODLE_35_STABLE
    • MOODLE_34_STABLE, MOODLE_35_STABLE
    • MDL-58768-master-2
    • Hide

      In all the following tests, when you are setting a date, pick a date that is not very far from today. for example, set a date within the next 7 days.

      Testing get_raw_events()

      1. Log in as an Admin
      2. Create a course and enrol a user s1 in it. (Take note of s1's user ID)
      3. Create an assignment (make sure to specify a due date) in the course
      4. Download eventstest.php to your Moodle's root folder.
      5. Edit the attached test script, setting the $userid variable to the s1's user ID.
      6. Run the script:

        php eventstest.php
        

      7. Verify that you see the event related to the assignment
      8. Log in to Moodle as s1
      9. Refresh the test script
      10. Verify that you still see the event related to the assignment
      11. Log out of Moodle
      12. Refresh the test script
      13. Verify that you still see the event related to the assignment

      Exporting user and group events

      1. Create a course and then create 2 groups in the course (group1 & group2)
      2. Create 2 users (user1 & user2) and enrol them into the course as a student.
      3. Add user1 to group1 and add user2 to group2.
      4. Create an assignment in the course and set a due date for the assignment.
      5. Navigate to the calendar month view in the course.
      6. Click on the "new event" button and create a group event for group1.
      7. Click on the "new event" button and create a group event for group2.
      8. Log in as user1
      9. Go to the calendar and create a user event
      10. Click on the "Export calendar" icon, and choose the following:
        Events to export: all events
        Time period: Recent and next 60 days
        and then click on the "Get calendar URL" button.
      11. Copy the calendar URL link
      12. Open a new browser session (close all browser windows and open one. or open a different browser which does not have an active Moodle session).
      13. Enter the URL from step 10 in the new browser and download the file.
      14. Open the downloaded file. If you don't have an application to open ics files, you can use a text editor.
      15. Verify that the downloaded file contains events for the assignment (step 4), the group event for group1 (step 6), and the user event (step 9).
      16. Verify that the downloaded file does not contain the event for group2 (step 7).
      Show
      In all the following tests, when you are setting a date, pick a date that is not very far from today. for example, set a date within the next 7 days. Testing get_raw_events() Log in as an Admin Create a course and enrol a user s1 in it. (Take note of s1's user ID) Create an assignment (make sure to specify a due date) in the course Download eventstest.php to your Moodle's root folder. Edit the attached test script, setting the  $userid  variable to the s1's user ID. Run the script: php eventstest.php Verify that you see the event related to the assignment Log in to Moodle as s1 Refresh the test script Verify  that you still see the event related to the assignment Log out of Moodle Refresh the test script Verify  that you still see the event related to the assignment Exporting user and group events Create a course and then create 2 groups in the course (group1 & group2) Create 2 users (user1 & user2) and enrol them into the course as a student. Add user1 to group1 and add user2 to group2. Create an assignment in the course and set a due date for the assignment. Navigate to the calendar month view in the course. Click on the "new event" button and create a group event for group1. Click on the "new event" button and create a group event for group2. Log in as user1 Go to the calendar and create a user event Click on the "Export calendar" icon, and choose the following: Events to export: all events Time period: Recent and next 60 days and then click on the "Get calendar URL" button. Copy the calendar URL link Open a new browser session (close all browser windows and open one. or open a different browser which does not have an active Moodle session). Enter the URL from step 10 in the new browser and download the file. Open the downloaded file. If you don't have an application to open ics files, you can use a text editor. Verify that the downloaded file contains events for the assignment (step 4), the group event for group1 (step 6), and the user event (step 9). Verify that the downloaded file does not contain the event for group2 (step 7).

      For details see: MDL-58736

      tl;dr the way we pull events out of the database and resolve overrides is not consistent with the way the API was designed. We expect a user to be passed around, but the function that actually retrieves the events from the table has a dependency on the logged in user.

      It never manifests itself as a bug anywhere in core as far as I can tell, since all of the functionality we have implemented is for the current logged in user, but it can be reproduced with the attached test script after following these steps:

      1. Create a course and enrol a user in it (take note of the ID)
      2. Create an assignment in the course
      3. Edit the attached test script, setting the $userid variable to the ID from step 1
      4. Place the attached test script in your moodle document root and run it from your browser
      5. You will not see any events returned, even though you should
      6. Log in to moodle as the user from step 1
      7. Refresh the test script
      8. You will see the events

      This came about because we tried to resolve overrides using SQL (see calendar/classes/local/event/strategies/raw_event_retrieval_strategy, when really it makes a load more sense to pull all the relevant records out of the database and resolve overrides with PHP.

            rezaie9 Shamim Rezaie
            cameron1729 cameron1729
            Simey Lameze Simey Lameze
            Jun Pataleta Jun Pataleta
            Janelle Barcega Janelle Barcega
            Votes:
            23 Vote for this issue
            Watchers:
            31 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 30 minutes
                1h 30m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.