diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 9a7d3f3bb7f55dc3e1e4ffb41be69b6123066ca5..de09110133da5dfb925849be4a73b6e2b5471a95 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -2,4 +2,5 @@ CHANGELOG for ACL for Drupal 6 ACL HEAD: Copied from 5.x-1.5 + Ported to D6 diff --git a/acl.info b/acl.info index 728e0a569817fb84b9e6fb375505993f6e121148..2320e1e223faefe14ed1a4207e02f2e0f181b0cb 100644 --- a/acl.info +++ b/acl.info @@ -1,3 +1,5 @@ name = ACL description = Access control list API. Has no features on its own. -package = Access control \ No newline at end of file +package = Access control +core = 6.x + diff --git a/acl.install b/acl.install index e241a0af9ecca9c3902884999f70fd392aa73cae..a0e73bb738b7c96e20442a6cd9ff970c99c109d8 100644 --- a/acl.install +++ b/acl.install @@ -1,93 +1,97 @@ t('The base Access Control Lists table.'), + 'fields' => array( + 'acl_id' => array( + 'description' => t('Primary key: unique ACL ID.'), + 'type' => 'serial', + 'not null' => TRUE), + 'module' => array( + 'description' => t('The name of the module that created this ACL entry.'), + 'type' => 'varchar', + 'length' => 255), + 'name' => array( + 'description' => t('A name (or other identifying information) for this ACL entry, given by the module that created it.'), + 'type' => 'varchar', + 'length' => 255)), + 'primary key' => array('acl_id'), + ); + $schema['acl_user'] = array( + 'description' => t('Identifies {users} to which the referenced {acl} entry applies.'), + 'fields' => array( + 'acl_id' => array( + 'description' => t('The {acl}.acl_id of the entry.'), + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0), + 'uid' => array( + 'description' => t('The {user}.uid to which this {acl} entry applies.'), + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0)), + 'primary key' => array('acl_id', 'uid'), + 'unique keys' => array( + 'uid' => array('uid')), + ); + $schema['acl_node'] = array( + 'description' => t('Identifies {node}s to which the referenced {acl} entry applies and defines the permissions granted.'), + 'fields' => array( + 'acl_id' => array( + 'description' => t('The {acl}.acl_id of the entry.'), + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0), + 'nid' => array( + 'description' => t('The {node}.nid to grant permissions for.'), + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0), + 'grant_view' => array( + 'description' => t('Whether to grant "view" permission.'), + 'type' => 'int', + 'size' => 'tiny', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0), + 'grant_update' => array( + 'description' => t('Whether to grant "update" permission.'), + 'type' => 'int', + 'size' => 'tiny', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0), + 'grant_delete' => array( + 'description' => t('Whether to grant "delete" permission.'), + 'type' => 'int', + 'size' => 'tiny', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0)), + 'primary key' => array('acl_id', 'nid'), + ); + return $schema; } + /* * Implementation of hook_uninstall */ function acl_uninstall() { - if ($GLOBALS['db_type'] == 'pgsql') { - db_query('DROP INDEX {acl_user}_uid_index'); - } - db_query('DROP TABLE {acl}'); - db_query('DROP TABLE {acl_user}'); - db_query('DROP TABLE {acl_node}'); -} - -/** - * Fixes table prefix - */ -function acl_update_1() { - $ret = array(); - switch ($GLOBALS['db_type']) { - case 'mysqli': - case 'mysql': - db_query('LOCK TABLES {sequences} WRITE'); - $ret[] = update_sql("UPDATE {sequences} SET name = '". db_prefix_tables('{acl}_acl_id') ."' WHERE name = 'acl_id'"); - db_query('UNLOCK TABLES'); - break; - case 'pgsql': - db_query('START TRANSACTION;'); - $ret[] = update_sql("CREATE SEQUENCE {acl}_acl_id_seq START ". db_next_id('acl_id')); - db_query('COMMIT;'); - break; - } - return $ret; + drupal_uninstall_schema('acl'); } /** @@ -95,49 +99,14 @@ function acl_update_1() { */ function acl_update_2() { $ret = array(); - switch ($GLOBALS['db_type']) { - case 'mysqli': - case 'mysql': - // drop the previously created indexes (except for acl_user.uid) - $ret[] = update_sql('ALTER TABLE {acl} DROP INDEX acl_id'); - $ret[] = update_sql('ALTER TABLE {acl_user} DROP INDEX acl_id'); - $ret[] = update_sql('ALTER TABLE {acl_node} DROP INDEX acl_id'); - $ret[] = update_sql('ALTER TABLE {acl_node} DROP INDEX nid'); - // create new indexes (as primary keys this time) - $ret[] = update_sql('ALTER TABLE {acl} ADD PRIMARY KEY (acl_id)'); - $ret[] = update_sql('ALTER TABLE {acl_user} ADD PRIMARY KEY (acl_id, uid)'); - $ret[] = update_sql('ALTER TABLE {acl_node} ADD PRIMARY KEY (acl_id, nid)'); - break; - - case 'pgsql': - $ret[] = update_sql('ALTER TABLE {acl} DROP PRIMARY KEY , ADD PRIMARY KEY (acl_id)'); - $ret[] = update_sql('ALTER TABLE {acl_user} DROP PRIMARY KEY , ADD PRIMARY KEY (acl_id, uid)'); - $ret[] = update_sql('ALTER TABLE {acl_node} DROP PRIMARY KEY , ADD PRIMARY KEY (acl_id, nid)'); - $ret[] = update_sql('CREATE INDEX {acl_user}_uid_index ON {acl_user} (uid)'); - break; - } - return $ret; -} - -/* - * Updates tables to use utf8 for mysql - */ -function acl_update_3() { - $ret = array(); - // Only for MySQL 4.1+ - switch ($GLOBALS['db_type']) { - case 'mysqli': - break; - case 'mysql': - if (version_compare(mysql_get_server_info($GLOBALS['active_db']), '4.1.0', '<')) { - return array(); - } - break; - case 'pgsql': - return array(); - } - $ret = update_convert_table_utf8('acl'); - $ret = array_merge($ret, update_convert_table_utf8('acl_node')); - $ret = array_merge($ret, update_convert_table_utf8('acl_user')); + // drop the previously created indexes (except for acl_user.uid) + db_drop_index($ret, 'acl', 'acl_id'); + db_drop_index($ret, 'acl_user', 'acl_id'); + db_drop_index($ret, 'acl_node', 'acl_id'); + db_drop_index($ret, 'acl_node', 'nid'); + // create new indexes (as primary keys this time) + db_add_primary_key($ret, 'acl', array('acl_id')); + db_add_primary_key($ret, 'acl_user', array('acl_id', 'uid')); + db_add_primary_key($ret, 'acl_node', array('acl_id', 'nid')); return $ret; } diff --git a/acl.module b/acl.module index eeb37c96f6268d9f56f28519ac224dcf857b3950..e84fa5779021764230332de6f491ea48147dd3f3 100644 --- a/acl.module +++ b/acl.module @@ -4,7 +4,7 @@ /** * @file acl.module * - * This module handls ACLs on behalf of other modules. The two main reasons + * This module handles ACLs on behalf of other modules. The two main reasons * to do this are so that modules using ACLs can share them with each * other without having to actually know much about them, and so that * ACLs can easily co-exist with the existing node_access system. @@ -14,9 +14,11 @@ * Create a new ACL. */ function acl_create_new_acl($module, $name) { - $acl_id = db_next_id('{acl}_acl_id'); - db_query("INSERT INTO {acl} (acl_id, module, name) VALUES (%d, '%s', '%s')", $acl_id, $module, $name); - return $acl_id; + $acl = array('module' => $module, 'name' => $name); + drupal_write_record('acl', $acl); + ///$acl_id = db_next_id('{acl}_acl_id'); + ///db_query("INSERT INTO {acl} (acl_id, module, name) VALUES (%d, '%s', '%s')", $acl_id, $module, $name); + return $acl['acl_id']; } /** @@ -247,12 +249,23 @@ function acl_node_grants($account, $op) { } /** - * Implementation of hook_disable + * Implementation of hook_node_access_interpret */ -function acl_disable() { - drupal_set_message(t('You have disabled the ACL module—to avoid permission problems you should now go to !link and click on the [!button] button!', array( - '!link' => l('admin/content/node-settings', 'admin/content/node-settings'), - '!button' => t('Rebuild permissions'), - ))); +function acl_node_access_interpret($realm, $gid, $nid) { + static $interpretations = array(); + if ($realm == 'acl') { + if (!isset($interpretations[$gid])) { + $acl = db_fetch_object(db_query("SELECT * from {acl} WHERE acl_id = %d", $gid)); + $interpretations[$gid] = $acl->module .'/'. $acl->name; + $result = db_query("SELECT u.name FROM {acl_user} au, {users} u WHERE au.acl_id = %d AND au.uid = u.uid", $gid); + while ($user = db_fetch_object($result)) { + $users[] = $user->name; + } + if ($users) { + $interpretations[$gid] .= ': '. implode(', ', $users); + } + } + return $interpretations[$gid]; + } }