MDL-15768 - add capability check in mod/resource for portfolio export

This commit is contained in:
mjollnir_
2008-08-11 14:53:00 +00:00
parent 7cbe6eed1f
commit 494e47e497
4 changed files with 56 additions and 4 deletions
+1
View 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';
+49
View File
@@ -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,
)
),
);
?>
+4 -2
View 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;
+2 -2
View 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;
?>