feature 731: permissions at image level

- this is the first version - I wait for feedback before changing help files

git-svn-id: http://piwigo.org/svn/trunk@2084 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2007-09-11 02:24:51 +00:00
parent 45fde2cc6b
commit 92f80e5d79
13 changed files with 275 additions and 51 deletions

View file

@ -89,7 +89,10 @@ SELECT id
INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON category_id = id
WHERE image_id = '.$_GET['id'].'
'.get_sql_condition_FandF(
array('forbidden_categories' => 'category_id'),
array(
'forbidden_categories' => 'category_id',
'forbidden_images' => 'image_id',
),
' AND'
).'
LIMIT 1

View file

@ -136,7 +136,7 @@ DELETE
$datas = array();
$dbfields = array('primary' => array('id'), 'update' => array());
$formfields = array('author', 'name', 'date_creation');
$formfields = array('author', 'name', 'date_creation', 'level');
foreach ($formfields as $formfield)
{
if ($_POST[$formfield.'_action'] != 'leave')
@ -163,7 +163,6 @@ SELECT id
if ('set' == $_POST['author_action'])
{
$data['author'] = $_POST['author'];
if ('' == $data['author'])
{
unset($data['author']);
@ -173,7 +172,6 @@ SELECT id
if ('set' == $_POST['name_action'])
{
$data['name'] = $_POST['name'];
if ('' == $data['name'])
{
unset($data['name']);
@ -189,6 +187,11 @@ SELECT id
;
}
if ('set' == $_POST['level_action'])
{
$data['level'] = $_POST['level'];
}
array_push($datas, $data);
}
// echo '<pre>'; print_r($datas); echo '</pre>';
@ -345,6 +348,18 @@ else
}
$template->assign_vars(array('DATE_CREATION_YEAR_VALUE'=>$year));
// image level options
$blockname = 'level_option';
foreach ($conf['available_permission_levels'] as $level)
{
$template->assign_block_vars(
$blockname,
array(
'VALUE' => $level,
'CONTENT' => l10n( sprintf('Level %d', $level) ),
));
}
// +-----------------------------------------------------------------------+
// | global mode thumbnails |
// +-----------------------------------------------------------------------+
@ -377,7 +392,7 @@ if (count($page['cat_elements_id']) > 0)
$template->assign_vars(array('NAV_BAR' => $nav_bar));
$query = '
SELECT id,path,tn_ext,file,filesize
SELECT id,path,tn_ext,file,filesize,level
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $page['cat_elements_id']).')
'.$conf['order_by'].'
@ -405,6 +420,16 @@ SELECT id,path,tn_ext,file,filesize
'TITLE' => get_thumbnail_title($row)
)
);
if ( $row['level']>0 )
{
$template->assign_block_vars('thumbnails.thumbnail.level',
array(
'LEVEL' => $row['level'],
'TITLE' => l10n( sprintf('Level %d', $row['level']) ),
)
);
}
}
}

View file

@ -97,7 +97,8 @@ SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
u.'.$conf['user_fields']['email'].' AS email,
ui.status,
ui.adviser,
ui.enabled_high
ui.enabled_high,
ui.level
FROM '.USERS_TABLE.' AS u
INNER JOIN '.USER_INFOS_TABLE.' AS ui
ON u.'.$conf['user_fields']['id'].' = ui.user_id
@ -351,7 +352,8 @@ DELETE FROM '.USER_GROUP_TABLE.'
$formfields =
array('nb_image_line', 'nb_line_page', 'template', 'language',
'recent_period', 'maxwidth', 'expand', 'show_nb_comments',
'show_nb_hits', 'maxheight', 'status', 'enabled_high');
'show_nb_hits', 'maxheight', 'status', 'enabled_high',
'level');
$true_false_fields = array('expand', 'show_nb_comments',
'show_nb_hits', 'enabled_high');
@ -756,6 +758,19 @@ foreach ($groups as $group_id => $group_name)
));
}
// user level options
$blockname = 'level_option';
foreach ($conf['available_permission_levels'] as $level)
{
$template->assign_block_vars(
$blockname,
array(
'VALUE' => $level,
'CONTENT' => l10n( sprintf('Level %d', $level) ),
'SELECTED' => $level==$default_user['level'] ? 'selected="selected"' : '',
));
}
// +-----------------------------------------------------------------------+
// | navigation bar |
// +-----------------------------------------------------------------------+
@ -818,6 +833,13 @@ foreach ($visible_user_list as $num => $local_user)
$checked = '';
}
$properties = array();
$properties[] =
(isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
? $lang['is_high_enabled'] : $lang['is_high_disabled'];
$properties[] = l10n( sprintf('Level %d', $local_user['level']) );
$template->assign_block_vars(
'user',
array(
@ -836,9 +858,8 @@ foreach ($visible_user_list as $num => $local_user)
? '<BR />['.l10n('adviser').']' : ''),
'EMAIL' => get_email_address_as_display_text($local_user['email']),
'GROUPS' => $groups_string,
'PROPERTIES' =>
(isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
? $lang['is_high_enabled'] : $lang['is_high_disabled']
'PROPERTIES' => implode( ',', $properties),
)
);
trigger_action('loc_assign_block_var_local_user_list', $local_user);

View file

@ -263,6 +263,9 @@ $conf['prefix_thumbnail'] = 'TN-';
// Administration>Identification>Users?
$conf['users_page'] = 20;
// image level permissions available in the admin interface
$conf['available_permission_levels'] = array(0,1,2,4,8);
// mail_options: only set it true if you have a send mail warning with
// "options" parameter missing on mail() function execution.
$conf['mail_options'] = false;

View file

@ -257,6 +257,22 @@ SELECT ui.*, uc.*
$userdata['forbidden_categories'] =
calculate_permissions($userdata['id'], $userdata['status']);
/* now we build the list of forbidden images (this list does not contain
images that are not in at least an authorized category)*/
$query = '
SELECT DISTINCT(id)
FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
WHERE category_id NOT IN ('.$userdata['forbidden_categories'].')
AND level>'.$userdata['level'];
$forbidden_ids = array_from_query($query, 'id');
if ( empty($forbidden_ids) )
{
array_push( $forbidden_ids, 0 );
}
$userdata['image_access_type'] = 'NOT IN'; //TODO maybe later
$userdata['image_access_list'] = implode(',',$forbidden_ids);
update_user_cache_categories($userdata);
// Set need update are done
@ -269,6 +285,7 @@ SELECT ui.*, uc.*
SELECT COUNT(DISTINCT(image_id)) as total
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id NOT IN ('.$userdata['forbidden_categories'].')
AND image_id '.$userdata['image_access_type'].' ('.$userdata['image_access_list'].')
;';
list($userdata['nb_total_images']) = mysql_fetch_array(pwg_query($query));
@ -281,10 +298,12 @@ DELETE FROM '.USER_CACHE_TABLE.'
$query = '
INSERT INTO '.USER_CACHE_TABLE.'
(user_id, need_update, forbidden_categories, nb_total_images)
(user_id, need_update, forbidden_categories, nb_total_images,
image_access_type, image_access_list)
VALUES
('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\',\''
.$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].')
.$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].',"'
.$userdata['image_access_type'].'","'.$userdata['image_access_list'].'")
;';
pwg_query($query);
}
@ -527,26 +546,20 @@ function get_computed_categories($userdata, $filter_days=null)
$group_by = '';
$query = 'SELECT c.id cat_id, global_rank';
if ( !isset($filter_days) )
{
$query .= ',
date_last cat_date_last,
nb_images cat_nb_images
FROM '.CATEGORIES_TABLE.' as c';
}
else
{
// Count by date_available to avoid count null
$query .= ',
MAX(date_available) cat_date_last,
COUNT(date_available) cat_nb_images
FROM '.CATEGORIES_TABLE.' as c
MAX(date_available) cat_date_last, COUNT(date_available) cat_nb_images
FROM '.CATEGORIES_TABLE.' as c
LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id
LEFT JOIN '.IMAGES_TABLE.' AS i
ON ic.image_id = i.id AND
i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$filter_days.' DAY)';
$group_by = 'c.id';
ON ic.image_id = i.id
AND i.level<='.$userdata['level'];
if ( isset($filter_days) )
{
$query .= ' AND i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$filter_days.' DAY)';
}
$group_by = 'c.id';
if ( !empty($userdata['forbidden_categories']) )
{
@ -839,9 +852,11 @@ function create_user_infos($arg_id, $override_values = null)
foreach ($user_ids as $user_id)
{
$level= isset($default_user['level']) ? $default_user['level'] : 0;
if ($user_id == $conf['webmaster_id'])
{
$status = 'webmaster';
$level = max( $conf['available_permission_levels'] );
}
else if (($user_id == $conf['guest_id']) or
($user_id == $conf['default_user_id']))
@ -858,7 +873,8 @@ function create_user_infos($arg_id, $override_values = null)
array(
'user_id' => $user_id,
'status' => $status,
'registration_date' => $dbnow
'registration_date' => $dbnow,
'level' => $level
));
array_push($inserts, $insert);
@ -1290,14 +1306,38 @@ function get_sql_condition_FandF(
break;
}
case 'visible_images':
{
if (!empty($filter['visible_images']))
{
$sql_list[] =
$field_name.' IN ('.$filter['visible_images'].')';
}
break;
// note there is no break - visible include forbidden
case 'forbidden_images':
if (
!empty($user['image_access_list'])
or $user['image_access_type']!='NOT IN'
)
{
$table_prefix=null;
if ($field_name=='id')
{
$table_prefix = '';
}
elseif ($field_name=='i.id')
{
$table_prefix = 'i.';
}
if ( isset($table_prefix) )
{
$sql_list[]=$table_prefix.'level<='.$user['level'];
}
else
{
$sql_list[]=$field_name.' '.$user['image_access_type']
.' ('.$user['image_access_list'].')';
}
}
break;
default:
{
die('Unknow condition');

View file

@ -0,0 +1,76 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | file : $Id$
// | last update : $Date$
// | last modifier : $Author$
// | revision : $Revision$
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH'))
{
die('Hacking attempt!');
}
$upgrade_description = 'Add #user_infos.level, #images.level and #user_cache.forbidden_images';
include_once(PHPWG_ROOT_PATH.'include/constants.php');
// +-----------------------------------------------------------------------+
// | Upgrade content |
// +-----------------------------------------------------------------------+
$query = '
ALTER TABLE '.IMAGES_TABLE.' ADD COLUMN level TINYINT UNSIGNED NOT NULL DEFAULT 0
';
pwg_query($query);
$query = '
ALTER TABLE '.USER_INFOS_TABLE.' ADD COLUMN level TINYINT UNSIGNED NOT NULL DEFAULT 0
';
pwg_query($query);
$query = '
ALTER TABLE '.USER_CACHE_TABLE.' ADD COLUMN image_access_type enum("NOT IN","IN") NOT NULL default "NOT IN"
';
pwg_query($query);
$query = '
ALTER TABLE '.USER_CACHE_TABLE.' ADD COLUMN image_access_list TEXT DEFAULT NULL
';
pwg_query($query);
$query = '
UPDATE '.USER_INFOS_TABLE.' SET level=8 WHERE status="webmaster"
';
pwg_query($query);
$query = '
UPDATE '.USER_CACHE_TABLE.' SET need_update=true
';
pwg_query($query);
echo
"\n"
.'"'.$upgrade_description.'"'.' ended'
."\n"
;
?>

View file

@ -198,6 +198,7 @@ CREATE TABLE `phpwebgallery_images` (
`path` varchar(255) NOT NULL default '',
`storage_category_id` smallint(5) unsigned default NULL,
`high_filesize` mediumint(9) unsigned default NULL,
`level` tinyint unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `images_i2` (`date_available`),
KEY `images_i3` (`average_rate`),
@ -328,6 +329,8 @@ CREATE TABLE `phpwebgallery_user_cache` (
`need_update` enum('true','false') NOT NULL default 'true',
`forbidden_categories` text,
`nb_total_images` mediumint(8) unsigned default NULL,
`image_access_type` enum('NOT IN','IN') NOT NULL default 'NOT IN',
`image_access_list` text default NULL,
PRIMARY KEY (`user_id`)
) TYPE=MyISAM;
@ -389,6 +392,7 @@ CREATE TABLE `phpwebgallery_user_infos` (
`template` varchar(255) NOT NULL default 'yoga/clear',
`registration_date` datetime NOT NULL default '0000-00-00 00:00:00',
`enabled_high` enum('true','false') NOT NULL default 'true',
`level` tinyint unsigned NOT NULL default '0',
UNIQUE KEY `user_infos_ui1` (`user_id`)
) TYPE=MyISAM;

View file

@ -641,4 +641,11 @@ $lang['display_thumbnail_classic'] = 'Classic display';
$lang['display_thumbnail_hoverbox'] = 'Hoverbox display';
$lang['Thumbnails'] = 'Thumbnails';
$lang['obligatory_user_mail_address'] = 'Mail address is obligatory for all users';
$lang['Minimum privacy level'] = 'Minimum privacy level';
$lang['Privacy level'] = 'Privacy level';
$lang['Level 0'] = 'Public';
$lang['Level 1'] = 'Contacts';
$lang['Level 2'] = 'Friends';
$lang['Level 4'] = 'Family';
$lang['Level 8'] = 'Admins';
?>

View file

@ -642,4 +642,11 @@ $lang['display_thumbnail_classic'] = 'Affichage classique';
$lang['display_thumbnail_hoverbox'] = 'Affichage lors du survol';
$lang['Thumbnails'] = 'Miniatures';
$lang['obligatory_user_mail_address'] = 'L\'adresse mail est obligatoire pour tous les utilisateurs';
$lang['Minimum privacy level'] = 'Niveau minimal de confidentialité';
$lang['Privacy level'] = 'Niveau de confidentialité';
$lang['Level 0'] = 'Public';
$lang['Level 1'] = 'Contacts';
$lang['Level 2'] = 'Amis';
$lang['Level 4'] = 'Famille';
$lang['Level 8'] = 'Admins';
?>

View file

@ -34,7 +34,11 @@
<!-- BEGIN thumbnail -->
<li><span class="wrap1">
<label>
<span class="wrap2"><span>
<span class="wrap2">
<!-- BEGIN level -->
<em class="levelIndicatorB">{thumbnails.thumbnail.level.LEVEL}</em><em class="levelIndicatorF" title="{thumbnails.thumbnail.level.TITLE}">{thumbnails.thumbnail.level.LEVEL}</em>
<!-- END level -->
<span>
<img src="{thumbnails.thumbnail.SRC}"
alt="{thumbnails.thumbnail.ALT}"
title="{thumbnails.thumbnail.TITLE}"
@ -133,6 +137,19 @@
</td>
</tr>
<tr>
<td>{lang:Minimum privacy level}</td>
<td>
<label><input type="radio" name="level_action" value="leave" checked="checked" />{lang:leave}</label>
<label><input type="radio" name="level_action" value="set" id="level_action_set" />{lang:set to}</label>
<select onmousedown="document.getElementById('level_action_set').checked = true;" name="level" size="1">
<!-- BEGIN level_option -->
<option {level_option.SELECTED} value="{level_option.VALUE}">{level_option.CONTENT} ({level_option.VALUE})</option>
<!-- END level_option -->
</select>
</td>
</tr>
</table>
<p>

View file

@ -190,6 +190,19 @@
</td>
</tr>
<tr>
<td>{lang:Privacy level}</td>
<td>
<label><input type="radio" name="level_action" value="leave" checked="checked" />{lang:leave}</label>
<label><input type="radio" name="level_action" value="set" id="level_action_set" />{lang:set to}</label>
<select onmousedown="document.getElementById('level_action_set').checked = true;" name="level" size="1">
<!-- BEGIN level_option -->
<option {level_option.SELECTED} value="{level_option.VALUE}">{level_option.CONTENT} ({level_option.VALUE})</option>
<!-- END level_option -->
</select>
</td>
</tr>
</table>
</fieldset>

View file

@ -47,6 +47,7 @@
#menubar UL UL {
font-size: 100%;
margin-top: 0;
margin-bottom: 0;
}
#menubar LI.selected A {

View file

@ -51,3 +51,10 @@
top: 2px;
}
UL.thumbnails .levelIndicatorB {
display:block; position:absolute; z-index:100;padding:0px 0 0 14px; color:black; font-weight:bold; fontsize:120%;
}
UL.thumbnails .levelIndicatorF {
display:block; position:absolute; z-index:101;padding:1px 0 0 15px; color:white; font-weight:bold; fontsize:120%;
}