web: users automatically obtain logger permissions when registering their first Fluksometer
This commit is contained in:
parent
44ca2c9b88
commit
685fba7a81
|
@ -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_devices} SET uid = %d WHERE serial = %d", $user->uid, $serial);
|
||||||
db_query("UPDATE {logger_meters} SET uid = %d WHERE device = '%s'", $user->uid, $device);
|
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);
|
db_query("INSERT INTO {logger_users} (uid, private) VALUES (%d, %d)", $user->uid, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ function logger_init() {
|
||||||
* Implementation of hook_perm().
|
* Implementation of hook_perm().
|
||||||
*/
|
*/
|
||||||
function logger_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 callback' => 'drupal_get_form',
|
||||||
'page arguments' => array('_logger_account_devices'),
|
'page arguments' => array('_logger_account_devices'),
|
||||||
'access callback' => '_logger_account_access',
|
'access callback' => '_logger_account_access',
|
||||||
'access arguments' => array('logger', 1),
|
'access arguments' => array('register devices', 1),
|
||||||
'type' => MENU_LOCAL_TASK,
|
'type' => MENU_LOCAL_TASK,
|
||||||
'file' => 'logger.admin.inc',
|
'file' => 'logger.admin.inc',
|
||||||
'weight' => 3,
|
'weight' => 3,
|
||||||
|
|
Loading…
Reference in New Issue