summaryrefslogtreecommitdiff
path: root/modules/system
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-05-07 19:34:24 +0000
committerDries Buytaert <dries@buytaert.net>2008-05-07 19:34:24 +0000
commitb9f1018ea4fe429656de0fad91fcde51d9507e50 (patch)
tree20648c37c14f84c119f13c49ce75c97f02c07336 /modules/system
parent48e293a6b3d647d79b7b3ce58ab467f9c3fd6de7 (diff)
downloadbrdo-b9f1018ea4fe429656de0fad91fcde51d9507e50.tar.gz
brdo-b9f1018ea4fe429656de0fad91fcde51d9507e50.tar.bz2
- Patch #73874 by pwolanin: normalize the permissions table and wrote simpletests for the (new) permission handling. At last.
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/system.install56
1 files changed, 54 insertions, 2 deletions
diff --git a/modules/system/system.install b/modules/system/system.install
index 9207e6e2d..89c2afde2 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -366,11 +366,18 @@ function system_install() {
// This sets uid 1 (superuser). We skip uid 2 but that's not a big problem.
db_query("UPDATE {users} SET uid = 1 WHERE name = '%s'", 'placeholder-for-uid-1');
+ // Built-in roles.
db_query("INSERT INTO {role} (name) VALUES ('%s')", 'anonymous user');
db_query("INSERT INTO {role} (name) VALUES ('%s')", 'authenticated user');
- db_query("INSERT INTO {permission} (rid, perm, tid) VALUES (%d, '%s', %d)", 1, 'access content', 0);
- db_query("INSERT INTO {permission} (rid, perm, tid) VALUES (%d, '%s', %d)", 2, 'access comments, access content, post comments, post comments without approval', 0);
+ // Anonymous role permissions.
+ db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 1, 'access content');
+
+ // Authenticated role permissions.
+ db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'access comments');
+ db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'access content');
+ db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'post comments');
+ db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'post comments without approval');
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'theme_default', 's:7:"garland";');
db_query("UPDATE {system} SET status = %d WHERE type = '%s' AND name = '%s'", 1, 'theme', 'garland');
@@ -2945,6 +2952,51 @@ function system_update_7006() {
}
/**
+ * Convert to new method of storing permissions.
+ *
+ * This update is in system.install rather than user.install so that
+ * all modules can use the updated permission scheme during their updates.
+ */
+function system_update_7007() {
+ $ret = array();
+
+ $schema['role_permission'] = array(
+ 'fields' => array(
+ 'rid' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ ),
+ 'permission' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
+ ),
+ 'primary key' => array('rid', 'permission'),
+ 'indexes' => array(
+ 'permission' => array('permission'),
+ ),
+ );
+
+ db_create_table($ret, 'role_permission', $schema['role_permission']);
+
+ // Copy the permissions from the old {permission} table to the new {role_permission} table.
+ $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid ASC");
+ while ($role = db_fetch_object($result)) {
+ foreach (explode(', ', $role->perm) as $perm) {
+ db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", $role->rid, $perm);
+ }
+ $ret[] = array('success' => TRUE, 'query' => "Inserted into {role_permission} the permissions for role ID " . $role->rid);
+ }
+ db_drop_table($ret, 'permission');
+
+ return $ret;
+}
+
+
+/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.
*/