Commit dba2ebb1 authored by Dries's avatar Dries

- Patch #570142 by Dave Reid | Dries: get rid of the admin/structure/contact/settings page.

parent e1d4b414
...@@ -162,18 +162,3 @@ function contact_admin_delete_submit($form, &$form_state) { ...@@ -162,18 +162,3 @@ function contact_admin_delete_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/structure/contact'; $form_state['redirect'] = 'admin/structure/contact';
return; return;
} }
function contact_admin_settings() {
$form['contact_hourly_threshold'] = array('#type' => 'select',
'#title' => t('Hourly threshold'),
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50)),
'#default_value' => 3,
'#description' => t('The maximum number of contact form submissions a user can perform per hour.'),
);
$form['contact_default_status'] = array(
'#type' => 'checkbox',
'#title' => t('Enable the personal contact form by default for new users'),
'#default_value' => 1,
);
return system_settings_form($form, TRUE);
}
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
*/ */
function contact_uninstall() { function contact_uninstall() {
variable_del('contact_default_status'); variable_del('contact_default_status');
variable_del('contact_form_information'); variable_del('contact_threshold_limit');
variable_del('contact_hourly_threshold'); variable_del('contact_threshold_window');
} }
/** /**
...@@ -73,3 +73,22 @@ function contact_schema() { ...@@ -73,3 +73,22 @@ function contact_schema() {
return $schema; return $schema;
} }
/**
* @defgroup updates-6.x-to-7.x Contact updates from 6.x to 7.x
* @{
*/
/**
* Rename the threshold limit variable.
*/
function contact_update_7000() {
variable_set('contact_threshold_limit', variable_get('contact_hourly_threshold', 5));
variable_del('contact_hourly_threshold');
return array();
}
/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.
*/
...@@ -59,12 +59,6 @@ function contact_menu() { ...@@ -59,12 +59,6 @@ function contact_menu() {
'access arguments' => array('administer site-wide contact form'), 'access arguments' => array('administer site-wide contact form'),
'file' => 'contact.admin.inc', 'file' => 'contact.admin.inc',
); );
$items['admin/structure/contact/list'] = array(
'title' => 'List',
'page callback' => 'contact_admin_categories',
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'contact.admin.inc',
);
$items['admin/structure/contact/add'] = array( $items['admin/structure/contact/add'] = array(
'title' => 'Add category', 'title' => 'Add category',
'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form',
...@@ -90,15 +84,6 @@ function contact_menu() { ...@@ -90,15 +84,6 @@ function contact_menu() {
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'file' => 'contact.admin.inc', 'file' => 'contact.admin.inc',
); );
$items['admin/structure/contact/settings'] = array(
'title' => 'Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('contact_admin_settings'),
'access arguments' => array('administer site-wide contact form'),
'file' => 'contact.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['contact'] = array( $items['contact'] = array(
'title' => 'Contact', 'title' => 'Contact',
'page callback' => 'contact_site_page', 'page callback' => 'contact_site_page',
...@@ -201,3 +186,19 @@ function contact_mail($key, &$message, $params) { ...@@ -201,3 +186,19 @@ function contact_mail($key, &$message, $params) {
break; break;
} }
} }
/**
* Implement of hook_form_FORM_ID_alter().
*/
function contact_form_user_admin_settings_alter(&$form, $form_state) {
$form['contact'] = array(
'#type' => 'fieldset',
'#title' => t('Contact forms'),
'#weight' => 0,
);
$form['contact']['contact_default_status'] = array(
'#type' => 'checkbox',
'#title' => t('Enable the personal contact form by default for new users.'),
'#default_value' => 1,
);
}
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
* Site-wide contact page. * Site-wide contact page.
*/ */
function contact_site_page() { function contact_site_page() {
if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3)) && !user_access('administer site-wide contact form')) { if (!flood_is_allowed('contact', variable_get('contact_threshold_limit', 5), variable_get('contact_threshold_window', 3600)) && !user_access('administer site-wide contact form')) {
$output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3))); $output = t("You cannot send more than %number messages in @interval. Please try again later.", array('%number' => variable_get('contact_threshold_limit', 3), '@interval' => format_interval(variable_get('contact_threshold_window', 3600))));
} }
elseif (!db_query("SELECT COUNT(cid) FROM {contact}")->fetchField()) { elseif (!db_query("SELECT COUNT(cid) FROM {contact}")->fetchField()) {
if (user_access('administer site-wide contact form')) { if (user_access('administer site-wide contact form')) {
...@@ -157,8 +157,8 @@ function contact_personal_page($account) { ...@@ -157,8 +157,8 @@ function contact_personal_page($account) {
if (!valid_email_address($user->mail)) { if (!valid_email_address($user->mail)) {
$output = t('You need to provide a valid e-mail address to contact other users. Please update your <a href="@url">user information</a> and try again.', array('@url' => url("user/$user->uid/edit", array('query' => 'destination=' . drupal_get_destination())))); $output = t('You need to provide a valid e-mail address to contact other users. Please update your <a href="@url">user information</a> and try again.', array('@url' => url("user/$user->uid/edit", array('query' => 'destination=' . drupal_get_destination()))));
} }
elseif (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3)) && !user_access('administer site-wide contact form')) { elseif (!flood_is_allowed('contact', variable_get('contact_threshold_limit', 5), variable_get('contact_threshold_window', 3600)) && !user_access('administer site-wide contact form')) {
$output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3))); $output = t("You cannot send more than %number messages in @interval. Please try again later.", array('%number' => variable_get('contact_threshold_limit', 3), '@interval' => format_interval(variable_get('contact_threshold_window', 3600))));
} }
else { else {
drupal_set_title($account->name); drupal_set_title($account->name);
......
...@@ -22,14 +22,17 @@ class ContactSitewideTestCase extends DrupalWebTestCase { ...@@ -22,14 +22,17 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
*/ */
function testSiteWideContact() { function testSiteWideContact() {
// Create and login administrative user. // Create and login administrative user.
$admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer site-wide contact form', 'administer permissions')); $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer site-wide contact form', 'administer permissions', 'administer users'));
$this->drupalLogin($admin_user); $this->drupalLogin($admin_user);
$flood_limit = 3;
variable_set('contact_threshold_limit', $flood_limit);
variable_set('contact_threshold_window', 600);
// Set settings. // Set settings.
$edit = array(); $edit = array();
$edit['contact_hourly_threshold'] = 3;
$edit['contact_default_status'] = TRUE; $edit['contact_default_status'] = TRUE;
$this->drupalPost('admin/structure/contact/settings', $edit, t('Save configuration')); $this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.')); $this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.'));
// Delete old categories to ensure that new categories are used. // Delete old categories to ensure that new categories are used.
...@@ -139,13 +142,13 @@ class ContactSitewideTestCase extends DrupalWebTestCase { ...@@ -139,13 +142,13 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
$this->assertText(t('You must select a valid category.'), t('Valid category required.')); $this->assertText(t('You must select a valid category.'), t('Valid category required.'));
// Submit contact form with correct values and check flood interval. // Submit contact form with correct values and check flood interval.
for ($i = 0; $i < $edit['contact_hourly_threshold']; $i++) { for ($i = 0; $i < $flood_limit; $i++) {
$this->submitContact($this->randomName(16), $recipients[0], $this->randomName(16), $categories[0], $this->randomName(64)); $this->submitContact($this->randomName(16), $recipients[0], $this->randomName(16), $categories[0], $this->randomName(64));
$this->assertText(t('Your message has been sent.'), t('Message sent.')); $this->assertText(t('Your message has been sent.'), t('Message sent.'));
} }
// Submit contact form one over limit. // Submit contact form one over limit.
$this->drupalGet('contact'); $this->drupalGet('contact');
$this->assertRaw(t('You cannot send more than %number messages per hour. Please try again later.', array('%number' => $edit['contact_hourly_threshold'])), t('Message threshold reached.')); $this->assertRaw(t('You cannot send more than %number messages in @interval. Please try again later.', array('%number' => variable_get('contact_threshold_limit', 3), '@interval' => format_interval(600))), t('Message threshold reached.'));
// Delete created categories. // Delete created categories.
$this->drupalLogin($admin_user); $this->drupalLogin($admin_user);
...@@ -157,7 +160,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase { ...@@ -157,7 +160,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
*/ */
function testAutoReply() { function testAutoReply() {
// Create and login administrative user. // Create and login administrative user.
$admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer site-wide contact form', 'administer permissions')); $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer site-wide contact form', 'administer permissions', 'administer users'));
$this->drupalLogin($admin_user); $this->drupalLogin($admin_user);
// Set up three categories, 2 with an auto-reply and one without. // Set up three categories, 2 with an auto-reply and one without.
...@@ -314,15 +317,16 @@ class ContactPersonalTestCase extends DrupalWebTestCase { ...@@ -314,15 +317,16 @@ class ContactPersonalTestCase extends DrupalWebTestCase {
* Test personal contact form. * Test personal contact form.
*/ */
function testPersonalContact() { function testPersonalContact() {
$admin_user = $this->drupalCreateUser(array('administer site-wide contact form')); $admin_user = $this->drupalCreateUser(array('administer site-wide contact form', 'administer users'));
$this->drupalLogin($admin_user); $this->drupalLogin($admin_user);
$flood_limit = 3;
variable_set('contact_threshold_limit', $flood_limit);
// Enable the personal contact form. // Enable the personal contact form.
$flood_control = 3;
$edit = array(); $edit = array();
$edit['contact_default_status'] = TRUE; $edit['contact_default_status'] = TRUE;
$edit['contact_hourly_threshold'] = $flood_control; $this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration'));
$this->drupalPost('admin/structure/contact/settings', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.')); $this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.'));
// Reload variables. // Reload variables.
...@@ -349,7 +353,7 @@ class ContactPersonalTestCase extends DrupalWebTestCase { ...@@ -349,7 +353,7 @@ class ContactPersonalTestCase extends DrupalWebTestCase {
$this->assertIdentical($num_records_flood, '0', t('Flood table emptied.')); $this->assertIdentical($num_records_flood, '0', t('Flood table emptied.'));
// Submit contact form with correct values and check flood interval. // Submit contact form with correct values and check flood interval.
for ($i = 0; $i < $flood_control; $i++) { for ($i = 0; $i < $flood_limit; $i++) {
$this->drupalGet('user/' . $web_user2->uid . '/contact'); $this->drupalGet('user/' . $web_user2->uid . '/contact');
$this->drupalPost(NULL, $edit, t('Send message')); $this->drupalPost(NULL, $edit, t('Send message'));
$this->assertText(t('Your message has been sent.'), t('Message sent.')); $this->assertText(t('Your message has been sent.'), t('Message sent.'));
...@@ -357,7 +361,7 @@ class ContactPersonalTestCase extends DrupalWebTestCase { ...@@ -357,7 +361,7 @@ class ContactPersonalTestCase extends DrupalWebTestCase {
// Submit contact form one over limit. // Submit contact form one over limit.
$this->drupalGet('user/' . $web_user2->uid . '/contact'); $this->drupalGet('user/' . $web_user2->uid . '/contact');
$this->assertRaw(t('You cannot send more than %number messages per hour. Please try again later.', array('%number' => $flood_control)), t('Message threshold reached.')); $this->assertRaw(t('You cannot send more than %number messages in @interval. Please try again later.', array('%number' => $flood_limit, '@interval' => format_interval(variable_get('contact_threshold_window', 3600)))), t('Message threshold reached.'));
$this->drupalLogout(); $this->drupalLogout();
...@@ -366,7 +370,7 @@ class ContactPersonalTestCase extends DrupalWebTestCase { ...@@ -366,7 +370,7 @@ class ContactPersonalTestCase extends DrupalWebTestCase {
// Disable the personal contact form. // Disable the personal contact form.
$edit = array(); $edit = array();
$edit['contact_default_status'] = FALSE; $edit['contact_default_status'] = FALSE;
$this->drupalPost('admin/structure/contact/settings', $edit, t('Save configuration')); $this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.')); $this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.'));
// Reload variables. // Reload variables.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment