This module is already very usefull to me but are there any plans to implement a role based ACL? Maybe I'll give it a try myself as an introduction to drupal development

Comments

matt b’s picture

Subscribing!

investigacoes’s picture

subscribing!

this would be perfect!!

Zyxtrio’s picture

I'm fairly new to all this but here is a hardcoded solution <.< (please don't yell at me :) )

First off add the following code to webform_submissions_acl.module

 function webform_submissions_acl_users_by_role($nid, $rid, $id_only = FALSE) {
  $users = array();
  $result = db_query("SELECT u.uid, u.name, u.status FROM {users} u 
INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE ur.rid = %d 
AND u.status = 1", $rid);
  while ($row = db_fetch_object($result)) {
    if ($id_only) {
      $users[] = $row->uid;
    }
    else {
      $users[] = $row;
    }
  }
  return $users;
} 

This is the basic function to return all users with a certain role ($rid).

Next, go to webform_submissions_acl.pages.inc

Under function webform_submissions_acl_form_validate($form, &$form_state) {, change

$account = user_load(array('name' => $form_state['values']['name']));

    if (in_array($account->uid, $node_users)) {
      form_set_error('name', t('User is already added for this form'));
    }

    $account = user_load(array('name' => $form_state['values']['name']));

    if (!$account) {
      form_set_error('name', t('Invalid user'));
    }

to

  $node_users = webform_submissions_acl_users_by_node($form_state['values']['nid'], TRUE);

  if($form_state['values']['name'] == "admin"){
    
    drupal_set_message(t('Added admin accounts'));

  } else {
    $account = user_load(array('name' => $form_state['values']['name']));

    if (in_array($account->uid, $node_users)) {
      form_set_error('name', t('User is already added for this form'));
    }

    $account = user_load(array('name' => $form_state['values']['name']));

    if (!$account) {
      form_set_error('name', t('Invalid user'));
    }
  }

and under function webform_submissions_acl_form_submit($form, &$form_state) {

change

$account = user_load(array('name' => $form_state['values']['name']));

    if ($account) {
      db_query("INSERT INTO {webform_submissions_acl} (nid, uid) VALUES (%d, %d)", $form_state['values']['nid'], $account->uid);
      drupal_set_message(t('The user was succesfully added.'), 'status');
    }
    else {
      drupal_set_message(t('Could not add user.'), 'error');
    }

to

$node_users = webform_submissions_acl_users_by_node($form_state['values']['nid'], TRUE);

  if($form_state['values']['name'] == "admin"){

    $node_add_users = webform_submissions_acl_users_by_role($form_state['values']['nid'],3);

    foreach($node_add_users as $user) {

     if (!in_array($user->uid, $node_users)) {
    
       db_query("INSERT INTO {webform_submissions_acl} (nid, uid) VALUES (%d, %d)", $form_state['values']['nid'], $user->uid);

      }

    }

    $node_add_users = webform_submissions_acl_users_by_role($form_state['values']['nid'],4);

    foreach($node_add_users as $user) {

     if (!in_array($user->uid, $node_users)) {
      
         db_query("INSERT INTO {webform_submissions_acl} (nid, uid) VALUES (%d, %d)", $form_state['values']['nid'], $user->uid);
      
      }
         
    }

  } else {

  
    $account = user_load(array('name' => $form_state['values']['name']));

    if ($account) {
      db_query("INSERT INTO {webform_submissions_acl} (nid, uid) VALUES (%d, %d)", $form_state['values']['nid'], $account->uid);
      drupal_set_message(t('The user was succesfully added.'), 'status');
    }
    else {
      drupal_set_message(t('Could not add user.'), 'error');
    }

  }

Now in that last code block change the 3 in $node_add_users = webform_submissions_acl_users_by_role($form_state['values']['nid'],3); to the role id of the desired role you want to add. To find the role id, go to admin/user/roles and click on edit role and take note of the number at the end of the url.

Now I have two different admin accounts (a content administrator and a site administrator) hence the $node_add_users = webform_submissions_acl_users_by_role($form_state['values']['nid'],4); (3 is content admin and 4 is site admin)

If you only have one role that you want to mass include, remove

$node_add_users = webform_submissions_acl_users_by_role($form_state['values']['nid'],4);

    foreach($node_add_users as $user) {

     if (!in_array($user->uid, $node_users)) {
      
         db_query("INSERT INTO {webform_submissions_acl} (nid, uid) VALUES (%d, %d)", $form_state['values']['nid'], $user->uid);
      
      }
         
    }

Now to add all admin users just type admin into the username textfield on the acl form and hit submit :)

Now I realize this is dirty and not oop :P I'm willing to work on that if someone wants a more user friendly version (Roles listed with a number to fill in as the username?)