I had a problem today where anonymous users always were served a webform even if the form total limit had been exceeded. I use cacheexclude module to exclude my webform node pages from being cached. Normal druapl cache is enabled.

I tracked it down to webform.module

$cached = $user->uid == 0 && (variable_get('cache', 0) || drupal_page_is_cacheable() === FALSE); 

If global drupal cache is enabled it always return $cached = TRUE. And if $cached = TRUE it doesn't disabled the webform when total limit have exceeded.

Why do we need to check both variable_get('cache', 0) and drupal_page_is_cacheable === FALSE?

Shouldn't the correct var definition be something like this. To check that page is cacheable.

$cached = $user->uid == 0 && (drupal_page_is_cacheable() === TRUE);

Or maybe I'm missing something?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Thanks for opening this report. There's definitely something weird going on here.

What's *supposed* to happen in Webform is the following:

- When the page cache is enabled, Webform should show the form to anonymous users even if they have exceeded the *per-user* submission limit. This is to prevent the page from getting cached with the form not shown.
- When the page cache is enabled, Webform show *not* show the form to anonymous users if the *total* form limit has been reached.

Now, when the page cache is not enabled, it's supposed to treat anonymous users identical to logged-in users, hiding or showing the form based on both the per-user and total limit immediately.

I think that your adjustment to the code is probably the correct thing to do for that line, since it's supposed to just determine if the page is cacheable at all. However, we can really simplify it all the way down to just this:

$cached = drupal_page_is_cacheable();

There's code later in the webform_node_view() function that still isn't going to behave as desired:

    // 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) {
      $enabled = FALSE;
    }

I think that the !$cached check should just be removed here, since if the entire form limit has been reached, it's supposed to hide the form entirely.

DanChadwick’s picture

Version: 7.x-3.x-dev » 8.x-4.x-dev
Status: Active » Fixed
FileSize
2.24 KB

I tested quicksketch's changes and they seem correct. The $cached is still passed to the message theme function, which is then used to prevent one user's messages from being cached.

Committed to 7.x-4.x and 8.x

  • DanChadwick committed 8603e9d on 7.x-4.x
    Issue #2194337 by quicksketch: Fixed Anonymous users always have $cached...
  • DanChadwick committed 95c3392 on 8.x-4.x
    Issue #2194337 by quicksketch: Fixed Anonymous users always have $cached...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

DanChadwick’s picture

Version: 8.x-4.x-dev » 7.x-4.x-dev