Changeset 11728


Ignore:
Timestamp:
Jul 13, 2011, 3:32:23 PM (10 years ago)
Author:
plg
Message:

merge r11727 from branch 2.2 to trunk

feature 2245: when a new private album is added, the creator and admins
automatically get permission on it.

Location:
trunk/admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r11487 r11728  
    12731273function create_virtual_category($category_name, $parent_id=null)
    12741274{
    1275   global $conf;
     1275  global $conf, $user;
    12761276
    12771277  // is the given category name only containing blank spaces ?
     
    13611361;';
    13621362  pwg_query($query);
     1363
     1364  if ('private' == $insert['status'])
     1365  {
     1366    add_permission_on_category($inserted_id, array_unique(array_merge(get_admins(), array($user['id']))));
     1367  }
    13631368
    13641369  return array(
     
    21842189}
    21852190
     2191function add_permission_on_category($category_ids, $user_ids)
     2192{
     2193  // array-ify categories and users
     2194  if (!is_array($category_ids))
     2195  {
     2196    $category_ids = array($category_ids);
     2197  }
     2198
     2199  if (!is_array($user_ids))
     2200  {
     2201    $user_ids = array($user_ids);
     2202  }
     2203
     2204  // check for emptiness
     2205  if (count($category_ids) == 0 or count($user_ids) == 0)
     2206  {
     2207    return;
     2208  }
     2209 
     2210  // make sure categories are private and select uppercats
     2211  $query = '
     2212SELECT
     2213    id
     2214  FROM '.CATEGORIES_TABLE.'
     2215  WHERE id IN ('.implode(',', get_uppercat_ids($category_ids)).')
     2216    AND status = \'private\'
     2217;';
     2218  $private_uppercats = array_from_query($query, 'id');
     2219
     2220  if (count($private_uppercats) == 0)
     2221  {
     2222    return;
     2223  }
     2224 
     2225  // We must not reinsert already existing lines in user_access table
     2226  $granteds = array();
     2227  foreach ($private_uppercats as $cat_id)
     2228  {
     2229    $granteds[$cat_id] = array();
     2230  }
     2231 
     2232  $query = '
     2233SELECT
     2234    user_id,
     2235    cat_id
     2236  FROM '.USER_ACCESS_TABLE.'
     2237  WHERE cat_id IN ('.implode(',', $private_uppercats).')
     2238    AND user_id IN ('.implode(',', $user_ids).')
     2239;';
     2240  $result = pwg_query($query);
     2241  while ($row = pwg_db_fetch_assoc($result))
     2242  {
     2243    array_push($granteds[$row['cat_id']], $row['user_id']);
     2244  }
     2245
     2246  $inserts = array();
     2247 
     2248  foreach ($private_uppercats as $cat_id)
     2249  {
     2250    $grant_to_users = array_diff($user_ids, $granteds[$cat_id]);
     2251   
     2252    foreach ($grant_to_users as $user_id)
     2253    {
     2254      array_push(
     2255        $inserts,
     2256        array(
     2257          'user_id' => $user_id,
     2258          'cat_id' => $cat_id
     2259          )
     2260        );
     2261    }
     2262  }
     2263
     2264  if (count($inserts) > 0)
     2265  {
     2266    mass_inserts(USER_ACCESS_TABLE, array_keys($inserts[0]), $inserts);
     2267  }
     2268}
     2269
     2270
     2271function get_admins($include_webmaster=true)
     2272{
     2273  $status_list = array('admin');
     2274
     2275  if ($include_webmaster)
     2276  {
     2277    $status_list[] = 'webmaster';
     2278  }
     2279 
     2280  $query = '
     2281SELECT
     2282    user_id
     2283  FROM '.USER_INFOS_TABLE.'
     2284  WHERE status in (\''.implode("','", $status_list).'\')
     2285;';
     2286
     2287  return array_from_query($query, 'user_id');
     2288}
    21862289?>
  • trunk/admin/site_update.php

    r11041 r11728  
    315315    }
    316316
     317    // add default permissions to categories
     318    $category_ids = array();
     319    foreach ($inserts as $category)
     320    {
     321      $category_ids[] = $category['id'];
     322    }
     323    add_permission_on_category($category_ids, get_admins());
     324
    317325    $counts['new_categories'] = count($inserts);
    318326  }
Note: See TracChangeset for help on using the changeset viewer.