Ignore:
Timestamp:
Mar 9, 2011, 2:06:10 PM (13 years ago)
Author:
plg
Message:

bug fixed: invalidate_user_cache now also invalidates community user
permissions cache

bug fixed: community permissions cache was not refreshed when user connects,
I have added $_SESSIONcommunity_user_id to make sure the permissions are
related to the correct user

change: use a random key for cache update to avoid "in the same second
refresh".

filter the list of parent albums for "create a new album" based on permissions
even when create_whole_gallery is true

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/community/include/functions_community.inc.php

    r9501 r9583  
    2626  global $conf, $user;
    2727
    28   if (!isset($conf['community_update']))
    29   {
    30     conf_update_param('community_update', time());
    31   }
    32  
    33   if (isset($_SESSION['community_user_permissions']))
    34   {
    35     if ($_SESSION['community_update'] > $conf['community_update'])
    36     {
    37       return $_SESSION['community_user_permissions'];
    38     }
     28  $cache_key = community_get_cache_key();
     29  if (!isset($cache_key))
     30  {
     31    $cache_key = community_update_cache_key();
     32  }
     33
     34  // I (plg) don't understand why, but when you connect, you keep the
     35  // permissions calculated for the "guest" : the session is "inheritated"
     36  // from guest to the connected user, so I add a
     37  // $_SESSION['community_user_id'] to force refresh if the permissions were
     38  // not calculated for the right user
     39  if (
     40    isset($_SESSION['community_user_id'])
     41    and $_SESSION['community_user_id'] == $user_id
     42    and $_SESSION['community_cache_key'] == $cache_key
     43    )
     44  {
     45    return $_SESSION['community_user_permissions'];
    3946  }
    4047
     
    199206
    200207  $_SESSION['community_user_permissions'] = $return;
    201   $_SESSION['community_update'] = time();
     208  $_SESSION['community_cache_key'] = $cache_key;
     209  $_SESSION['community_user_id'] = $user_id;
    202210
    203211  return $_SESSION['community_user_permissions'];
     
    242250}
    243251
     252function community_update_cache_key()
     253{
     254  $cache_key = generate_key(20);
     255  conf_update_param('community_cache_key', $cache_key);
     256  return $cache_key;
     257}
     258
     259function community_get_cache_key()
     260{
     261  global $conf;
     262
     263  if (isset($conf['community_cache_key']))
     264  {
     265    return $conf['community_cache_key'];
     266  }
     267  else
     268  {
     269    return null;
     270  }
     271}
    244272?>
Note: See TracChangeset for help on using the changeset viewer.