]> git.mjollnir.org Git - moodle.git/commitdiff
capability riskbitmasks and user trustbitmask patch #1 see MDL-6412
authorskodak <skodak>
Thu, 31 Aug 2006 08:36:36 +0000 (08:36 +0000)
committerskodak <skodak>
Thu, 31 Aug 2006 08:36:36 +0000 (08:36 +0000)
lib/accesslib.php
lib/db/install.xml
lib/db/mysql.php
lib/db/mysql.sql
lib/db/postgres7.php
lib/db/postgres7.sql
version.php

index 954a4c596778bd025922db6513e77c5def7ae756..e9226b3c572bde9943cfe2d699d11cc435da3bb4 100755 (executable)
@@ -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
index 86feaae73bab99b54a48779655e8caac4b484327..cd40c18ee74c996ab1cd165469ec27b40e70b75d 100644 (file)
         <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"/>
         <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"/>
index dd47603e107e304484036d10e52c10d19de77da3..cef6b3832090230aeed08da789dadfd0311fe784 100644 (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;
 }
 
index 2c584f1f56e6ee1d80a9c0568205df4740a9c8e2..8d9a8b449c1c9e11636563fd91f1cb836c54c174 100644 (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';
index 9df86a3c6afd07d9b3b4522b0a15a05c3ae7f534..aefb67cd6278cd2a2a5732c5e394a81e4a943a25 100644 (file)
@@ -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;
 }
index 0a4a345c66a710c5e1d70ceb1c730a7783e544a0..deabce829aa35e50c9ee6ef560602b3d4b022f38 100644 (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);
 
index b914e154893ab50a454a0db9dca1d57b267dcd0e..8aade5b35540656d5b4f2d3d51a45d4da3021423 100644 (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