? .project ? sites/default/files ? sites/default/settings.php Index: modules/user/user.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.admin.inc,v retrieving revision 1.43 diff -u -p -r1.43 user.admin.inc --- modules/user/user.admin.inc 26 Apr 2009 19:44:40 -0000 1.43 +++ modules/user/user.admin.inc 30 Apr 2009 15:19:35 -0000 @@ -676,46 +676,39 @@ function theme_user_admin_perm($form) { function user_admin_role() { $rid = arg(4); if ($rid) { - if ($rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID) { - drupal_goto('admin/user/roles'); - } - // Display the edit role form. $role = db_query('SELECT * FROM {role} WHERE rid = :rid', array(':rid' => $rid))->fetchObject(); + } + // Display the edit role form. $form['name'] = array( '#type' => 'textfield', '#title' => t('Role name'), - '#default_value' => $role->name, + '#default_value' => isset($role->name) ? check_plain($role->name) : NULL, '#size' => 30, '#required' => TRUE, '#maxlength' => 64, '#description' => t('The name for this role. Example: "moderator", "editorial board", "site architect".'), ); + // Disable and fill in protected role names. + if ($rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID) { + $form['name']['#disabled'] = true; + $form['name']['#value'] = t($role->name); + } + $form['description'] = array( + '#type' => 'textarea', + '#title' => t('Description'), + '#default_value' => isset($role->description) ? filter_xss_admin($role->description) : NULL, + '#description' => t('A description of the role to explain what it is for. Example: "Can perform content administration tasks, but cannot ban users."'), + ); $form['rid'] = array( '#type' => 'value', '#value' => $rid, ); $form['submit'] = array( '#type' => 'submit', - '#value' => t('Save role'), - ); - $form['delete'] = array( - '#type' => 'submit', - '#value' => t('Delete role'), - ); - } - else { - $form['name'] = array( - '#type' => 'textfield', - '#size' => 32, - '#maxlength' => 64, - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Add role'), + '#value' => $rid ? t('Save role') : t('Add role'), ); $form['#submit'][] = 'user_admin_role_submit'; $form['#validate'][] = 'user_admin_role_validate'; - } return $form; } @@ -745,7 +738,8 @@ function user_admin_role_submit($form, & if ($form_state['values']['op'] == t('Save role')) { db_update('role') ->fields(array( - 'name' => $form_state['values']['name'], + 'name' => $form_state['values']['name'], + 'description' => $form_state['values']['description'], )) ->condition('rid', $form_state['values']['rid']) ->execute(); @@ -760,12 +754,55 @@ function user_admin_role_submit($form, & drupal_set_message(t('The role has been deleted.')); } elseif ($form_state['values']['op'] == t('Add role')) { - db_insert('role')->fields(array('name' => $form_state['values']['name']))->execute(); + db_insert('role') + ->fields(array( + 'name' => $form_state['values']['name'], + 'description' => $form_state['values']['description'], + ))->execute(); drupal_set_message(t('The role has been added.')); } $form_state['redirect'] = 'admin/user/roles'; return; } +/** + * Implementation of confirmation form for role deletion + * + * @ingroup forms + * @see user_admin_role_delete_submit() + */ +function user_admin_role_delete($form_id, $rid) { + $role = db_query('SELECT * FROM {role} WHERE rid = :rid', array(':rid' => $rid))->fetchObject(); + + $form = array(); + $form['rid'] = array( + '#type' => 'value', + '#value' => $rid, + ); + $form = confirm_form($form, + t('Are you sure you want to delete the %title role?', array('%title' => $role->name)), + isset($_GET['destination']) ? $_GET['destination'] : 'admin/user/roles', + t('This action cannot be undone.'), + t('Delete role'), + t('Cancel') + ); + return $form; +} + +/** + * Submit handler for role deletion + * + * @ingroup forms + * @see user_admin_role_delete() + */ +function user_admin_role_delete_submit($form, &$form_state) { + db_query('DELETE FROM {role} WHERE rid = %d', $form_state['values']['rid']); + db_query('DELETE FROM {role_permission} WHERE rid = %d', $form_state['values']['rid']); + // Update the users who have this role set: + db_query('DELETE FROM {users_roles} WHERE rid = %d', $form_state['values']['rid']); + drupal_set_message(t('The role has been deleted.')); + $form_state['redirect'] = 'admin/user/roles'; +} + /** * Theme user administration overview. @@ -811,29 +848,34 @@ function theme_user_admin_account($form) return $output; } - /** - * Theme the new-role form. + * Displays the role admin overview page. * - * @ingroup themeable */ -function theme_user_admin_new_role($form) { - $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 2)); - foreach (user_roles() as $rid => $name) { - $edit_permissions = l(t('edit permissions'), 'admin/user/permissions/' . $rid); - if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) { - $rows[] = array($name, l(t('edit role'), 'admin/user/roles/edit/' . $rid), $edit_permissions); +function user_admin_role_list() { + $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 3)); + $result = db_query("SELECT r.rid, r.name, r.description FROM {role} r"); + while ($role = db_fetch_object($result)) { + if (!in_array($role->rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) { + $delete = l(t('delete'), 'admin/user/roles/delete/' . $role->rid); } else { - $rows[] = array($name, t('locked'), $edit_permissions); + $delete = t('required'); } + $rows[] = array( + check_plain($role->name) . '
' . t('Permissions let you control what users can do on your site. Each user role (defined on the user roles page) has its own set of permissions. For example, you could give users classified as "Administrators" permission to "administer nodes" but deny this power to ordinary, "authenticated" users. You can use permissions to reveal new features to privileged users (those with subscriptions, for example). Permissions also allow trusted users to share the administrative burden of running a busy site.', array('@role' => url('admin/user/roles'))) . '
'; case 'admin/user/roles': - return t('Roles allow you to fine tune the security and administration of Drupal. A role defines a group of users that have certain privileges as defined in user permissions. Examples of roles include: anonymous user, authenticated user, moderator, administrator and so on. In this area you will define the role names of the various roles. To delete a role choose "edit".
By default, Drupal comes with two user roles:
-A role defines a group of users that share a common set of privileges as defined in user permissions. Examples of roles include: moderator, administrator and so on. Authenticated user and Anonymous user are two default roles that cannot be deleted.
', array('@permissions' => url('admin/user/permissions'))); case 'admin/user/search': return '' . t('Enter a simple pattern ("*" may be used as a wildcard match) to search for a username or e-mail address. For example, one may search for "br" and Drupal might return "brian", "brad", and "brenda@example.com".') . '
'; } @@ -2499,7 +2517,6 @@ function user_build_filter_query() { function user_forms() { $forms['user_admin_access_add_form']['callback'] = 'user_admin_access_form'; $forms['user_admin_access_edit_form']['callback'] = 'user_admin_access_form'; - $forms['user_admin_new_role']['callback'] = 'user_admin_role'; return $forms; } @@ -2909,4 +2926,25 @@ function _user_forms(&$edit, $account, $ return empty($groups) ? FALSE : $groups; } - +/** + * Determine what operation can happen to which roles + * @param $op + * The operation being performed on the role + * - "edit" + * - "delete" + * @param $rid + * The unique id of the role + * @return + * TRUE if the operation may be performed + */ +function user_role_access($op, $rid = NULL) { + $is_protected_role = ($rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID); + if( + !user_access('administer permissions') || //not allowed + !key_exists($rid, user_roles()) || //nonexistent role + ($op == 'delete' && $is_protected_role) //protected role + ){ + return false; + } + return true; +}