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
This commit is contained in:
poltawski 2007-08-13 10:08:15 +00:00
parent 94783496f1
commit 7e874772a3
5 changed files with 25 additions and 3 deletions

View File

@ -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));
}

View File

@ -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';

View File

@ -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:

View File

@ -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
)
)
);

View File

@ -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