From 8603e9d0d6bc4689a28abae9ab5f24ad8f458494 Mon Sep 17 00:00:00 2001
From: Dan Chadwick <dan899@gmail.com>
Date: Sun, 16 Nov 2014 14:06:35 -0500
Subject: [PATCH] Issue #2194337 by quicksketch: Fixed Anonymous users always
 have $cached enabled even if drupal_page_is_cacheable is
 FALSE.

---
 webform.module |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/webform.module b/webform.module
index ffd95df..bcf9179 100644
--- a/webform.module
+++ b/webform.module
@@ -1879,13 +1879,15 @@ function webform_node_view($node, $view_mode) {
   }
 
   // Check if this page is cached or not.
-  $cached = $user->uid == 0 && (variable_get('cache', 0) || drupal_page_is_cacheable() === FALSE);
+  $cached = drupal_page_is_cacheable();
 
-  // Check if the user can add another submission.
+  // Check if the user can add another submission based on the individual submission limit.
   if ($node->webform['submit_limit'] != -1) { // -1: Submissions are never throttled.
     module_load_include('inc', 'webform', 'includes/webform.submissions');
 
-    // Disable the form if the limit is exceeded and page cache is not active.
+    // Disable the form if the limit is exceeded and page cache is not active. This prevent
+    // One anonymous user from generated a disabled webform page for the cache, which would
+    // be shown to other anonymous users who have not exceeded the limit.
     if (($user_limit_exceeded = webform_submission_user_limit_check($node)) && !$cached) {
       $enabled = FALSE;
     }
@@ -1896,8 +1898,10 @@ function webform_node_view($node, $view_mode) {
   if ($node->webform['total_submit_limit'] != -1) { // -1: Submissions are never throttled.
     module_load_include('inc', 'webform', 'includes/webform.submissions');
 
-    // Disable the form if the limit is exceeded and page cache is not active.
-    if (($total_limit_exceeded = webform_submission_total_limit_check($node)) && !$cached) {
+    // Disable the form if the limit is exceeded. The cache is irrelevant for the total
+    // submission limit; when it is exceeded for one user, it is exceeded for any other
+    // user.
+    if (($total_limit_exceeded = webform_submission_total_limit_check($node))) {
       $enabled = FALSE;
     }
   }
-- 
1.7.8.msysgit.0

