1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-06 11:59:56 +02:00

Personal information visibility (Fix #81)

This commit is contained in:
SUTJael 2013-12-26 12:47:06 +01:00
parent 1bbeee0ef4
commit 9edffd6fb8
6 changed files with 154 additions and 57 deletions

View file

@ -27,7 +27,7 @@
* This handles all of the preference stuff for Ampache * This handles all of the preference stuff for Ampache
* *
*/ */
class Preference class Preference extends database_object
{ {
/** /**
* __constructor * __constructor
@ -39,6 +39,32 @@ class Preference
} // __construct } // __construct
/**
* get_by_user
* Return a preference for specific user identifier
*/
public static function get_by_user($user_id, $pref_name)
{
//debug_event('preference.class.php', 'Getting preference {'.$pref_name.'} for user identifier {'.$user_id.'}...', '5');
$user_id = Dba::escape($user_id);
$pref_name = Dba::escape($pref_name);
$id = self::id_from_name($pref_name);
if (parent::is_cached('get_by_user', $user_id)) {
return parent::get_from_cache('get_by_user', $user_id);
}
$sql = "SELECT `value` FROM `user_preference` WHERE `preference`='$id' AND `user`='$user_id'";
$db_results = Dba::read($sql);
$data = Dba::fetch_assoc($db_results);
parent::add_to_cache('get_by_user', $user_id, $data['value']);
return $data['value'];
} // get_by_user
/** /**
* update * update
* This updates a single preference from the given name or id * This updates a single preference from the given name or id
@ -63,13 +89,15 @@ class Preference
if (self::has_access($name)) { if (self::has_access($name)) {
$value = Dba::escape($value); $value = Dba::escape($value);
$user_id = Dba::escape($user_id); $user_id = Dba::escape($user_id);
$sql = "UPDATE `user_preference` SET `value`='$value' " . $sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$id'$user_check";
"WHERE `preference`='$id'$user_check";
$db_results = Dba::write($sql); $db_results = Dba::write($sql);
Preference::clear_from_session(); Preference::clear_from_session();
parent::remove_from_cache('get_by_user', user_id);
return true; return true;
} else { } else {
debug_event('denied',$GLOBALS['user']->username . ' attempted to update ' . $name . ' but does not have sufficient permissions','3'); debug_event('denied', $GLOBALS['user']->username . ' attempted to update ' . $name . ' but does not have sufficient permissions','3');
} }
return false; return false;
@ -110,6 +138,8 @@ class Preference
$sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$preference_id'"; $sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$preference_id'";
$db_results = Dba::write($sql); $db_results = Dba::write($sql);
parent::clear_cache();
return true; return true;
} // update_all } // update_all
@ -161,11 +191,16 @@ class Preference
{ {
$name = Dba::escape($name); $name = Dba::escape($name);
if (parent::is_cached('id_from_name', $name)) {
return parent::get_from_cache('id_from_name', $name);
}
$sql = "SELECT `id` FROM `preference` WHERE `name`='$name'"; $sql = "SELECT `id` FROM `preference` WHERE `name`='$name'";
$db_results = Dba::read($sql); $db_results = Dba::read($sql);
$row = Dba::fetch_assoc($db_results); $row = Dba::fetch_assoc($db_results);
parent::add_to_cache('id_from_name', $name, $row['id']);
return $row['id']; return $row['id'];
} // id_from_name } // id_from_name
@ -226,8 +261,8 @@ class Preference
" INNER JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` " . " INNER JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` " .
" WHERE `user_preference`.`user`='$user_id' AND `preference`.`catagory` != 'internal' $user_limit " . " WHERE `user_preference`.`user`='$user_id' AND `preference`.`catagory` != 'internal' $user_limit " .
" ORDER BY `preference`.`description`"; " ORDER BY `preference`.`description`";
$db_results = Dba::read($sql);
$db_results = Dba::read($sql);
$results = array(); $results = array();
while ($row = Dba::fetch_assoc($db_results)) { while ($row = Dba::fetch_assoc($db_results)) {
@ -241,7 +276,7 @@ class Preference
/** /**
* insert * insert
* This inserts a new preference into the preference table * This inserts a new preference into the preference table
* it does NOT sync up the users, that should be done independtly * it does NOT sync up the users, that should be done independently
*/ */
public static function insert($name,$description,$default,$level,$type,$catagory) public static function insert($name,$description,$default,$level,$type,$catagory)
{ {

View file

@ -1020,7 +1020,7 @@ class Song extends database_object implements media
} }
else if (!Access::check('interface','100')) { else if (!Access::check('interface','100')) {
// If user identifier is empty, we need to retrieve only users which have allowed view of personnal info // If user identifier is empty, we need to retrieve only users which have allowed view of personnal info
$personal_info_id = Preference::id_from_name('allow_personal_info'); $personal_info_id = Preference::id_from_name('allow_personal_info_recent');
if ($personal_info_id) { if ($personal_info_id) {
$current_user = $GLOBALS['user']->id; $current_user = $GLOBALS['user']->id;
$sql .= "AND `user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='$personal_info_id' AND `value`='1') OR `user`='$current_user') "; $sql .= "AND `user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='$personal_info_id' AND `value`='1') OR `user`='$current_user') ";

View file

@ -228,7 +228,7 @@ class Stream
if (!Access::check('interface','100')) { if (!Access::check('interface','100')) {
// We need to check only for users which have allowed view of personnal info // We need to check only for users which have allowed view of personnal info
$personal_info_id = Preference::id_from_name('allow_personal_info'); $personal_info_id = Preference::id_from_name('allow_personal_info_now');
if ($personal_info_id) { if ($personal_info_id) {
$current_user = $GLOBALS['user']->id; $current_user = $GLOBALS['user']->id;
$sql .= "WHERE (`now_playing`.`user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='$personal_info_id' AND `value`='1') OR `user`='$current_user')) "; $sql .= "WHERE (`now_playing`.`user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='$personal_info_id' AND `value`='1') OR `user`='$current_user')) ";

View file

@ -329,6 +329,11 @@ class Update
$update_string = '- Add option to allow/disallow to show personnal information to other users (now playing and recently played).<br />'; $update_string = '- Add option to allow/disallow to show personnal information to other users (now playing and recently played).<br />';
$version[] = array('version' => '360027','description' => $update_string); $version[] = array('version' => '360027','description' => $update_string);
$update_string = '- Personnal information: allow/disallow to show in now playing.<br />'.
'- Personnal information: allow/disallow to show in recently played.<br />'.
'- Personnal information: allow/disallow to show time and/or agent in recently played.<br />';
$version[] = array('version' => '360028','description' => $update_string);
return $version; return $version;
} }
@ -1814,7 +1819,7 @@ class Update
/** /**
* update_360027 * update_360027
* *
* This inserts the Album default sort preference... * Personal information: allow/disallow to show my personal information into now playing and recently played lists.
*/ */
public static function update_360027() public static function update_360027()
{ {
@ -1829,4 +1834,44 @@ class Update
return true; return true;
} }
/**
* update_360028
*
* Personal information: allow/disallow to show in now playing.
* Personal information: allow/disallow to show in recently played.
* Personal information: allow/disallow to show time and/or agent in recently played.
*/
public static function update_360028()
{
// Update previous update preference
$sql = "UPDATE `preference` SET `name`='allow_personal_info_now', `description`='Personal information visibility - Now playing' WHERE `name`='allow_personal_info'";
Dba::write($sql);
// Insert new recently played preference
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('allow_personal_info_recent','1','Personal information visibility - Recently played',25,'boolean','interface')";
Dba::write($sql);
$id = Dba::insert_id();
$sql = "INSERT INTO `user_preference` VALUES (-1,?,'1')";
Dba::write($sql, array($id));
// Insert streaming time preference
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('allow_personal_info_time','1','Personal information visibility - Recently played - Allow to show streaming date/time',25,'boolean','interface')";
Dba::write($sql);
$id = Dba::insert_id();
$sql = "INSERT INTO `user_preference` VALUES (-1,?,'1')";
Dba::write($sql, array($id));
// Insert streaming agent preference
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('allow_personal_info_agent','1','Personal information visibility - Recently played - Allow to show streaming agent',25,'boolean','interface')";
Dba::write($sql);
$id = Dba::insert_id();
$sql = "INSERT INTO `user_preference` VALUES (-1,?,'1')";
Dba::write($sql, array($id));
return true;
}
} }

View file

@ -170,7 +170,10 @@ function create_preference_input($name,$value)
case 'plex_backend': case 'plex_backend':
case 'webplayer_flash': case 'webplayer_flash':
case 'webplayer_html5': case 'webplayer_html5':
case 'allow_personal_info': case 'allow_personal_info_now':
case 'allow_personal_info_recent':
case 'allow_personal_info_time':
case 'allow_personal_info_agent':
if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; } if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; }
echo "<select name=\"$name\">\n"; echo "<select name=\"$name\">\n";
echo "\t<option value=\"1\" $is_true>" . T_("Enable") . "</option>\n"; echo "\t<option value=\"1\" $is_true>" . T_("Enable") . "</option>\n";

View file

@ -40,8 +40,22 @@ $thcount = 7;
<?php foreach ($data as $row) { <?php foreach ($data as $row) {
$row_user = new User($row['user']); $row_user = new User($row['user']);
$song = new Song($row['object_id']); $song = new Song($row['object_id']);
$interval = intval(time() - $row['date']);
$agent = '';
$time_string = '-';
$is_allowed = Access::check('interface', '100') || $GLOBALS['user']->id == $row_user->id;
if (!$is_allowed) {
$has_allowed_time = Preference::get_by_user($row_user->id, 'allow_personal_info_time');
$has_allowed_agent = Preference::get_by_user($row_user->id, 'allow_personal_info_agent');
}
if ($is_allowed || $has_allowed_agent) {
$agent = $row['agent']; $agent = $row['agent'];
}
if ($is_allowed || $has_allowed_time) {
$interval = intval(time() - $row['date']);
if ($interval < 60) { if ($interval < 60) {
$unit = 'seconds'; $unit = 'seconds';
@ -70,7 +84,7 @@ $thcount = 7;
// I wonder how smart gettext is? // I wonder how smart gettext is?
$time_string = sprintf(T_ngettext('%d ' . rtrim($unit, 's') . ' ago', '%d ' . $unit . ' ago', $interval), $interval); $time_string = sprintf(T_ngettext('%d ' . rtrim($unit, 's') . ' ago', '%d ' . $unit . ' ago', $interval), $interval);
}
$song->format(); $song->format();
?> ?>
<tr class="<?php echo UI::flip_class(); ?>"> <tr class="<?php echo UI::flip_class(); ?>">
@ -95,9 +109,9 @@ $thcount = 7;
</td> </td>
<td class="cel_lastplayed"><?php echo $time_string; ?></td> <td class="cel_lastplayed"><?php echo $time_string; ?></td>
<td class="cel_agent"> <td class="cel_agent">
<?php if ($agent != '') { ?> <?php if (!empty($agent)) {
<?php echo UI::get_icon('info', $agent); ?> echo UI::get_icon('info', $agent);
<?php } ?> } ?>
</td> </td>
</tr> </tr>
<?php } ?> <?php } ?>