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

instance_allow_multiple() can be bypassed for blocks

XMLWordPrintable

      Steps to reproduce:

      1. Create a course
      2. Turn on edit mode
      3. Open the course page in two windows.
      4. Open the block drawer in both windows
      5. Click on the „Add block“ button in both windows.
      6. Click on "Logged in user" (this is block_myprofile) in both windows.
      7. Confirm the block is added twice (which should not be possible).

      This is a serious issue in some cases as some blocks (e.g. block_stash which caused this problem at our site repeatedly) expect that there is only one instance and use code like $DB->get_record() which can throw an exception when retrieving multiple records. This makes a course completely unusable.

      The problem has three parts:

      • block_manager::add_block() doesn't check whether the passed block can be added
      • block_manager::get_addable_blocks() uses block_manager::is_block_present() to check whether there is already an instance. But is_block_present() uses $this->blockinstances instead of $this->birecordsbyregion to check, the first mentioned is empty when calling add_block().
      • Unit tests in core_block\externallib_test and block_html\privacy\provider_test didn't care for the right capabilities until now. I updated them accordingly (as one part affects block_html, I moved that to a separate commit).

        1. 84611 test - 405.png
          138 kB
          Andrew Gosali
        2. 84611 test - 500.png
          120 kB
          Andrew Gosali
        3. 84611 test - main.png
          213 kB
          Andrew Gosali

            stefan.hanauska Stefan Hanauska
            stefan.hanauska Stefan Hanauska
            Meirza Meirza
            David Woloszyn David Woloszyn
            Andrew Gosali Andrew Gosali
            Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours, 46 minutes
                2h 46m

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