I have added a permission that allows administrators to access all forms even when in Read Only Mode.

I have also refactored the code against the current dev to reduce duplicate checks and keep all logic in one place. It's quite a refactor.

In addition to this, I have changed the behavior of the warnings. The two warnings are now displayed as warnings rather than as form fields. I think this makes more sense to the user and administrator. Additionally the warning do not get duplicated (which was a quick fix). I believe the warnings make sense since they are prominent on the page while replacing the form with a text message was confusing and not immediately obvious.

Furthermore, a warning is given to all users with the permission to access forms while in read only mode that informs them prominently that other users cannot access this content. I believe placing this on only the pages with forms is sufficient, but it could be a site wide warning for administrators and could even be a separate permission. I think we should think about the necessity of this message. For most uses, the administrators will know the site is in Read Only Mode since they put it there during emergencies or odd maintenance. For use cases that want to lock down content editing for non administrators, this message will show to a larger group of users who didn't initiate the read only mode but want to know that it's active. For example, the admin activates it and publishers can still add a page or two (during a small switchover window where they can save in progress work before a move) but know to stop creating new content.

The patch will be attached and has been tested by hand for the scenarios I could think of.

Comments

damontgomery’s picture

Here is the patch. It requires the quick patch here first, http://drupal.org/node/1882296#comment-6938610

BarisW’s picture

Thanks for the patch. I will apply it now and review it.

I'm not sure about adding a new permission, or if we can just use the already existing 'Access site in maintanance' permission from Drupal core. For now, I'll leave it like this but we might take it out in the future.

BarisW’s picture

Status: Needs review » Fixed

Thanks. Committed. I've only rewritten the check in _readonlymode_form_check(). It's a matter of taste and coding style, but I prefer the way it is now, easier to read than one long line with lots of checks.

Like this:

<?php
// If not in read-only mode, allow the form.
  if (!variable_get('site_readonly', FALSE)) {
    return TRUE;
  }

  // Admins can access all forms.
  if (user_access('readonlymode access forms')) {
    return TRUE;
  }

  // Is the form in the list of default forms? Then allow access.
  if (in_array($form_id, _readonlymode_default_forms_allowed())) {
    return TRUE;
  }

  // If the form in the list of read-only forms? Allow access.
  if (!$submitted && in_array($form_id, _readonlymode_default_forms_viewonly())) {
    return TRUE;
  }
?>

etc.

Thanks for all the hard work. I've added proper attribution, so the commits end up on your profile.

damontgomery’s picture

Status: Fixed » Closed (fixed)

Baris,

Thanks. I like the broken out checks as well and I think it's much more legible and maintainable.

The reasoning for the custom permission was that the two modes do slightly different things. One totally locks the site down and one partially locks it down. I could imagine a scenario where you need the extra one although it's not my scenario.

Editors can access the site in Read Only Mode (to prevent some sort of flood of new content / spam).
Admins can access in Maintenance mode but it's a super lock down that blocks even editors.

I think the permission also makes it super clear that this is something different and it's easy to find since it's labeled along with the module name.

petew’s picture

BarisW, interesting, that was exactly my approach in the original patch, I too prefer this more readable style. It changed here after it was reviewed internally, i'm glad you've gone with the clearer approach.