From 494e47e497da878cf864face1f550b1e210b33dd Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Mon, 11 Aug 2008 14:53:00 +0000 Subject: [PATCH] MDL-15768 - add capability check in mod/resource for portfolio export --- lang/en_utf8/resource.php | 1 + mod/resource/db/access.php | 49 ++++++++++++++++++++++++++++++++++++++ mod/resource/lib.php | 6 +++-- mod/resource/version.php | 4 ++-- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 mod/resource/db/access.php diff --git a/lang/en_utf8/resource.php b/lang/en_utf8/resource.php index e8342cfb37..a9ead0d125 100644 --- a/lang/en_utf8/resource.php +++ b/lang/en_utf8/resource.php @@ -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 index 0000000000..a68a38249b --- /dev/null +++ b/mod/resource/db/access.php @@ -0,0 +1,49 @@ +: +// +// component_name should be the same as the directory name of the mod or block. +// +// Core moodle capabilities are defined thus: +// moodle/: +// +// Examples: mod/forum:viewpost +// block/recent_activity:view +// moodle/site:deleteuser +// +// The variable name for the capability definitions array follows the format +// $__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, + ) + ), + +); + +?> diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 6d949cf87f..8bb207cade 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -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; diff --git a/mod/resource/version.php b/mod/resource/version.php index 51a67c370c..5d5ddbc697 100644 --- a/mod/resource/version.php +++ b/mod/resource/version.php @@ -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; ?> -- 2.39.5