mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
Merge branch 'MDL-74078-master' of https://github.com/mickhawkins/moodle
This commit is contained in:
commit
e9883614ab
@ -422,6 +422,11 @@ class moodle_page {
|
||||
*/
|
||||
protected $_navigationoverflow = true;
|
||||
|
||||
/**
|
||||
* @var bool Whether to override/remove all editing capabilities for blocks on the page.
|
||||
*/
|
||||
protected $_forcelockallblocks = false;
|
||||
|
||||
/**
|
||||
* Force the settings menu to be displayed on this page. This will only force the
|
||||
* settings menu on an activity / resource page that is being displayed on a theme that
|
||||
@ -1052,10 +1057,12 @@ class moodle_page {
|
||||
|
||||
/**
|
||||
* Does the user have permission to edit blocks on this page.
|
||||
* Can be forced to false by calling the force_lock_all_blocks() method.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function user_can_edit_blocks() {
|
||||
return has_capability($this->_blockseditingcap, $this->_context);
|
||||
return $this->_forcelockallblocks ? false : has_capability($this->_blockseditingcap, $this->_context);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1596,6 +1603,17 @@ class moodle_page {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove access to editing/moving on all blocks on a page.
|
||||
* This overrides any capabilities and is intended only for pages where no user (including admins) should be able to
|
||||
* modify blocks on the page (eg My Courses).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function force_lock_all_blocks(): void {
|
||||
$this->_forcelockallblocks = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since Moodle 3.4
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@
|
||||
* @category phpunit
|
||||
* @copyright 2009 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \moodle_page
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
@ -763,6 +764,47 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests user_can_edit_blocks() returns the expected response.
|
||||
* @covers ::user_can_edit_blocks()
|
||||
*/
|
||||
public function test_user_can_edit_blocks() {
|
||||
global $DB;
|
||||
|
||||
$systemcontext = context_system::instance();
|
||||
$this->testpage->set_context($systemcontext);
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$role = $DB->get_record('role', ['shortname' => 'teacher']);
|
||||
role_assign($role->id, $user->id, $systemcontext->id);
|
||||
$this->setUser($user);
|
||||
|
||||
// Confirm expected response (false) when user does not have access to edit blocks.
|
||||
$capability = $this->testpage->all_editing_caps()[0];
|
||||
assign_capability($capability, CAP_PROHIBIT, $role->id, $systemcontext, true);
|
||||
$this->assertFalse($this->testpage->user_can_edit_blocks());
|
||||
|
||||
// Give capability and confirm expected response (true) now user has access to edit blocks.
|
||||
assign_capability($capability, CAP_ALLOW, $role->id, $systemcontext, true);
|
||||
$this->assertTrue($this->testpage->user_can_edit_blocks());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that calling force_lock_all_blocks() will cause user_can_edit_blocks() to return false, regardless of capabilities.
|
||||
* @covers ::force_lock_all_blocks()
|
||||
*/
|
||||
public function test_force_lock_all_blocks() {
|
||||
$this->testpage->set_context(context_system::instance());
|
||||
$this->setAdminUser();
|
||||
|
||||
// Confirm admin user has access to edit blocks.
|
||||
$this->assertTrue($this->testpage->user_can_edit_blocks());
|
||||
|
||||
// Force lock and confirm user can no longer edit, despite having the capability.
|
||||
$this->testpage->force_lock_all_blocks();
|
||||
$this->assertFalse($this->testpage->user_can_edit_blocks());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,6 +224,9 @@ defined or can't be applied.
|
||||
* Calendar, Timeline - Center
|
||||
* Recently accessed courses - Side bar/blocks drawer
|
||||
* Flat navigation classes have been marked for deprecation with the introduction of primary and secondary navigation concepts.
|
||||
* A new method, force_lock_all_blocks(), has been added to the moodle_page class to allow pages to force the value of
|
||||
user_can_edit_blocks() to return false where necessary. This makes it possible to remove block editing on a page
|
||||
from ALL users, including admins, where required on pages with multi region layouts exist, such as "My courses".
|
||||
|
||||
=== 3.11.4 ===
|
||||
* A new option dontforcesvgdownload has been added to the $options parameter of the send_file() function.
|
||||
|
@ -58,6 +58,13 @@ $PAGE->blocks->add_region('content');
|
||||
$PAGE->set_subpage($currentpage->id);
|
||||
$PAGE->set_title(get_string('mycourses'));
|
||||
$PAGE->set_heading(get_string('mycourses'));
|
||||
|
||||
// No blocks can be edited on this page (including by managers/admins) because:
|
||||
// - Course overview is a fixed item on the page and cannot be moved/removed.
|
||||
// - We do not want new blocks on the page.
|
||||
// - Only global blocks (if any) should be visible on the site panel, and cannot be moved int othe centre pane.
|
||||
$PAGE->force_lock_all_blocks();
|
||||
|
||||
// Force the add block out of the default area.
|
||||
$PAGE->theme->addblockposition = BLOCK_ADDBLOCK_POSITION_CUSTOM;
|
||||
|
||||
|
@ -86,3 +86,28 @@ Feature: Run tests over my courses.
|
||||
And I click on "Manage courses" "link"
|
||||
And I wait to be redirected
|
||||
And I should see "Manage course categories and courses"
|
||||
|
||||
@javascript
|
||||
Scenario: Admin can see relevant blocks but not add or move them
|
||||
Given I log in as "admin"
|
||||
And I am on site homepage
|
||||
And I turn editing mode on
|
||||
And I add the "Text" block
|
||||
And I configure the "(new text block)" block
|
||||
And I set the following fields to these values:
|
||||
| Page contexts | Display throughout the entire site |
|
||||
| Text block title | Text on all pages |
|
||||
| Content | This is visible on all pages |
|
||||
| Default region | Right |
|
||||
And I press "Save changes"
|
||||
And I should see "This is visible on all pages"
|
||||
And "Move Text on all pages block" "button" should exist in the "Text on all pages" "block"
|
||||
When I am on the "My courses" page
|
||||
# Check blocks visible but are "locked" in place.
|
||||
Then "Course overview" "text" should exist in the "region-main" "region"
|
||||
And I should not see "Add a block"
|
||||
And I should see "This is visible on all pages"
|
||||
And "Move Text on all pages block" "button" should not exist in the "Text on all pages" "block"
|
||||
And "Move Course overview block" "button" should not exist in the "Course overview" "block"
|
||||
And I click on "Actions menu" "icon" in the "Course overview" "block"
|
||||
And I should not see "Delete Course overview block"
|
||||
|
@ -81,7 +81,8 @@ $THEME->layouts = [
|
||||
// My courses page.
|
||||
'mycourses' => array(
|
||||
'file' => 'drawers.php',
|
||||
'regions' => array(),
|
||||
'regions' => ['side-pre'],
|
||||
'defaultregion' => 'side-pre',
|
||||
'options' => array('nonavbar' => true),
|
||||
),
|
||||
// My dashboard page.
|
||||
|
30
theme/boost/tests/behat/mycoursesblocks.feature
Normal file
30
theme/boost/tests/behat/mycoursesblocks.feature
Normal file
@ -0,0 +1,30 @@
|
||||
@javascript @theme_boost
|
||||
Feature: My courses page block layout in Boost theme
|
||||
In order to have a clear and consistent view on the my courses page
|
||||
As a student
|
||||
I need to see the blocks in the expected placement
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student@example.com |
|
||||
And I log in as "admin"
|
||||
And I am on site homepage
|
||||
And I turn editing mode on
|
||||
And I add the "Text" block
|
||||
And I configure the "(new text block)" block
|
||||
And I set the following fields to these values:
|
||||
| Page contexts | Display throughout the entire site |
|
||||
| Text block title | Text on all pages |
|
||||
| Content | This is visible on all pages |
|
||||
| Default region | Right |
|
||||
And I press "Save changes"
|
||||
|
||||
Scenario: Student can see relevant blocks with correct placement on my courses page
|
||||
When I log in as "student1"
|
||||
And I am on the "My courses" page
|
||||
Then "Course overview" "text" should exist in the "region-main" "region"
|
||||
And I should see "This is visible on all pages"
|
||||
And I press "Close block drawer"
|
||||
And "Course overview" "text" should exist in the "region-main" "region"
|
||||
And I should not see "This is visible on all pages"
|
@ -75,7 +75,8 @@ $THEME->layouts = [
|
||||
// My courses page.
|
||||
'mycourses' => array(
|
||||
'file' => 'columns.php',
|
||||
'regions' => array()
|
||||
'regions' => ['side-pre', 'side-post'],
|
||||
'defaultregion' => 'side-pre',
|
||||
),
|
||||
// My dashboard page.
|
||||
'mydashboard' => array(
|
||||
|
27
theme/classic/tests/behat/mycoursesblocks.feature
Normal file
27
theme/classic/tests/behat/mycoursesblocks.feature
Normal file
@ -0,0 +1,27 @@
|
||||
@javascript @theme_classic
|
||||
Feature: My courses page block layout in Classic theme
|
||||
In order to have a clear and consistent view on the my courses page
|
||||
As a student
|
||||
I need to see the blocks in the expected placement
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student@example.com |
|
||||
And I log in as "admin"
|
||||
And I am on site homepage
|
||||
And I turn editing mode on
|
||||
And I add the "Text" block
|
||||
And I configure the "(new text block)" block
|
||||
And I set the following fields to these values:
|
||||
| Page contexts | Display throughout the entire site |
|
||||
| Text block title | Text on all pages |
|
||||
| Content | This is visible on all pages |
|
||||
| Default region | Right |
|
||||
And I press "Save changes"
|
||||
|
||||
Scenario: Student can see relevant blocks with correct placement on my courses page
|
||||
When I log in as "student1"
|
||||
And I am on the "My courses" page
|
||||
Then "Course overview" "text" should exist in the "region-main" "region"
|
||||
And "This is visible on all pages" "text" should exist in the ".columnright" "css_element"
|
Loading…
x
Reference in New Issue
Block a user