When a form element of type options is submitted Drupal will insert a 'key' => 0 entry for options that are left unselected. The function oa_core_user_spaces_render() does not handle this correctly when reading $conf['types'].

In my case $conf['types'] contains the following values when only Spaces are selected:

array(
  'oa_space' => 'oa_space',
  'oa_group' => 0,
);

The loop foreach ($group_types as $type) { also loops over this zero value, invoking oa_core_get_groups_by_user_access() with $type = (int) 0.

This, in turn causes a cache polution because the result of oa_core_get_groups_by_user_access(..., $type = 0) is empty but the cache id $cid used in this function is exactly the same were the oa_core_get_groups_by_user_access() function called without $type parameter. As such, once oa_core_get_groups_by_user_access(..., $type = 0) is called, oa_core_get_groups_by_user_access() will return an empty result even when the user has spaces.

Steps to reproduce:

Requirements:

  • devel module
  • current user has one or more oa_space memberships
  1. Execute the following code in /devel/php: dpm(oa_core_get_groups_by_user_access());
  2. Notice that there are results.
  3. Clear the cache at /admin/config/development/performance
  4. Go to /spaces (this page contains the panel that contains the bug, the cache is now poluted)
  5. Execute the following code in /devel/php: dpm(oa_core_get_groups_by_user_access());
  6. Notice that there are no results.
CommentFileSizeAuthor
#2 2867021-oa_core-cachepolution-1.patch1.78 KBJorrit
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jorrit created an issue. See original summary.

Jorrit’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
1.78 KB

The attached patch does the following things:

  1. It fixes the bug outlined above by applying array_filter() to the options array, stripping the 0 value.
  2. It changes the input normalization in oa_core_get_groups_by_user_access() from isset() to !empty(), fixing any other situations where $type = 0.
  3. It moves the input normalization code to before the $cid initialization code. In this way, the same cache entry is used regardless if oa_core_get_groups_by_user_access() is called with NULL parameters or with their actual default values.

    For example, currently the following two invocations use different cache entries (with the same contents):

    oa_core_get_groups_by_user_access(NULL, FALSE, NULL, NULL, NULL, NULL);
    oa_core_get_groups_by_user_access(NULL, FALSE, NULL, NULL, NULL, OA_SPACE_TYPE);
    
mpotter’s picture

Status: Needs review » Fixed

Nice job tracking this down! I confirmed the issue and the fix(es) and committed this to 188c1db in oa_core. Thanks again for your help!

Jorrit’s picture

Thanks you!

Status: Fixed » Closed (fixed)

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