enforce user access to offline items

This commit is contained in:
Luke Pulverenti 2015-02-03 16:06:56 -05:00
parent 256990ac7b
commit 655c9ea7a1
10 changed files with 80 additions and 12 deletions

View File

@ -1083,6 +1083,23 @@ namespace MediaBrowser.Controller.Entities
return IsParentalAllowed(user);
}
public virtual bool IsVisibleStandalone(User user)
{
if (!IsVisible(user))
{
return false;
}
if (Parents.Any(i => !i.IsVisible(user)))
{
return false;
}
// TODO: Need some work here, e.g. is in user library, for channels, can user access channel, etc.
return true;
}
/// <summary>
/// Gets a value indicating whether this instance is folder.
/// </summary>

View File

@ -5,12 +5,14 @@ namespace MediaBrowser.Model.Sync
public class SyncDataRequest
{
public List<string> LocalItemIds { get; set; }
public List<string> OfflineUserIds { get; set; }
public string TargetId { get; set; }
public SyncDataRequest()
{
LocalItemIds = new List<string>();
OfflineUserIds = new List<string>();
}
}
}

View File

@ -5,10 +5,12 @@ namespace MediaBrowser.Model.Sync
public class SyncDataResponse
{
public List<string> ItemIdsToRemove { get; set; }
public Dictionary<string, List<string>> ItemUserAccess { get; set; }
public SyncDataResponse()
{
ItemIdsToRemove = new List<string>();
ItemUserAccess = new Dictionary<string, List<string>>();
}
}
}

View File

@ -147,7 +147,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var currentUser = user;
channels = channels
.Where(i => i.IsParentalAllowed(currentUser))
.Where(i => i.IsVisible(currentUser))
.OrderBy(i =>
{
double number = 0;
@ -679,7 +679,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
{
// Avoid implicitly captured closure
var currentUser = user;
programs = programs.Where(i => i.IsParentalAllowed(currentUser));
programs = programs.Where(i => i.IsVisible(currentUser));
}
var programList = programs.ToList();
@ -714,7 +714,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
// Avoid implicitly captured closure
var currentUser = user;
programs = programs.Where(i => i.IsParentalAllowed(currentUser));
programs = programs.Where(i => i.IsVisible(currentUser));
if (query.IsAiring.HasValue)
{

View File

@ -314,6 +314,10 @@ namespace MediaBrowser.Server.Implementations.Sync
try
{
_fileSystem.DeleteDirectory(path, true);
}
catch (DirectoryNotFoundException)
{
}
catch (Exception ex)
{
@ -664,9 +668,48 @@ namespace MediaBrowser.Server.Implementations.Sync
response.ItemIdsToRemove = response.ItemIdsToRemove.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
var itemsOnDevice = request.LocalItemIds
.Except(response.ItemIdsToRemove)
.ToList();
SetUserAccess(request, response, itemsOnDevice);
return response;
}
private void SetUserAccess(SyncDataRequest request, SyncDataResponse response, List<string> itemIds)
{
var users = request.OfflineUserIds
.Select(_userManager.GetUserById)
.Where(i => i != null)
.ToList();
foreach (var itemId in itemIds)
{
var item = _libraryManager.GetItemById(itemId);
if (item != null)
{
var usersWithAccess = new List<User>();
foreach (var user in users)
{
if (IsUserVisible(item, user))
{
usersWithAccess.Add(user);
}
}
response.ItemUserAccess[itemId] = users.Select(i => i.Id.ToString("N")).ToList();
}
}
}
private bool IsUserVisible(BaseItem item, User user)
{
return item.IsVisibleStandalone(user);
}
private bool IsLibraryItemAvailable(BaseItem item)
{
if (item == null)
@ -723,6 +766,10 @@ namespace MediaBrowser.Server.Implementations.Sync
try
{
_fileSystem.DeleteDirectory(path, true);
}
catch (DirectoryNotFoundException)
{
}
catch (Exception ex)
{

View File

@ -407,7 +407,6 @@ namespace MediaBrowser.Server.Implementations.Sync
if (!string.IsNullOrWhiteSpace(query.TargetId))
{
whereClauses.Add("TargetId=@TargetId");
cmd.Parameters.Add(cmd, "@TargetId", DbType.String).Value = query.TargetId;
}
if (!string.IsNullOrWhiteSpace(query.UserId))
{
@ -422,7 +421,7 @@ namespace MediaBrowser.Server.Implementations.Sync
var startIndex = query.StartIndex ?? 0;
if (startIndex > 0)
{
whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM SyncJobs ORDER BY DateLastModified DESC LIMIT {0})",
whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM SyncJobs ORDER BY (Select Max(DateLastModified) from SyncJobs where TargetId=@TargetId) DESC, DateLastModified DESC LIMIT {0})",
startIndex.ToString(_usCulture)));
}
@ -431,7 +430,8 @@ namespace MediaBrowser.Server.Implementations.Sync
cmd.CommandText += " where " + string.Join(" AND ", whereClauses.ToArray());
}
cmd.CommandText += " ORDER BY DateLastModified DESC";
cmd.CommandText += " ORDER BY (Select Max(DateLastModified) from SyncJobs where TargetId=@TargetId) DESC, DateLastModified DESC";
cmd.Parameters.Add(cmd, "@TargetId", DbType.String).Value = query.TargetId;
if (query.Limit.HasValue)
{

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.551</version>
<version>3.0.552</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.551" />
<dependency id="MediaBrowser.Common" version="3.0.552" />
<dependency id="NLog" version="3.1.0.0" />
<dependency id="SimpleInjector" version="2.6.1" />
</dependencies>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.551</version>
<version>3.0.552</version>
<title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Model.Signed</id>
<version>3.0.551</version>
<version>3.0.552</version>
<title>MediaBrowser.Model - Signed Edition</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.551</version>
<version>3.0.552</version>
<title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.551" />
<dependency id="MediaBrowser.Common" version="3.0.552" />
</dependencies>
</metadata>
<files>