MDL-11421 context levels fixed in capability definitions, sorting of caps by name, plug-ins may report used core caps, fixed some risks; merged from MOODLE_19_STABLE

This commit is contained in:
skodak 2008-07-24 21:59:13 +00:00
parent 7f2a7c3cca
commit f432bebff2
22 changed files with 204 additions and 101 deletions

View File

@ -795,6 +795,9 @@ class block_base {
return true;
}
function get_extra_capabilities() {
return array();
}
}
/**

View File

@ -19,7 +19,7 @@
function init() {
$this->title = get_string('feedstitle', 'block_rss_client');
$this->version = 2007101509;
$this->version = 2007101511;
$this->cron = 300; /// Set min time between cron executions to 300 secs (5 mins)
}

View File

@ -36,7 +36,7 @@ $block_rss_client_capabilities = array(
'block/rss_client:createprivatefeeds' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_BLOCK,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
@ -49,7 +49,7 @@ $block_rss_client_capabilities = array(
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_BLOCK,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
@ -59,7 +59,7 @@ $block_rss_client_capabilities = array(
'block/rss_client:manageownfeeds' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_BLOCK,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
@ -72,7 +72,7 @@ $block_rss_client_capabilities = array(
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_BLOCK,
'legacy' => array(
'admin' => CAP_ALLOW
)

View File

@ -14,7 +14,7 @@ $enrol_authorize_capabilities = array(
'enrol/authorize:uploadcsv' => array(
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_USER,
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'admin' => CAP_ALLOW
)

View File

@ -1,6 +1,6 @@
<?php // $Id$
$plugin->version = 2008020500;
$plugin->version = 2008020501;
$plugin->requires = 2007101507;
?>

View File

@ -3311,106 +3311,94 @@ function print_context_name($context, $withprefix = true, $short = false) {
* `component` varchar(100) NOT NULL,
*/
function fetch_context_capabilities($context) {
global $DB;
global $DB, $CFG;
$sort = 'ORDER BY contextlevel,component,id'; // To group them sensibly for display
$params = null;
$sort = 'ORDER BY contextlevel,component,name'; // To group them sensibly for display
$params = array();
switch ($context->contextlevel) {
case CONTEXT_SYSTEM: // all
$sql = "SELECT * FROM {capabilities}";
$SQL = "SELECT *
FROM {capabilities}";
break;
case CONTEXT_USER:
$sql = "SELECT *
$extracaps = array('moodle/grade:viewall');
list($extra, $params) = $DB->get_in_or_equal($extracaps, SQL_PARAMS_NAMED, 'cap0');
$SQL = "SELECT *
FROM {capabilities}
WHERE contextlevel = ".CONTEXT_USER;
WHERE contextlevel = ".CONTEXT_USER."
OR name $extra";
break;
case CONTEXT_COURSECAT: // all
$sql = "SELECT * FROM {capabilities}";
case CONTEXT_COURSECAT: // course category context and bellow
$SQL = "SELECT *
FROM {capabilities}
WHERE contextlevel IN (".CONTEXT_COURSECAT.",".CONTEXT_COURSE.",".CONTEXT_MODULE.",".CONTEXT_BLOCK.")";
break;
case CONTEXT_COURSE: // all
$sql = "SELECT * FROM {capabilities}";
break;
case CONTEXT_GROUP: // group caps
case CONTEXT_COURSE: // course context and bellow
$SQL = "SELECT *
FROM {capabilities}
WHERE contextlevel IN (".CONTEXT_COURSE.",".CONTEXT_MODULE.",".CONTEXT_BLOCK.")";
break;
case CONTEXT_MODULE: // mod caps
$cm = $DB->get_record('course_modules', array('id'=>$context->instanceid));
$cm = $DB->get_record('course_modules', array('id'=>$context->instanceid));
$module = $DB->get_record('modules', array('id'=>$cm->module));
$sql = "SELECT *
$extra = "";
$modfile = "$CFG->dirroot/mod/$module->name/lib.php";
if (file_exists($modfile)) {
include_once($modfile);
$modfunction = $module->name.'_get_extra_capabilities';
if (function_exists($modfunction)) {
if ($extracaps = $modfunction()) {
list($extra, $params) = $DB->get_in_or_equal($extracaps, SQL_PARAMS_NAMED, 'cap0');
$extra = "OR name $extra";
}
}
}
$SQL = "SELECT *
FROM {capabilities}
WHERE contextlevel = ".CONTEXT_MODULE." AND component = ?";
$params = array("mod/$module->name");
WHERE contextlevel = ".CONTEXT_MODULE."
AND component = :component
$extra";
$params['component'] = "mod/$module->name";
break;
case CONTEXT_BLOCK: // block caps
$cb = $DB->get_record('block_instance', array('id'=>$context->instanceid));
$cb = $DB->get_record('block_instance', array('id'=>$context->instanceid));
$block = $DB->get_record('block', array('id'=>$cb->blockid));
$sql = "SELECT *
$extra = "";
if ($blockinstance = block_instance($block->name)) {
if ($extracaps = $blockinstance->get_extra_capabilities()) {
list($extra, $params) = $DB->get_in_or_equal($extracaps, SQL_PARAMS_NAMED, 'cap0');
$extra = "OR name $extra";
}
}
$SQL = "SELECT *
FROM {capabilities}
WHERE (contextlevel = ".CONTEXT_BLOCK." AND component = 'moodle') OR (component = ?)";
$params = array("block/$block->name");
WHERE (contextlevel = ".CONTEXT_BLOCK."
AND component = :component)
$extra";
$params['component'] = "block/$block->name";
break;
default:
return false;
}
$records = $DB->get_records_sql($sql.' '.$sort, $params);
/// the rest of code is a bit hacky, think twice before modifying it :-(
// special sorting of core system capabiltites and enrollments
if (in_array($context->contextlevel, array(CONTEXT_SYSTEM, CONTEXT_COURSECAT, CONTEXT_COURSE))) {
$first = array();
foreach ($records as $key=>$record) {
if (preg_match('|^moodle/|', $record->name) and $record->contextlevel == CONTEXT_SYSTEM) {
$first[$key] = $record;
unset($records[$key]);
} else if (count($first)){
break;
}
}
if (count($first)) {
$records = $first + $records; // merge the two arrays keeping the keys
}
} else {
$contextindependentcaps = fetch_context_independent_capabilities();
$records = array_merge($contextindependentcaps, $records);
if (!$records = $DB->get_records_sql($SQL.' '.$sort, $params)) {
$records = array();
}
return $records;
}
/**
* Gets the context-independent capabilities that should be overrridable in
* any context.
* @return array of capability records from the capabilities table.
*/
function fetch_context_independent_capabilities() {
global $DB;
//only CONTEXT_SYSTEM capabilities here or it will break the hack in fetch_context_capabilities()
$contextindependentcaps = array(
'moodle/site:accessallgroups'
);
$records = array();
foreach ($contextindependentcaps as $capname) {
$record = $DB->get_record('capabilities', array('name'=>$capname));
array_push($records, $record);
}
return $records;
}

View File

@ -35,7 +35,7 @@ $moodle_capabilities = array(
'moodle/site:doanything' => array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG,
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG | RISK_DATALOSS,
'captype' => 'admin',
'contextlevel' => CONTEXT_SYSTEM
@ -91,7 +91,7 @@ $moodle_capabilities = array(
'moodle/legacy:admin' => array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG,
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG | RISK_DATALOSS,
'captype' => 'legacy',
'contextlevel' => CONTEXT_SYSTEM
@ -100,7 +100,7 @@ $moodle_capabilities = array(
'moodle/site:config' => array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG,
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG | RISK_DATALOSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
@ -149,7 +149,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
@ -161,7 +161,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
@ -173,7 +173,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
@ -185,7 +185,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_BLOCK,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
@ -195,7 +195,7 @@ $moodle_capabilities = array(
'moodle/site:accessallgroups' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
@ -206,7 +206,7 @@ $moodle_capabilities = array(
'moodle/site:viewfullnames' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
@ -219,7 +219,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
@ -232,7 +232,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
@ -309,7 +309,7 @@ $moodle_capabilities = array(
'moodle/user:viewdetails' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'guest' => CAP_ALLOW,
'student' => CAP_ALLOW,
@ -324,7 +324,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
@ -348,7 +348,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
@ -360,7 +360,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'admin' => CAP_ALLOW
)
@ -371,7 +371,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW
)
@ -391,7 +391,7 @@ $moodle_capabilities = array(
'moodle/role:unassignself' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'student' => (empty($CFG->allowunenrol)) ? CAP_INHERIT : CAP_ALLOW,
'teacher' => CAP_ALLOW,
@ -404,7 +404,7 @@ $moodle_capabilities = array(
'moodle/role:viewhiddenassigns' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
@ -417,7 +417,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_XSS | RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
@ -685,7 +685,7 @@ $moodle_capabilities = array(
'moodle/blog:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'guest' => CAP_ALLOW,
'user' => CAP_ALLOW,
@ -713,7 +713,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
@ -726,7 +726,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'user' => CAP_ALLOW,
'admin' => CAP_ALLOW
@ -738,7 +738,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
@ -751,7 +751,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
@ -1157,7 +1157,7 @@ $moodle_capabilities = array(
'moodle/notes:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
@ -1169,7 +1169,7 @@ $moodle_capabilities = array(
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,

View File

@ -3089,4 +3089,11 @@ function assignment_reset_course_form_defaults($course) {
return array('reset_assignment_submissions'=>1);
}
/**
* Returns all other caps used in module
*/
function assignment_get_extra_capabilities() {
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
}
?>

View File

@ -812,4 +812,11 @@ function chat_reset_userdata($data) {
return $status;
}
/**
* Returns all other caps used in module
*/
function chat_get_extra_capabilities() {
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
}
?>

View File

@ -740,6 +740,13 @@ function choice_get_response_data($choice, $cm, $groupmode) {
}
return $allresponses;
}
/**
* Returns all other caps used in module
*/
function chice_get_extra_capabilities() {
return array('moodle/site:accessallgroups');
}
?>

View File

@ -2262,4 +2262,12 @@ function data_reset_userdata($data) {
return $status;
}
/**
* Returns all other caps used in module
*/
function data_get_extra_capabilities() {
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
}
?>

View File

@ -6864,4 +6864,11 @@ function forum_get_open_modes() {
'0' => get_string('openmode0', 'forum') );
}
/**
* Returns all other caps used in module
*/
function forum_get_extra_capabilities() {
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames', 'moodle/site:trustcontent');
}
?>

View File

@ -2299,4 +2299,11 @@ function glossary_reset_userdata($data) {
return $status;
}
/**
* Returns all other caps used in module
*/
function glossary_get_extra_capabilities() {
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames', 'moodle/site:trustcontent');
}
?>

View File

@ -2527,4 +2527,11 @@ END_OF_SCRIPT;
}
}
/**
* Returns all other caps used in module
*/
function hotpot_get_extra_capabilities() {
return array('moodle/site:accessallgroups');
}
?>

View File

@ -128,4 +128,11 @@ function label_reset_userdata($data) {
return array();
}
/**
* Returns all other caps used in module
*/
function lable_get_extra_capabilities() {
return array('moodle/site:accessallgroups');
}
?>

View File

@ -696,4 +696,11 @@ function lesson_reset_userdata($data) {
return $status;
}
/**
* Returns all other caps used in module
*/
function lesson_get_extra_capabilities() {
return array('moodle/site:accessallgroups');
}
?>

View File

@ -1209,4 +1209,24 @@ function quiz_num_attempt_summary($quiz, $cm, $returnzero = false, $currentgroup
}
return '';
}
/**
* Returns all other caps used in module
*/
function quiz_get_extra_capabilities() {
return array(
'moodle/site:accessallgroups',
'moodle/question:add',
'moodle/question:editmine',
'moodle/question:editall',
'moodle/question:viewmine',
'moodle/question:viewall',
'moodle/question:usemine',
'moodle/question:useall',
'moodle/question:movemine',
'moodle/question:moveall',
'moodle/question:managecategory',
);
}
?>

View File

@ -673,4 +673,12 @@ function resource_delete_warning($course, $files) {
function resource_reset_userdata($data) {
return array();
}
/**
* Returns all other caps used in module
*/
function resource_get_extra_capabilities() {
return array('moodle/site:accessallgroups');
}
?>

View File

@ -626,4 +626,11 @@ function scorm_reset_userdata($data) {
return $status;
}
/**
* Returns all other caps used in module
*/
function scorm_get_extra_capabilities() {
return array('moodle/site:accessallgroups');
}
?>

View File

@ -581,4 +581,11 @@ function survey_reset_userdata($data) {
return $status;
}
/**
* Returns all other caps used in module
*/
function survey_get_extra_capabilities() {
return array('moodle/site:accessallgroups');
}
?>

View File

@ -1757,5 +1757,11 @@ function wiki_release_lock($wikiid,$pagename) {
}
}
/**
* Returns all other caps used in module
*/
function wiki_get_extra_capabilities() {
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
}
?>

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 = 2008072402; // YYYYMMDD = date of the last version bump
$version = 2008072403; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20080724)'; // Human-friendly version name