From 7e874772a359e91a8fc7c9b0f05378188979f203 Mon Sep 17 00:00:00 2001 From: poltawski Date: Mon, 13 Aug 2007 10:08:15 +0000 Subject: [PATCH] MDL-10573 - Added a capability for viewing blocks, this allows role-based control of block display. Changed context capability check so that CONTEXT_BLOCK capabilities can also come from the moodle core capability definitions --- blocks/moodleblock.class.php | 8 ++++++++ lang/en_utf8/role.php | 1 + lib/accesslib.php | 8 ++++++-- lib/db/access.php | 9 +++++++++ version.php | 2 +- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index a3778c5ca4..730348b7ba 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -195,10 +195,18 @@ class block_base { /** * Returns true or false, depending on whether this block has any content to display + * and whether the user has permission to view the block * * @return boolean */ function is_empty() { + + $context = get_context_instance(CONTEXT_BLOCK, $this->instance->id); + + if ( !has_capability('moodle/block:view', $context) ) { + return true; + } + $this->get_content(); return(empty($this->content->text) && empty($this->content->footer)); } diff --git a/lang/en_utf8/role.php b/lang/en_utf8/role.php index 0d5ed0d614..7ca0f46a7f 100644 --- a/lang/en_utf8/role.php +++ b/lang/en_utf8/role.php @@ -13,6 +13,7 @@ $string['blog:manageentries'] = 'Edit and manage entries'; $string['blog:manageofficialtags'] = 'Manage official tags'; $string['blog:managepersonaltags'] = 'Manage personal tags'; $string['blog:view'] = 'View blog entries'; +$string['block:view'] = 'View block'; $string['calendar:manageentries'] = 'Manage any calendar entries'; $string['calendar:manageownentries'] = 'Manage own calendar entries'; $string['capabilities'] = 'Capabilities'; diff --git a/lib/accesslib.php b/lib/accesslib.php index 0dab4a7aee..dded2a34d9 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2917,7 +2917,7 @@ function fetch_context_capabilities($context) { $block = get_record('block', 'id', $cb->blockid); $SQL = "select * from {$CFG->prefix}capabilities where contextlevel = ".CONTEXT_BLOCK." - and component = 'block/$block->name'"; + and ( component = 'block/$block->name' or component = 'moodle')"; break; default: @@ -3396,7 +3396,11 @@ function get_component_string($component, $contextlevel) { break; case CONTEXT_BLOCK: - $string = get_string('blockname', 'block_'.basename($component)); + if( $component == 'moodle' ){ + $string = get_string('block'); + }else{ + $string = get_string('blockname', 'block_'.basename($component)); + } break; default: diff --git a/lib/db/access.php b/lib/db/access.php index ef0290726f..37e26358dc 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -1145,6 +1145,15 @@ $moodle_capabilities = array( 'editingteacher' => CAP_ALLOW, 'admin' => CAP_ALLOW ) + ), + + 'moodle/block:view' => array( + 'captype' => 'read', + 'contextlevel' => CONTEXT_BLOCK, + 'legacy' => array( + 'guest' => CAP_ALLOW, + 'user' => CAP_ALLOW + ) ) ); diff --git a/version.php b/version.php index cdbae7e09b..0b6ac435d6 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2007081001; // YYYYMMDD = date + $version = 2007081301; // YYYYMMDD = date // XY = increments within a single day $release = '1.9 dev'; // Human-friendly version name -- 2.39.5