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

has_capability() does not return the correct result for some tasks if user data marked "dirty" (requiring re-fetching)

XMLWordPrintable

    • MOODLE_403_STABLE, MOODLE_404_STABLE
    • MOODLE_403_STABLE, MOODLE_404_STABLE
    • MDL-81991-403-alt
    • MDL-81991-404-alt
    • MDL-81991-main-alt
    • Hide

      Note: Tester can follow the testing instructions without the patch to replicate the issue. Without the patch, Step 13 will return the wrong data: User has capability

      Initial setup

      1. Download adhoc_bug.phpand put it in: admin/tool/task/classes/adhoc_bug.php
      2. Download testadhoc.phpand put it in: admin/testadhoc.php
      3. Purge the cache if needed.
      4. Create a course called: Test-81991. Note the course id.
      5. Create a user called: s1. Note the user id.
      6. Open the admin/testadhoc.php
      7. Change userid and courseid to yours. Save and close.

      Testing

      1. Open terminal
      2. Run: 

        php admin/cli/adhoc_task.php --execute --keep-alive=500

      3. Login as admin.
      4. Navigate to the created course -> Participant.
      5. Enrol the s1 to the course as a Teacher role.
      6. Open this URL in another browser tab: http://[your_moodle_url]/admin/testadhoc.php
      7. Verify that you will see: Task has been queued
      8. Verify that you will see: User has capability in the terminal window.
      9. Switch to the Participant browser.
      10. Click the Edit (Pencil icon) button in the Role column of s1 user.
      11. Remove the Teacher role.
      12. Click Save.
      13. Open this URL in another browser tab: http://[your_moodle_url]/admin/testadhoc.php
      14. Verify that you will see: Task has been queued
      15. Verify that you will see: User does not have capability in the terminal window.
      Show
      Note : Tester can follow the testing instructions without the patch to replicate the issue. Without the patch, Step 13 will return the wrong data: User has capability Initial setup Download adhoc_bug.php and put it in: admin/tool/task/classes/adhoc_bug.php Download testadhoc.php and put it in: admin/testadhoc.php Purge the cache if needed. Create a course called: Test-81991. Note the course id. Create a user called: s1. Note the user id. Open the admin/testadhoc.php Change userid and courseid to yours. Save and close. Testing Open terminal Run:  php admin/cli/adhoc_task.php --execute --keep-alive= 500 Login as admin. Navigate to the created course -> Participant. Enrol the s1 to the course as a Teacher role. Open this URL in another browser tab: http://[your_moodle_url]/admin/testadhoc.php Verify that you will see: Task has been queued Verify that you will see: User has capability in the terminal window. Switch to the Participant browser. Click the Edit (Pencil icon) button in the Role column of s1 user. Remove the Teacher role. Click Save. Open this URL in another browser tab: http://[your_moodle_url]/admin/testadhoc.php Verify that you will see: Task has been queued Verify that you will see: User does not have capability in the terminal window.
    • 6
    • Team Hedgehog 2024 Sprint 2.1, Team Hedgehog 2024 Sprint 2.2, Team Hedgehog 2024 Sprint 2.3

      When we remove a role (Example: Teacher) out of a user in a course. Moodle will mark that user as dirty. All the permissions of that user need to be reloaded.

      It's okay via UI or a single run of scheduled tasks or ad-hoc tasks.

      But if the scheduled task or ad-hoc task is triggered via the keep-alive instance, the permissions are not reloaded

      The has_capability() method will return the old data of that user.

      I have attached a sample code to demonstrate the bug.

        1. adhoc_bug.php
          1 kB
        2. MDL-81991.png
          MDL-81991.png
          203 kB
        3. testadhoc.php
          1 kB

            huongn@moodle.com Huong Nguyen
            huongn@moodle.com Huong Nguyen
            Raquel Ortega Raquel Ortega
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 week, 1 day, 5 hours, 56 minutes
                1w 1d 5h 56m

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