Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.963
diff -u -r1.963 user.module
--- modules/user/user.module 9 Feb 2009 07:36:15 -0000 1.963
+++ modules/user/user.module 6 Mar 2009 22:18:04 -0000
@@ -1248,7 +1248,15 @@
'access arguments' => array('administer permissions'),
'type' => MENU_CALLBACK,
);
-
+
+ $items['admin/user/roles/delete'] = array(
+ 'title' => 'Delete role',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('user_admin_role_delete'),
+ 'access arguments' => array('administer permissions'),
+ 'type' => MENU_CALLBACK,
+ );
+
$items['user/%user_uid_optional'] = array(
'title' => 'My account',
'title callback' => 'user_page_title',
@@ -2256,7 +2264,7 @@
case 'admin/user/permissions':
return '
' . 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:
+ 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.
By default, Drupal comes with two user roles:
- Anonymous user: this role is used for users that don\'t have a user account or that are not authenticated.
- Authenticated user: this role is automatically granted to all logged in users.
Index: modules/user/user.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.admin.inc,v
retrieving revision 1.37
diff -u -r1.37 user.admin.inc
--- modules/user/user.admin.inc 3 Feb 2009 18:55:32 -0000 1.37
+++ modules/user/user.admin.inc 6 Mar 2009 22:18:04 -0000
@@ -732,14 +732,6 @@
db_query("UPDATE {role} SET name = '%s' WHERE rid = %d", $form_state['values']['name'], $form_state['values']['rid']);
drupal_set_message(t('The role has been renamed.'));
}
- elseif ($form_state['values']['op'] == t('Delete role')) {
- 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.'));
- }
elseif ($form_state['values']['op'] == t('Add role')) {
db_query("INSERT INTO {role} (name) VALUES ('%s')", $form_state['values']['name']);
drupal_set_message(t('The role has been added.'));
@@ -799,17 +791,17 @@
* @ingroup themeable
*/
function theme_user_admin_new_role($form) {
- $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 2));
+ $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 3));
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);
+ $rows[] = array($name, $edit_permissions, l(t('rename role'), 'admin/user/roles/edit/' . $rid), l(t('delete role'), 'admin/user/roles/delete/'.$rid));
}
else {
- $rows[] = array($name, t('locked'), $edit_permissions);
+ $rows[] = array($name, $edit_permissions, t('locked'), t('locked'),);
}
}
- $rows[] = array(drupal_render($form['name']), array('data' => drupal_render($form['submit']), 'colspan' => 2));
+ $rows[] = array(drupal_render($form['name']), array('data' => drupal_render($form['submit']), 'colspan' => 3));
$output = drupal_render_children($form);
$output .= theme('table', $header, $rows);
@@ -862,3 +854,36 @@
return $output;
}
+/**
+ * Menu callback -- ask for confirmation of role deletion
+ */
+function user_admin_role_delete() {
+ $rid = arg(4);
+ $form['rid'] = array(
+ '#type' => 'value',
+ '#value' => $rid,
+ );
+ $roles = user_roles();
+ return confirm_form($form,
+ t('Are you sure you want to delete the role: %title?', array('%title' => $roles[$rid])),
+ isset($_GET['destination']) ? $_GET['destination'] : 'admin/user/roles',
+ t('This action cannot be undone.'),
+ t('Delete'),
+ t('Cancel')
+ );
+}
+
+/**
+ * Execute role deletion
+ */
+function user_admin_role_delete_submit($form, &$form_state) {
+ if ($form_state['values']['confirm']) {
+ 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';
+}