]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15768 - add capability check in mod/resource for portfolio export
authormjollnir_ <mjollnir_>
Mon, 11 Aug 2008 14:53:00 +0000 (14:53 +0000)
committermjollnir_ <mjollnir_>
Mon, 11 Aug 2008 14:53:00 +0000 (14:53 +0000)
lang/en_utf8/resource.php
mod/resource/db/access.php [new file with mode: 0644]
mod/resource/lib.php
mod/resource/version.php

index e8342cfb371f6124a188e1b326a1dd7a7a344677..a9ead0d1253a4c77bc9aec6f649eb20a94da89d5 100644 (file)
@@ -104,6 +104,7 @@ $string['previous'] = 'Previous';
 $string['redeploy'] = 'Deploy again';
 $string['repository'] = 'IMS repository';
 $string['resource:view'] = 'View resource';
+$string['resource:exportresource'] = 'Export resource';
 $string['resourcedefaulturl'] = 'Default URL';
 $string['resourcetype'] = 'Type of resource';
 $string['resourcetype1'] = 'Reference';
diff --git a/mod/resource/db/access.php b/mod/resource/db/access.php
new file mode 100644 (file)
index 0000000..a68a382
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+//
+// Capability definitions for the resource module.
+//
+// The capabilities are loaded into the database table when the module is
+// installed or updated. Whenever the capability definitions are updated,
+// the module version number should be bumped up.
+//
+// The system has four possible values for a capability:
+// CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT, and inherit (not set).
+//
+//
+// CAPABILITY NAMING CONVENTION
+//
+// It is important that capability names are unique. The naming convention
+// for capabilities that are specific to modules and blocks is as follows:
+//   [mod/block]/<component_name>:<capabilityname>
+//
+// component_name should be the same as the directory name of the mod or block.
+//
+// Core moodle capabilities are defined thus:
+//    moodle/<capabilityclass>:<capabilityname>
+//
+// Examples: mod/forum:viewpost
+//           block/recent_activity:view
+//           moodle/site:deleteuser
+//
+// The variable name for the capability definitions array follows the format
+//   $<componenttype>_<component_name>_capabilities
+//
+// For the core capabilities, the variable is $moodle_capabilities.
+
+
+$mod_resource_capabilities = array(
+
+    'mod/resource:exportresource' => array(
+
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_MODULE,
+        'legacy' => array(
+            'admin' => CAP_ALLOW,
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+        )
+    ),
+
+);
+
+?>
index 6d949cf87f71171e5092a5d05f96aaac6da885be..8bb207cade2fd36599e93e3660a0c1c8c6052cef 100644 (file)
@@ -743,11 +743,13 @@ class resource_portfolio_caller extends portfolio_module_caller_base {
     }
 
     public function check_permissions() {
-        return true;
+        return has_capability('mod/resource:exportresource', get_context_instance(CONTEXT_MODULE, $this->cm->id));
     }
 
     public static function add_button($resource, $fullform=true, $return=false) {
-        // @todo penny can we put the capability check in here?
+        if (!has_capability('mod/resource:exportresource', get_context_instance(CONTEXT_MODULE, $resource->cm->id))) {
+            return;
+        }
         if (!is_callable(array($resource, 'portfolio_prepare_package')) || !is_callable(array($resource, 'portfolio_get_sha1'))) {
             debugging(get_string('portfolionotimplemented', 'resource'));
             return false;
index 51a67c370cc3cbb22b3f61edbc50a5c57d2df3bb..5d5ddbc697aa08bbbaec398d4b8e508947835556 100644 (file)
@@ -5,8 +5,8 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2007101509;
-$module->requires = 2007101509;  // Requires this Moodle version
+$module->version  = 2008081100;
+$module->requires = 2008080701;  // Requires this Moodle version
 $module->cron     = 0;
 
 ?>