summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-22 18:24:14 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-22 18:24:14 +0000
commita9762cd3bf93ac8bbcafec23328c3ecde9d1498a (patch)
tree4a7abe998616a563a6471b3ac8915a943fcdeaa1 /modules
parent4cbe60a533acc3d30da5ddd68f932d79982eeeff (diff)
downloadbrdo-a9762cd3bf93ac8bbcafec23328c3ecde9d1498a.tar.gz
brdo-a9762cd3bf93ac8bbcafec23328c3ecde9d1498a.tar.bz2
#201415 by sun: Add a permission to access site in maintenance mode.
Diffstat (limited to 'modules')
-rw-r--r--modules/system/system.admin.inc15
-rw-r--r--modules/system/system.install27
-rw-r--r--modules/system/system.module4
-rw-r--r--modules/system/system.test86
4 files changed, 123 insertions, 9 deletions
diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc
index 9bd326ff2..c99d9ee28 100644
--- a/modules/system/system.admin.inc
+++ b/modules/system/system.admin.inc
@@ -1808,18 +1808,15 @@ function system_date_time_lookup() {
* @see system_settings_form()
*/
function system_site_maintenance_mode() {
-
- $form['site_offline'] = array(
- '#type' => 'radios',
- '#title' => t('Site status'),
+ $form['maintenance_mode'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Put site into maintenance mode'),
'#default_value' => 0,
- '#options' => array(t('Online'), t('Offline')),
- '#description' => t('When set to "Online", all visitors will be able to browse your site normally. When set to "Offline", only users with the "administer site configuration" permission will be able to access your site to perform maintenance; all other visitors will see the site offline message configured below. Authorized users can log in during "Offline" mode directly via the <a href="@user-login">user login</a> page.', array('@user-login' => url('user'))),
+ '#description' => t('When enabled, only users with the "Access site in maintenance mode" <a href="@permissions-url">permission</a> are able to access your site to perform maintenance; all other visitors see the maintenance mode message configured below. Authorized users can log in directly via the <a href="@user-login">user login</a> page.', array('@permissions-url' => url('admin/config/people/permissions'), '@user-login' => url('user'))),
);
-
- $form['site_offline_message'] = array(
+ $form['maintenance_mode_message'] = array(
'#type' => 'textarea',
- '#title' => t('Site offline message'),
+ '#title' => t('Maintenance mode message'),
'#default_value' => t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal'))),
'#description' => t('Message to show visitors when the site is in maintenance mode.')
);
diff --git a/modules/system/system.install b/modules/system/system.install
index 5c8cf20b9..d8c2e5e65 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -2429,6 +2429,33 @@ function system_update_7035() {
}
/**
+ * Split the 'access site in maintenance mode' permission from 'administer site configuration'.
+ */
+function system_update_7036() {
+ $ret = array();
+ // Get existing roles that can 'administer site configuration'.
+ $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer site configuration'))->fetchCol();
+ // None found.
+ if (empty($rids)) {
+ return $ret;
+ }
+ $insert = db_insert('role_permission')->fields(array('rid', 'permission'));
+ foreach ($rids as $rid) {
+ $insert->values(array(
+ 'rid' => $rid,
+ 'permission' => 'access site in maintenance mode',
+ ));
+ }
+ $insert->execute();
+
+ // Remove obsolete variable 'site_offline_message'.
+ // @see update_fix_d7_requirements().
+ variable_del('site_offline_message');
+
+ return $ret;
+}
+
+/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.
*/
diff --git a/modules/system/system.module b/modules/system/system.module
index e768944e3..01a6f82a4 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -228,6 +228,10 @@ function system_permission() {
'title' => t('Access administration pages'),
'description' => t('View the administration panel and browse the help system.'),
),
+ 'access site in maintenance mode' => array(
+ 'title' => t('Access site in maintenance mode'),
+ 'description' => t('Log in when the site is in maintenance mode.'),
+ ),
'access site reports' => array(
'title' => t('Access site reports'),
'description' => t('View reports from system logs and other status information.'),
diff --git a/modules/system/system.test b/modules/system/system.test
index 92d0e32dc..fe2ab3949 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -648,6 +648,92 @@ class PageNotFoundTestCase extends DrupalWebTestCase {
}
/**
+ * Tests site maintenance functionality.
+ */
+class SiteMaintenanceTestCase extends DrupalWebTestCase {
+ protected $admin_user;
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Site maintenance mode functionality',
+ 'description' => 'Test access to site while in maintenance mode.',
+ 'group' => 'System',
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+
+ // Create a user allowed to access site in maintenance mode.
+ $this->user = $this->drupalCreateUser(array('access site in maintenance mode'));
+ // Create an administrative user.
+ $this->admin_user = $this->drupalCreateUser(array('administer site configuration', 'access site in maintenance mode'));
+ $this->drupalLogin($this->admin_user);
+ }
+
+ /**
+ * Verify site maintenance mode functionality.
+ */
+ function testSiteMaintenance() {
+ // Turn on maintenance mode.
+ $edit = array(
+ 'maintenance_mode' => 1,
+ );
+ $this->drupalPost('admin/config/development/maintenance', $edit, t('Save configuration'));
+
+ $admin_message = t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => url('admin/config/development/maintenance')));
+ $user_message = t('Operating in maintenance mode.');
+ $offline_message = t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')));
+
+ $this->drupalGet('');
+ $this->assertRaw($admin_message, t('Found the site maintenance mode message.'));
+
+ // Logout and verify that offline message is displayed.
+ $this->drupalLogout();
+ $this->drupalGet('');
+ $this->assertText($offline_message);
+ $this->drupalGet('node');
+ $this->assertText($offline_message);
+ $this->drupalGet('user/register');
+ $this->assertText($offline_message);
+ $this->drupalGet('user/password');
+ $this->assertText($offline_message);
+
+ // Verify that user is able to log in.
+ $this->drupalGet('user');
+ $this->assertNoText($offline_message);
+ $this->drupalGet('user/login');
+ $this->assertNoText($offline_message);
+
+ // Log in user and verify that maintenance mode message is displayed
+ // directly after login.
+ $edit = array(
+ 'name' => $this->user->name,
+ 'pass' => $this->user->pass_raw,
+ );
+ $this->drupalPost(NULL, $edit, t('Log in'));
+ $this->assertText($user_message);
+
+ // Log in administrative user and configure a custom site offline message.
+ $this->drupalLogout();
+ $this->drupalLogin($this->admin_user);
+ $this->drupalGet('admin/config/development/maintenance');
+ $this->assertNoRaw($admin_message, t('Site maintenance mode message not displayed.'));
+
+ $offline_message = 'Sorry, not online.';
+ $edit = array(
+ 'maintenance_mode_message' => $offline_message,
+ );
+ $this->drupalPost(NULL, $edit, t('Save configuration'));
+
+ // Logout and verify that custom site offline message is displayed.
+ $this->drupalLogout();
+ $this->drupalGet('');
+ $this->assertRaw($offline_message, t('Found the site offline message.'));
+ }
+}
+
+/**
* Tests generic date and time handling capabilities of Drupal.
*/
class DateTimeFunctionalTest extends DrupalWebTestCase {