Index: modules/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user.module,v retrieving revision 1.432 diff -u -F^f -r1.432 user.module --- modules/user.module 23 Jan 2005 15:39:49 -0000 1.432 +++ modules/user.module 25 Jan 2005 19:07:33 -0000 @@ -667,13 +667,7 @@ function user_menu($may_cache) { $items[] = array('path' => 'admin/user/configure/settings', 'title' => t('settings'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); $items[] = array('path' => 'admin/user/configure/access', 'title' => t('access rules'), - 'callback' => 'user_configure', 'access' => $access, - 'type' => MENU_LOCAL_TASK); - $items[] = array('path' => 'admin/user/configure/access/mail', 'title' => t('e-mail rules'), - 'callback' => 'user_configure', 'access' => $access, - 'type' => MENU_LOCAL_TASK); - $items[] = array('path' => 'admin/user/configure/access/user', 'title' => t('name rules'), - 'callback' => 'user_configure', 'access' => $access, + 'callback' => 'user_admin_access', 'access' => $access, 'type' => MENU_LOCAL_TASK); $items[] = array('path' => 'admin/user/configure/role', 'title' => t('roles'), 'callback' => 'user_configure', 'access' => $access, @@ -1311,60 +1305,99 @@ function user_admin_create($edit = array return form($output); } -function user_admin_access($edit = array()) { - $type = arg(4); +function user_admin_access($op = NULL, $aid = 0) { + if ($_POST['op']) { + $op = $_POST['op']; + } + $edit = $_POST['edit']; - if (empty($type)) { - return; + // If a non-checking form was submitted, then it needs to have a mask. + if ($edit && !$edit['test'] && !$edit['mask']) { + form_set_error('mask', t('You must enter a mask.')); } - $op = $_POST['op']; - $id = arg(5); + switch ($op) { + case t('Add rule'): + if (!form_get_errors()) { + $aid = db_next_id('{access}_aid'); + db_query("INSERT INTO {access} (aid, mask, type, status) VALUES ('%s', '%s', '%s', %d)", $aid, $edit['mask'], $edit['type'], $edit['status']); + drupal_set_message(t('The access rule has been added.')); + // Since we are not refreshing the page we need to clear out $edit. + $edit = array(); + } + break; - if ($op == t('Add rule')) { - $aid = db_next_id('{access}_aid'); - db_query("INSERT INTO {access} (aid, mask, type, status) VALUES ('%s', '%s', '%s', %d)", $aid, $edit['mask'], $type, $edit['status']); - drupal_set_message(t('The access rule has been added.')); - } - else if ($op == t('Check')) { - if (user_deny($type, $edit['test'])) { - drupal_set_message(t('%test is not allowed.', array('%test' => '' .$edit['test'] .''))); - } - else { - drupal_set_message(t('%test is allowed.', array('%test' => ''. $edit['test'] .''))); - } - } - else if ($id) { - db_query('DELETE FROM {access} WHERE aid = %d', $id); - drupal_set_message(t('The access rule has been deleted.')); - } + case 'delete': + db_query('DELETE FROM {access} WHERE aid = %d', $aid); + drupal_set_message(t('The access rule has been deleted.')); + drupal_goto('admin/user/configure/access'); + + case t('Save rule'): + if (!form_get_errors()) { + 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_goto('admin/user/configure/access'); + } + // Fall through to the edit form if there are errors. + case 'edit': + if (!$edit) { + $edit = db_fetch_array(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid)); + } + $form = _user_admin_access_form($edit); + $form .= form_submit(t('Save rule')); + print theme('page', form($form)); + return; - $header = array(t('Type'), t('Mask'), t('Operations')); - $result = db_query("SELECT * FROM {access} WHERE type = '%s' AND status = 1 ORDER BY mask", $type); - while ($rule = db_fetch_object($result)) { - $rows[] = array(t('Allow'), $rule->mask, array('data' => l(t('delete'), "admin/user/configure/access/$type/$rule->aid"), 'align' => 'center')); + case t('Check username'): + case t('Check e-mail'): + if (user_deny($edit['type'], $edit['test'])) { + drupal_set_message(t('%test is not allowed.', array('%test' => ''. $edit['test'] .''))); + } + else { + drupal_set_message(t('%test is allowed.', array('%test' => ''. $edit['test'] .''))); + } + break; } - $result = db_query("SELECT * FROM {access} WHERE type = '%s' AND status = 0 ORDER BY mask", $type); + $header = array(array('data' => t('Rule type'), 'field' => 'status'), array('data' => t('Access type'), 'field' => 'type'), array('data' =>t('Mask'), 'field' => 'mask'), array('data' => t('Operations'), 'colspan' => 2)); + $result = db_query("SELECT aid, type, status, mask FROM {access}". tablesort_sql($header)); + $access_types = array('user' => t('username'), 'mail' => t('e-mail')); + $rows = array(); while ($rule = db_fetch_object($result)) { - $rows[] = array(t('Deny'), $rule->mask, l(t('delete'), "admin/user/configure/access/$type/$rule->aid")); + $rows[] = array($rule->status ? t('allow') : t('deny'), $access_types[$rule->type], $rule->mask, l(t('edit'), 'admin/user/configure/access/edit/'. $rule->aid), l(t('delete'), 'admin/user/configure/access/delete/'. $rule->aid)); + } + if (count($rows) == 0) { + $rows[] = array(array('data' => ''. t('There are currently no access rules.') .'', 'colspan' => 5)); } - - $options = array('1' => t('Allow'), '0' => t('Deny')); - $rows[] = array(form_radios(NUll, 'status', $edit['status'], $options), form_textfield(NULL, 'mask', $edit['mask'], 32, 64), form_submit(t('Add rule'))); $output .= theme('table', $header, $rows); - $output .= '
%: '. t('Matches any number of characters, even zero characters') .'.
_: '. t('Matches exactly one character.') .'
This web page allows the administrators to register a new users by hand. Note that you cannot have a user where either the e-mail address or the username match another user in the system.
'); case 'admin/user/configure/access': - return t('Access rules allow Drupal administrators to choose usernames and e-mail address that are prevented from using drupal. To enter the mask for e-mail addresses click on e-mail rules, for the username mask click on name rules.
', array('%email' => url('admin/user/configure/access/mail'), '%username' => url('admin/user/configure/access/user'))); - case 'admin/user/configure/access/mail': - return t('Setup and test the e-mail access rules. The access function checks if you match a deny and not an allow. If you match only a deny then it is denied. Any other case, such as both a deny and an allow pattern matching, allows the pattern.
'); - case 'admin/user/configure/access/user': - return t('Setup and test the username access rules. The access function checks if you match a deny and not an allow. If you do then it is denied. Any other case, such as a deny pattern and an allow pattern, allows the pattern.
'); + return ''. t('Set up username and e-mail address access rules for new accounts. If a username or email address for a new account matches any deny rule, but not an allow rule, then the new account will not be allowed to be created.') .'
'; case 'admin/user/configure/permission': return t('In this area you will define the permissions for each user role (role names are defined on the user roles page). Each permission describes a fine-grained logical operation, such as being able to access the administration pages, or adding/modifying a user account. You could say a permission represents access granted to a user to perform a set of operations.
', array('%role' => url('admin/user/configure/role'))); case 'admin/user/configure/role':