summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalvis2008-01-02 01:54:39 (GMT)
committer salvis2008-01-02 01:54:39 (GMT)
commit7c75e1d32bb94ec0f23bb54f6c8a27acdee6f462 (patch)
treec0d05717fe5929d10ea3ec4c3e66610375556064
parenta1351ce2ca439c95fe3fff163f59f9dfd08c39cc (diff)
Ported to D6.
-rw-r--r--CHANGELOG.txt1
-rw-r--r--acl.info4
-rw-r--r--acl.install215
-rw-r--r--acl.module33
4 files changed, 119 insertions, 134 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 9a7d3f3..de09110 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 728e0a5..2320e1e 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 e241a0a..a0e73bb 100644
--- a/acl.install
+++ b/acl.install
@@ -1,93 +1,97 @@
<?php
// $Id$
-function acl_install() {
- switch ($GLOBALS['db_type']) {
- case 'mysql':
- case 'mysqli':
- db_query("create table if not exists {acl} (
- acl_id int(10) NOT NULL default 0,
- module varchar(255),
- name varchar(255),
- PRIMARY KEY (acl_id)
- ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
-
- db_query("create table if not exists {acl_user} (
- acl_id int(10) NOT NULL default 0,
- uid int(10) NOT NULL default 0,
- PRIMARY KEY (acl_id, uid),
- KEY uid (uid)
- ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
-
- db_query("create table if not exists {acl_node} (
- acl_id int(10) NOT NULL default 0,
- nid int(10) NOT NULL default 0,
- grant_view tinyint(1) unsigned NOT NULL default '0',
- grant_update tinyint(1) unsigned NOT NULL default '0',
- grant_delete tinyint(1) unsigned NOT NULL default '0',
- PRIMARY KEY (acl_id, nid)
- ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
- break;
- case 'pgsql':
- db_query("CREATE TABLE {acl} (
- acl_id integer NOT NULL DEFAULT 0,
- module varchar(255),
- name varchar(255),
- PRIMARY KEY (acl_id)
- );");
- db_query("CREATE SEQUENCE {acl}_acl_id_seq;");
-
- db_query("CREATE TABLE {acl_user} (
- acl_id integer NOT NULL DEFAULT 0,
- uid int NOT NULL DEFAULT 0,
- PRIMARY KEY (acl_id, uid)
- );");
- db_query("CREATE INDEX {acl_user}_uid_index ON {acl_user} (uid)");
+/**
+* Implementation of hook_install().
+*/
+function acl_install() {
+ drupal_install_schema('acl');
+}
- db_query("CREATE TABLE {acl_node} (
- acl_id integer NOT NULL DEFAULT 0,
- nid int NOT NULL DEFAULT 0,
- grant_view smallint NOT NULL default 0,
- grant_update smallint NOT NULL default 0,
- grant_delete smallint NOT NULL default 0,
- PRIMARY KEY (acl_id, nid)
- );");
- break;
- }
+/**
+ * Implementation of hook_schema().
+ */
+function acl_schema() {
+ $schema['acl'] = array(
+ 'description' => 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 eeb37c9..e84fa57 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&mdash;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];
+ }
}