capability riskbitmasks and user trustbitmask patch #1 see MDL-6412

This commit is contained in:
skodak 2006-08-31 08:36:36 +00:00
parent 2b3447c38a
commit be4486da83
7 changed files with 34 additions and 9 deletions

View file

@ -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;

View file

@ -583,7 +583,8 @@
<FIELD NAME="ajax" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="htmleditor" NEXT="autosubscribe"/>
<FIELD NAME="autosubscribe" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="ajax" NEXT="trackforums"/>
<FIELD NAME="trackforums" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="autosubscribe" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="trackforums"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="trackforums" NEXT="trustbitmask"/>
<FIELD NAME="trustbitmask" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Default comment for the field, please edit me" PREVIOUS="timemodified"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for user"/>
@ -915,7 +916,8 @@
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="captype"/>
<FIELD NAME="captype" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="contextlevel"/>
<FIELD NAME="contextlevel" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="captype" NEXT="component"/>
<FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="contextlevel"/>
<FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="contextlevel" NEXT="riskbitmask"/>
<FIELD NAME="riskbitmask" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Default comment for the field, please edit me" PREVIOUS="component"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for capabilities" NEXT="name"/>

View file

@ -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;
}

View file

@ -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';

View file

@ -1760,6 +1760,10 @@ function main_upgrade($oldversion=0) {
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;
}

View file

@ -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);

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 = 2006083001; // YYYYMMDD = date
$version = 2006083003; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.7 dev'; // Human-friendly version name