You are here

function flexiaccess_user_submit in Flexi Access 7

Commit updates from user page.

1 string reference to 'flexiaccess_user_submit'
flexiaccess_user in ./flexiaccess.users.inc
Build form to handle ACLs for user.

File

./flexiaccess.users.inc, line 176
Form handling for per user ACL.

Code

function flexiaccess_user_submit($form, &$form_state) {
  if (empty($form_state['uncommitted'])) {
    $form_state['uncommitted'] = array();
  }
  foreach ($form_state['values']['acl'] as $ac) {
    if (in_array($ac['nid'], $form_state['uncommitted'])) {

      // New relationship between user and node.
      // Create acls for node where necessary.
      _flexiaccess_create_acl_rows($ac['nid']);
    }

    // Add acls to user.

    /*
     * The following is easily accomplished with a single query.
     * The correct way to do it, however, is to use the API, which
     * unfortunately uses many queries.
     * Would a single query be better at avoiding race conditions?
     */
    foreach (array(
      'view',
      'update',
      'delete',
    ) as $op) {
      $acl_id = acl_get_id_by_name('flexiaccess', $op . '_' . $ac['nid']);

      // Doing both add and remove here ensures that the latest form
      // submission takes effect in the db:
      if (1 == $ac[$op]) {

        // Add permission.
        acl_add_user($acl_id, $form_state['user']->uid);
      }
      else {

        // This block will only be reached when multiple admins have
        // edited the same permissions. Remove permission.
        acl_remove_user($acl_id, $form_state['user']->uid);
      }
    }

    // Apply changes for the node.
    node_access_acquire_grants(node_load($ac['nid']));
  }
  cache_clear_all();
  drupal_set_message(t('Your changes to the ACL has been saved.'));
}