You are here

function administerusersbyrole_permission in Administer Users by Role 7.2

Same name and namespace in other branches
  1. 7 administerusersbyrole.module \administerusersbyrole_permission()

Implements hook_permission().

File

./administerusersbyrole.module, line 16
Provides fine-grained permissions for creating, editing, and deleting users.

Code

function administerusersbyrole_permission() {
  $roles = user_roles(TRUE);

  // Exclude the admin role.  Once you can edit an admin, you can set their password, log in and do anything,
  // which defeats the point of using this module.
  $admin_rid = variable_get('user_admin_role', 0);
  $perms = array();
  $perms['create users'] = array(
    'title' => 'Create new users',
  );
  $perms['access users overview'] = array(
    'title' => 'Access the users overview page',
  );
  $ops = array(
    'edit' => t('edit'),
    'cancel' => t('cancel'),
  );
  foreach ($roles as $rid => $role) {
    if ($rid == $admin_rid) {
      continue;
    }
    foreach ($ops as $op => $operation) {
      $perm_string = _administerusersbyrole_build_perm_string($rid, $op);
      if ($rid === DRUPAL_AUTHENTICATED_RID) {
        $perm_title = drupal_ucfirst(t("@operation users with no custom roles", array(
          '@operation' => $operation,
        )));
      }
      else {
        $perm_title = drupal_ucfirst(t("@operation users with role %role", array(
          '@operation' => $operation,
          '%role' => $role,
        )));
      }
      $perms[$perm_string] = array(
        'title' => $perm_title,
      );
    }
  }
  return $perms;
}