From 685fba7a81c37170162e4825930aeee6cec95b51 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Fri, 12 Mar 2010 17:18:32 +0000 Subject: [PATCH] web: users automatically obtain logger permissions when registering their first Fluksometer --- web/drupal/modules/logger/logger.admin.inc | 6 +++++- web/drupal/modules/logger/logger.module | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/web/drupal/modules/logger/logger.admin.inc b/web/drupal/modules/logger/logger.admin.inc index bec48d4..0b03bca 100644 --- a/web/drupal/modules/logger/logger.admin.inc +++ b/web/drupal/modules/logger/logger.admin.inc @@ -67,7 +67,11 @@ function _logger_account_devices_submit($form, &$form_state) { db_query("UPDATE {logger_devices} SET uid = %d WHERE serial = %d", $user->uid, $serial); db_query("UPDATE {logger_meters} SET uid = %d WHERE device = '%s'", $user->uid, $device); - if (db_result(db_query("SELECT COUNT(*) FROM {logger_users} WHERE uid = %d", $user->uid)) == 0) { + // check whether the user is already a true fluksonian + // if not, generate the proper entries in {users_roles} and {logger_users} + if (!user_access('logger')) { + $rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", 'fluksonian')); + db_query("INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)", $user->uid, $rid); db_query("INSERT INTO {logger_users} (uid, private) VALUES (%d, %d)", $user->uid, 0); } diff --git a/web/drupal/modules/logger/logger.module b/web/drupal/modules/logger/logger.module index 720a8f1..be968bb 100644 --- a/web/drupal/modules/logger/logger.module +++ b/web/drupal/modules/logger/logger.module @@ -52,7 +52,7 @@ function logger_init() { * Implementation of hook_perm(). */ function logger_perm() { - return array('logger'); + return array('logger', 'register devices'); } /** @@ -181,7 +181,7 @@ function logger_menu() { 'page callback' => 'drupal_get_form', 'page arguments' => array('_logger_account_devices'), 'access callback' => '_logger_account_access', - 'access arguments' => array('logger', 1), + 'access arguments' => array('register devices', 1), 'type' => MENU_LOCAL_TASK, 'file' => 'logger.admin.inc', 'weight' => 3,