]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10573 - Added a capability for viewing blocks, this allows role-based control...
authorpoltawski <poltawski>
Mon, 13 Aug 2007 10:08:15 +0000 (10:08 +0000)
committerpoltawski <poltawski>
Mon, 13 Aug 2007 10:08:15 +0000 (10:08 +0000)
display.

Changed context capability check so that CONTEXT_BLOCK capabilities can also come from the
moodle core capability definitions

blocks/moodleblock.class.php
lang/en_utf8/role.php
lib/accesslib.php
lib/db/access.php
version.php

index a3778c5ca4c6312301735224b6798f1e36c36083..730348b7bab400a577ed4ae267efa5d1a5226afc 100644 (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));
     }
index 0d5ed0d6148c306526c294be69abe470e4fc0844..7ca0f46a7fc906282fa5ce29a40f83a1593321e0 100644 (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';
index 0dab4a7aee5ea3d3252acd41fabba76c5750a531..dded2a34d932307395efcddffb8a401dc4d75485 100755 (executable)
@@ -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:
index ef0290726fe742271a9d3d7d82b9923231a90593..37e26358dc202d2f29524a2d306ea8b2eb523ffa 100644 (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
+        )
     )
 );
 
index cdbae7e09bf8be01d034e1ab2abccbdf61887414..0b6ac435d6c5e1d6ee8a03c145017b94d7cc5f91 100644 (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