Changeset 9583 for extensions


Ignore:
Timestamp:
Mar 9, 2011, 2:06:10 PM (14 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

Location:
extensions/community
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • extensions/community/add_photos.php

    r9563 r9583  
    270270
    271271$create_subcategories = false;
    272 
    273 if ($user_permissions['create_whole_gallery'])
     272if ($user_permissions['create_whole_gallery'] or count($user_permissions['create_categories']) > 0)
    274273{
    275274  $create_subcategories = true;
    276275}
    277276
    278 if (count($user_permissions['create_categories']) > 0)
    279 {
    280   $create_subcategories = true;
    281   $category_ids = null;
    282  
    283   $query = '
     277$create_categories = $user_permissions['create_categories'];
     278if (count($user_permissions['create_categories']) == 0)
     279{
     280  $create_categories = array(-1);
     281}
     282
     283$query = '
    284284SELECT id,name,uppercats,global_rank
    285285  FROM '.CATEGORIES_TABLE.'
    286   WHERE id IN ('.implode(',', $user_permissions['create_categories']).')
    287 ;';
    288 
    289   display_select_cat_wrapper(
    290     $query,
    291     $selected_category,
    292     'category_parent_options'
    293     );
    294 }
     286  WHERE id IN ('.implode(',', $create_categories).')
     287;';
     288
     289display_select_cat_wrapper(
     290  $query,
     291  $selected_category,
     292  'category_parent_options'
     293  );
    295294
    296295$template->assign(
  • extensions/community/admin_permissions.php

    r9536 r9583  
    157157  }
    158158
    159   conf_update_param('community_update', time());
     159  community_update_cache_key();
    160160}
    161161
     
    175175  pwg_query($query);
    176176
    177   conf_update_param('community_update', time());
     177  community_update_cache_key();
    178178
    179179  $_SESSION['page_infos'] = array(l10n('Permission 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?>
  • extensions/community/main.inc.php

    r9563 r9583  
    127127  // photos" link in the gallery menu
    128128  $user_permissions = community_get_user_permissions($user['id']);
    129  
     129
    130130  if (count($user_permissions['upload_categories']) == 0 and !$user_permissions ['create_whole_gallery'])
    131131  {
     
    213213  community_reject_user_pendings($user_id);
    214214}
     215
     216add_event_handler('invalidate_user_cache', 'community_refresh_cache_update_time');
     217function community_refresh_cache_update_time()
     218{
     219  community_update_cache_key();
     220}
    215221?>
  • extensions/community/maintain.inc.php

    r9566 r9583  
    328328  mass_inserts($prefixeTable.'community_permissions', array_keys($insert), array($insert));
    329329
    330   conf_update_param('community_update', time());
     330  include_once(dirname(__FILE__).'/include/functions_community.inc.php');
     331  community_update_cache_key();
    331332}
    332333?>
Note: See TracChangeset for help on using the changeset viewer.