From c35cf9bfcdd5a1eb7d852d4f4f6049028e3debbb Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 11 Jan 2016 16:44:15 +0800 Subject: [PATCH] MDL-51702 blocks: Allow permission overrides in dashboard --- .../configure_block_throughout_site.feature | 4 +- lib/blocklib.php | 56 +++++++++---------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/blocks/tests/behat/configure_block_throughout_site.feature b/blocks/tests/behat/configure_block_throughout_site.feature index 95e17058b7c..bf2e8b03df0 100644 --- a/blocks/tests/behat/configure_block_throughout_site.feature +++ b/blocks/tests/behat/configure_block_throughout_site.feature @@ -48,11 +48,11 @@ Feature: Add and configure blocks throughout the site # The first block matching the pattern should be top-left block And I should see "Comments" in the "//*[@id='region-pre' or @id='block-region-side-pre']/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' block ')]" "xpath_element" - Scenario: Blocks on the dashboard page cannot have roles assigned to them + Scenario: Blocks on the dashboard page can have roles assigned to them Given I log in as "manager1" And I click on "Dashboard" "link" in the "Navigation" "block" When I press "Customise this page" - Then I should not see "Assign roles in Navigation block" + Then I should see "Assign roles in Navigation block" Scenario: Blocks on courses can have roles assigned to them Given I log in as "teacher1" diff --git a/lib/blocklib.php b/lib/blocklib.php index b045eb2e481..595cf3b780a 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -1093,38 +1093,36 @@ class block_manager { } // Display either "Assign roles" or "Permissions" or "Change permissions" icon (whichever first is available). - if ($this->page->pagetype != 'my-index') { - $rolesurl = null; + $rolesurl = null; - if (get_assignable_roles($block->context, ROLENAME_SHORT)) { - $rolesurl = new moodle_url('/admin/roles/assign.php', array('contextid' => $block->context->id)); - $str = new lang_string('assignrolesinblock', 'block', $blocktitle); - $icon = 'i/assignroles'; - } else if (has_capability('moodle/role:review', $block->context) or get_overridable_roles($block->context)) { - $rolesurl = new moodle_url('/admin/roles/permissions.php', array('contextid' => $block->context->id)); - $str = get_string('permissions', 'role'); - $icon = 'i/permissions'; - } else if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $block->context)) { - $rolesurl = new moodle_url('/admin/roles/check.php', array('contextid' => $block->context->id)); - $str = get_string('checkpermissions', 'role'); - $icon = 'i/checkpermissions'; - } + if (get_assignable_roles($block->context, ROLENAME_SHORT)) { + $rolesurl = new moodle_url('/admin/roles/assign.php', array('contextid' => $block->context->id)); + $str = new lang_string('assignrolesinblock', 'block', $blocktitle); + $icon = 'i/assignroles'; + } else if (has_capability('moodle/role:review', $block->context) or get_overridable_roles($block->context)) { + $rolesurl = new moodle_url('/admin/roles/permissions.php', array('contextid' => $block->context->id)); + $str = get_string('permissions', 'role'); + $icon = 'i/permissions'; + } else if (has_any_capability(array('moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $block->context)) { + $rolesurl = new moodle_url('/admin/roles/check.php', array('contextid' => $block->context->id)); + $str = get_string('checkpermissions', 'role'); + $icon = 'i/checkpermissions'; + } - if ($rolesurl) { - //TODO: please note it is sloppy to pass urls through page parameters!! - // it is shortened because some web servers (e.g. IIS by default) give - // a 'security' error if you try to pass a full URL as a GET parameter in another URL. - $return = $this->page->url->out(false); - $return = str_replace($CFG->wwwroot . '/', '', $return); - $rolesurl->param('returnurl', $return); + if ($rolesurl) { + // TODO: please note it is sloppy to pass urls through page parameters!! + // it is shortened because some web servers (e.g. IIS by default) give + // a 'security' error if you try to pass a full URL as a GET parameter in another URL. + $return = $this->page->url->out(false); + $return = str_replace($CFG->wwwroot . '/', '', $return); + $rolesurl->param('returnurl', $return); - $controls[] = new action_menu_link_secondary( - $rolesurl, - new pix_icon($icon, $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), - $str, - array('class' => 'editing_roles') - ); - } + $controls[] = new action_menu_link_secondary( + $rolesurl, + new pix_icon($icon, $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), + $str, + array('class' => 'editing_roles') + ); } if ($this->user_can_delete_block($block)) {