- Patch #17931 by Neil: fixed bug in access rules page:

* split up the menu callback for editing/adding/deleting rules
  * improved the delete message
  * fixed a double page printing bug
4.6.x
Dries Buytaert 2005-02-28 16:41:15 +00:00
parent 89ccc5d06d
commit 174d22dbbb
2 changed files with 118 additions and 118 deletions

View File

@ -663,17 +663,17 @@ function user_menu($may_cache) {
$items[] = array('path' => 'admin/access/rules/list', 'title' => t('list'), $items[] = array('path' => 'admin/access/rules/list', 'title' => t('list'),
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
$items[] = array('path' => 'admin/access/rules/add', 'title' => t('add rule'), $items[] = array('path' => 'admin/access/rules/add', 'title' => t('add rule'),
'callback' => 'user_admin_access_edit', 'access' => $access, 'callback' => 'user_admin_access_add', 'access' => $access,
'type' => MENU_LOCAL_TASK); 'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'admin/access/rules/check', 'title' => t('check rules'), $items[] = array('path' => 'admin/access/rules/check', 'title' => t('check rules'),
'callback' => 'user_admin_access_check', 'access' => $access, 'callback' => 'user_admin_access_check', 'access' => $access,
'type' => MENU_LOCAL_TASK); 'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'admin/access/rules/edit', 'title' => t('edit rule'), $items[] = array('path' => 'admin/access/rules/edit', 'title' => t('edit rule'),
'callback' => 'user_admin_access_edit', 'access' => $access, 'callback' => 'user_admin_access_edit', 'access' => $access,
'type' => MENU_CALLBACK, 'callback arguments' => array('edit')); 'type' => MENU_CALLBACK);
$items[] = array('path' => 'admin/access/rules/delete', 'title' => t('delete rule'), $items[] = array('path' => 'admin/access/rules/delete', 'title' => t('delete rule'),
'callback' => 'user_admin_access_edit', 'access' => $access, 'callback' => 'user_admin_access_delete', 'access' => $access,
'type' => MENU_CALLBACK, 'callback arguments' => array('delete')); 'type' => MENU_CALLBACK);
if (module_exist('search')) { if (module_exist('search')) {
$items[] = array('path' => 'admin/user/search', 'title' => t('search'), $items[] = array('path' => 'admin/user/search', 'title' => t('search'),
@ -1330,16 +1330,10 @@ function user_admin_access_check() {
} }
/** /**
* Menu callback: add/edit an access rule * Menu callback: add an access rule
*/ */
function user_admin_access_edit($op = NULL, $aid = 0) { function user_admin_access_add() {
if ($_POST['op']) { if ($edit = $_POST['edit']) {
$op = $_POST['op'];
}
$edit = $_POST['edit'];
switch ($op) {
case t('Add rule'):
if (!$edit['mask']) { if (!$edit['mask']) {
form_set_error('mask', t('You must enter a mask.')); form_set_error('mask', t('You must enter a mask.'));
} }
@ -1349,11 +1343,19 @@ function user_admin_access_edit($op = NULL, $aid = 0) {
drupal_set_message(t('The access rule has been added.')); drupal_set_message(t('The access rule has been added.'));
drupal_goto('admin/access/rules'); drupal_goto('admin/access/rules');
} }
break; }
case t('Delete'): $form = _user_admin_access_form($edit);
case 'delete': $form .= form_submit(t('Add rule'));
if ($edit['confirm']) {
print theme('page', form($form, 'post', NULL, array('id' => 'access-rules')));
}
/**
* Menu callback: delete an access rule
*/
function user_admin_access_delete($aid = 0) {
if ($_POST['edit']['confirm']) {
db_query('DELETE FROM {access} WHERE aid = %d', $aid); db_query('DELETE FROM {access} WHERE aid = %d', $aid);
drupal_set_message(t('The access rule has been deleted.')); drupal_set_message(t('The access rule has been deleted.'));
drupal_goto('admin/access/rules'); drupal_goto('admin/access/rules');
@ -1361,24 +1363,29 @@ function user_admin_access_edit($op = NULL, $aid = 0) {
else { else {
$access_types = array('user' => t('username'), 'mail' => t('e-mail')); $access_types = array('user' => t('username'), 'mail' => t('e-mail'));
$edit = db_fetch_object(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid)); $edit = db_fetch_object(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid));
$output .= form_item(t('Confirm deletion'), $edit->mask .' ('. $access_types[$edit->type] .')'); $output = '<p>'. t('Are you sure you want to delete the %type rule for %rule?', array('%type' => $access_types[$edit->type], '%rule' => '<em>'. $edit->mask .'</em>')) .'</p>';
$output .= form_hidden('aid', $edit->aid);
$output .= form_hidden('confirm', 1); $output .= form_hidden('confirm', 1);
$output .= form_submit(t('Delete')); $output .= form_submit(t('Delete'));
$output = form($output); $output = form($output);
print theme('page', $output); print theme('page', $output);
} }
return; }
case t('Save rule'): /**
if (!form_get_errors()) { * Menu callback: edit an access rule
*/
function user_admin_access_edit($aid = 0) {
if ($edit = $_POST['edit']) {
if (!$edit['mask']) {
form_set_error('mask', t('You must enter a mask.'));
}
else {
db_query("UPDATE {access} SET mask = '%s', type = '%s', status = '%s' WHERE aid = %d", $edit['mask'], $edit['type'], $edit['status'], $aid); db_query("UPDATE {access} SET mask = '%s', type = '%s', status = '%s' WHERE aid = %d", $edit['mask'], $edit['type'], $edit['status'], $aid);
drupal_set_message(t('The access rule has been saved.')); drupal_set_message(t('The access rule has been saved.'));
drupal_goto('admin/access/rules'); drupal_goto('admin/access/rules');
} }
// Fall through to the edit form if there are errors. }
case 'edit': else {
if (!$edit) {
$edit = db_fetch_array(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid)); $edit = db_fetch_array(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid));
} }
$form = _user_admin_access_form($edit); $form = _user_admin_access_form($edit);
@ -1386,13 +1393,6 @@ function user_admin_access_edit($op = NULL, $aid = 0) {
print theme('page', form($form, 'post', NULL, array('id' => 'access-rules'))); print theme('page', form($form, 'post', NULL, array('id' => 'access-rules')));
} }
$form = _user_admin_access_form($edit);
$form .= form_submit(t('Add rule'));
$output .= form($form, 'post', NULL, array('id' => 'access-rules'));
print theme('page', $output);
}
function _user_admin_access_form($edit) { function _user_admin_access_form($edit) {
$output = '<div class="access-type">'. form_radios(t('Access type'), 'status', $edit['status'], array('1' => t('Allow'), '0' => t('Deny'))) .'</div>'; $output = '<div class="access-type">'. form_radios(t('Access type'), 'status', $edit['status'], array('1' => t('Allow'), '0' => t('Deny'))) .'</div>';
$output .= '<div class="rule-type">'. form_radios(t('Rule type'), 'type', $edit['type'] ? $edit['type'] : 'user', array('user' => t('Username'), 'mail' => t('E-mail'))) .'</div>'; $output .= '<div class="rule-type">'. form_radios(t('Rule type'), 'type', $edit['type'] ? $edit['type'] : 'user', array('user' => t('Username'), 'mail' => t('E-mail'))) .'</div>';

View File

@ -663,17 +663,17 @@ function user_menu($may_cache) {
$items[] = array('path' => 'admin/access/rules/list', 'title' => t('list'), $items[] = array('path' => 'admin/access/rules/list', 'title' => t('list'),
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
$items[] = array('path' => 'admin/access/rules/add', 'title' => t('add rule'), $items[] = array('path' => 'admin/access/rules/add', 'title' => t('add rule'),
'callback' => 'user_admin_access_edit', 'access' => $access, 'callback' => 'user_admin_access_add', 'access' => $access,
'type' => MENU_LOCAL_TASK); 'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'admin/access/rules/check', 'title' => t('check rules'), $items[] = array('path' => 'admin/access/rules/check', 'title' => t('check rules'),
'callback' => 'user_admin_access_check', 'access' => $access, 'callback' => 'user_admin_access_check', 'access' => $access,
'type' => MENU_LOCAL_TASK); 'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'admin/access/rules/edit', 'title' => t('edit rule'), $items[] = array('path' => 'admin/access/rules/edit', 'title' => t('edit rule'),
'callback' => 'user_admin_access_edit', 'access' => $access, 'callback' => 'user_admin_access_edit', 'access' => $access,
'type' => MENU_CALLBACK, 'callback arguments' => array('edit')); 'type' => MENU_CALLBACK);
$items[] = array('path' => 'admin/access/rules/delete', 'title' => t('delete rule'), $items[] = array('path' => 'admin/access/rules/delete', 'title' => t('delete rule'),
'callback' => 'user_admin_access_edit', 'access' => $access, 'callback' => 'user_admin_access_delete', 'access' => $access,
'type' => MENU_CALLBACK, 'callback arguments' => array('delete')); 'type' => MENU_CALLBACK);
if (module_exist('search')) { if (module_exist('search')) {
$items[] = array('path' => 'admin/user/search', 'title' => t('search'), $items[] = array('path' => 'admin/user/search', 'title' => t('search'),
@ -1330,16 +1330,10 @@ function user_admin_access_check() {
} }
/** /**
* Menu callback: add/edit an access rule * Menu callback: add an access rule
*/ */
function user_admin_access_edit($op = NULL, $aid = 0) { function user_admin_access_add() {
if ($_POST['op']) { if ($edit = $_POST['edit']) {
$op = $_POST['op'];
}
$edit = $_POST['edit'];
switch ($op) {
case t('Add rule'):
if (!$edit['mask']) { if (!$edit['mask']) {
form_set_error('mask', t('You must enter a mask.')); form_set_error('mask', t('You must enter a mask.'));
} }
@ -1349,11 +1343,19 @@ function user_admin_access_edit($op = NULL, $aid = 0) {
drupal_set_message(t('The access rule has been added.')); drupal_set_message(t('The access rule has been added.'));
drupal_goto('admin/access/rules'); drupal_goto('admin/access/rules');
} }
break; }
case t('Delete'): $form = _user_admin_access_form($edit);
case 'delete': $form .= form_submit(t('Add rule'));
if ($edit['confirm']) {
print theme('page', form($form, 'post', NULL, array('id' => 'access-rules')));
}
/**
* Menu callback: delete an access rule
*/
function user_admin_access_delete($aid = 0) {
if ($_POST['edit']['confirm']) {
db_query('DELETE FROM {access} WHERE aid = %d', $aid); db_query('DELETE FROM {access} WHERE aid = %d', $aid);
drupal_set_message(t('The access rule has been deleted.')); drupal_set_message(t('The access rule has been deleted.'));
drupal_goto('admin/access/rules'); drupal_goto('admin/access/rules');
@ -1361,24 +1363,29 @@ function user_admin_access_edit($op = NULL, $aid = 0) {
else { else {
$access_types = array('user' => t('username'), 'mail' => t('e-mail')); $access_types = array('user' => t('username'), 'mail' => t('e-mail'));
$edit = db_fetch_object(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid)); $edit = db_fetch_object(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid));
$output .= form_item(t('Confirm deletion'), $edit->mask .' ('. $access_types[$edit->type] .')'); $output = '<p>'. t('Are you sure you want to delete the %type rule for %rule?', array('%type' => $access_types[$edit->type], '%rule' => '<em>'. $edit->mask .'</em>')) .'</p>';
$output .= form_hidden('aid', $edit->aid);
$output .= form_hidden('confirm', 1); $output .= form_hidden('confirm', 1);
$output .= form_submit(t('Delete')); $output .= form_submit(t('Delete'));
$output = form($output); $output = form($output);
print theme('page', $output); print theme('page', $output);
} }
return; }
case t('Save rule'): /**
if (!form_get_errors()) { * Menu callback: edit an access rule
*/
function user_admin_access_edit($aid = 0) {
if ($edit = $_POST['edit']) {
if (!$edit['mask']) {
form_set_error('mask', t('You must enter a mask.'));
}
else {
db_query("UPDATE {access} SET mask = '%s', type = '%s', status = '%s' WHERE aid = %d", $edit['mask'], $edit['type'], $edit['status'], $aid); db_query("UPDATE {access} SET mask = '%s', type = '%s', status = '%s' WHERE aid = %d", $edit['mask'], $edit['type'], $edit['status'], $aid);
drupal_set_message(t('The access rule has been saved.')); drupal_set_message(t('The access rule has been saved.'));
drupal_goto('admin/access/rules'); drupal_goto('admin/access/rules');
} }
// Fall through to the edit form if there are errors. }
case 'edit': else {
if (!$edit) {
$edit = db_fetch_array(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid)); $edit = db_fetch_array(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid));
} }
$form = _user_admin_access_form($edit); $form = _user_admin_access_form($edit);
@ -1386,13 +1393,6 @@ function user_admin_access_edit($op = NULL, $aid = 0) {
print theme('page', form($form, 'post', NULL, array('id' => 'access-rules'))); print theme('page', form($form, 'post', NULL, array('id' => 'access-rules')));
} }
$form = _user_admin_access_form($edit);
$form .= form_submit(t('Add rule'));
$output .= form($form, 'post', NULL, array('id' => 'access-rules'));
print theme('page', $output);
}
function _user_admin_access_form($edit) { function _user_admin_access_form($edit) {
$output = '<div class="access-type">'. form_radios(t('Access type'), 'status', $edit['status'], array('1' => t('Allow'), '0' => t('Deny'))) .'</div>'; $output = '<div class="access-type">'. form_radios(t('Access type'), 'status', $edit['status'], array('1' => t('Allow'), '0' => t('Deny'))) .'</div>';
$output .= '<div class="rule-type">'. form_radios(t('Rule type'), 'type', $edit['type'] ? $edit['type'] : 'user', array('user' => t('Username'), 'mail' => t('E-mail'))) .'</div>'; $output .= '<div class="rule-type">'. form_radios(t('Rule type'), 'type', $edit['type'] ? $edit['type'] : 'user', array('user' => t('Username'), 'mail' => t('E-mail'))) .'</div>';