From be4486da8320c69b1b2ad54c87383efe89bd25d2 Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 31 Aug 2006 08:36:36 +0000 Subject: [PATCH] capability riskbitmasks and user trustbitmask patch #1 see MDL-6412 --- lib/accesslib.php | 25 +++++++++++++++++++------ lib/db/install.xml | 6 ++++-- lib/db/mysql.php | 4 ++++ lib/db/mysql.sql | 1 + lib/db/postgres7.php | 4 ++++ lib/db/postgres7.sql | 1 + version.php | 2 +- 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index 954a4c5967..e9226b3c57 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1237,17 +1237,29 @@ function get_cached_capabilities($component='moodle') { function update_capabilities($component='moodle') { $storedcaps = array(); - $filecaps = array(); - + + $filecaps = load_capability_def($component); $cachedcaps = get_cached_capabilities($component); if ($cachedcaps) { foreach ($cachedcaps as $cachedcap) { array_push($storedcaps, $cachedcap->name); + // update risk bitmasks in existing capabilitites if needed + if (array_key_exists($cachedcap->name, $filecaps)) { + if (!array_key_exists('riskbitmask', $filecaps[$cachedcap->name])) { + $filecaps[$cachedcap->name]['riskbitmask'] = 0; // no risk by default + } + if ($cachedcap->riskbitmask != $filecaps[$cachedcap->name]['riskbitmask']) { + $updatecap = new object; + $updatecap->id = $cachedcap->id; + $updatecap->riskbitmask = $filecaps[$cachedcap->name]['riskbitmask']; + if (!update_record('capabilities', $updatecap)) { + return false; + } + } + } } } - - $filecaps = load_capability_def($component); - + // Are there new capabilities in the file definition? $newcaps = array(); @@ -1264,6 +1276,7 @@ function update_capabilities($component='moodle') { $capability->captype = $capdef['captype']; $capability->contextlevel = $capdef['contextlevel']; $capability->component = $component; + $capability->riskbitmask = $capdef['riskbitmask']; if (!insert_record('capabilities', $capability, false, 'id')) { return false; @@ -1905,4 +1918,4 @@ function get_users_by_capability($context, $capability, $fields='distinct u.*', return get_records_sql($select.$from.$where); } -?> +?> \ No newline at end of file diff --git a/lib/db/install.xml b/lib/db/install.xml index 86feaae73b..cd40c18ee7 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -583,7 +583,8 @@ - + + @@ -915,7 +916,8 @@ - + + diff --git a/lib/db/mysql.php b/lib/db/mysql.php index dd47603e10..cef6b38320 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -2165,6 +2165,10 @@ function main_upgrade($oldversion=0) { table_column('sessions2', 'sessdata', 'sessdata', 'LONGTEXT', '', '', '', '', ''); } + if ($oldversion < 2006083002) { + table_column('capabilities', '', 'riskbitmask', 'INTEGER', '10', 'unsigned', '0', 'not null', ''); + } + return $result; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 2c584f1f56..8d9a8b449c 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -985,6 +985,7 @@ CREATE TABLE prefix_capabilities ( `captype` varchar(50) NOT NULL default '', `contextlevel` int(10) unsigned NOT NULL default '0', `component` varchar(100) NOT NULL default '', + `riskbitmask` int(10) unsigned NOT NULL default '0', UNIQUE KEY `name` (`name`), PRIMARY KEY (`id`) ) TYPE=MYISAM COMMENT ='this defines all capabilities'; diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 9df86a3c6a..aefb67cd62 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -1759,6 +1759,10 @@ function main_upgrade($oldversion=0) { execute_sql(" CREATE INDEX {$CFG->prefix}sess_exp2_ix ON {$CFG->prefix}sessions2 (expireref);", true); } + + if ($oldversion < 2006083002) { + table_column('capabilities', '', 'riskbitmask', 'INTEGER', '10', 'unsigned', '0', 'not null', ''); + } return $result; } diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index 0a4a345c66..deabce829a 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -750,6 +750,7 @@ CREATE TABLE prefix_capabilities ( captype varchar(50) NOT NULL default '', contextlevel integer NOT NULL default 0, component varchar(100) NOT NULL default '' + riskbitmask integer NOT NULL default 0, ); CREATE UNIQUE INDEX prefix_capabilities_name_idx ON prefix_capabilities (name); diff --git a/version.php b/version.php index b914e15489..8aade5b355 100644 --- a/version.php +++ b/version.php @@ -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 = 2006083001; // YYYYMMDD = date + $version = 2006083003; // YYYYMMDD = date // XY = increments within a single day $release = '1.7 dev'; // Human-friendly version name -- 2.39.5