-
Bug
-
Resolution: Fixed
-
Major
-
4.4.7, 4.5, 5.0
Steps to reproduce:
- Create a course
- Turn on edit mode
- Open the course page in two windows.
- Open the block drawer in both windows
- Click on the „Add block“ button in both windows.
- Click on "Logged in user" (this is block_myprofile) in both windows.
- 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).