Filter groups by library access
This commit is contained in:
parent
459297211e
commit
e74832d139
|
@ -1,9 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Session;
|
using MediaBrowser.Controller.Session;
|
||||||
using MediaBrowser.Controller.Syncplay;
|
using MediaBrowser.Controller.Syncplay;
|
||||||
|
@ -32,6 +34,11 @@ namespace Emby.Server.Implementations.Syncplay
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly ISessionManager _sessionManager;
|
private readonly ISessionManager _sessionManager;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The library manager.
|
||||||
|
/// </summary>
|
||||||
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The map between sessions and groups.
|
/// The map between sessions and groups.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -49,11 +56,13 @@ namespace Emby.Server.Implementations.Syncplay
|
||||||
public SyncplayManager(
|
public SyncplayManager(
|
||||||
ILogger<SyncplayManager> logger,
|
ILogger<SyncplayManager> logger,
|
||||||
IUserManager userManager,
|
IUserManager userManager,
|
||||||
ISessionManager sessionManager)
|
ISessionManager sessionManager,
|
||||||
|
ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
_sessionManager = sessionManager;
|
_sessionManager = sessionManager;
|
||||||
|
_libraryManager = libraryManager;
|
||||||
|
|
||||||
_sessionManager.SessionEnded += _sessionManager_SessionEnded;
|
_sessionManager.SessionEnded += _sessionManager_SessionEnded;
|
||||||
_sessionManager.PlaybackStopped += _sessionManager_PlaybackStopped;
|
_sessionManager.PlaybackStopped += _sessionManager_PlaybackStopped;
|
||||||
|
@ -116,6 +125,23 @@ namespace Emby.Server.Implementations.Syncplay
|
||||||
return _sessionToGroupMap.ContainsKey(session.Id);
|
return _sessionToGroupMap.ContainsKey(session.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool HasAccessToItem(User user, Guid itemId)
|
||||||
|
{
|
||||||
|
if (!user.Policy.EnableAllFolders)
|
||||||
|
{
|
||||||
|
var item = _libraryManager.GetItemById(itemId);
|
||||||
|
var collections = _libraryManager.GetCollectionFolders(item).Select(
|
||||||
|
folder => folder.Id.ToString("N", CultureInfo.InvariantCulture)
|
||||||
|
);
|
||||||
|
var intersect = collections.Intersect(user.Policy.EnabledFolders);
|
||||||
|
return intersect.Count() > 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Guid? GetSessionGroup(SessionInfo session)
|
private Guid? GetSessionGroup(SessionInfo session)
|
||||||
{
|
{
|
||||||
ISyncplayController group;
|
ISyncplayController group;
|
||||||
|
@ -181,6 +207,12 @@ namespace Emby.Server.Implementations.Syncplay
|
||||||
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), update, CancellationToken.None);
|
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), update, CancellationToken.None);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!HasAccessToItem(user, group.GetPlayingItemId()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
group.SessionJoin(session);
|
group.SessionJoin(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,6 +255,8 @@ namespace Emby.Server.Implementations.Syncplay
|
||||||
if (session.NowPlayingItem != null)
|
if (session.NowPlayingItem != null)
|
||||||
{
|
{
|
||||||
return _groups.Values.Where(
|
return _groups.Values.Where(
|
||||||
|
group => HasAccessToItem(user, group.GetPlayingItemId())
|
||||||
|
).Where(
|
||||||
group => group.GetPlayingItemId().Equals(session.FullNowPlayingItem.Id)
|
group => group.GetPlayingItemId().Equals(session.FullNowPlayingItem.Id)
|
||||||
).Select(
|
).Select(
|
||||||
group => group.GetInfo()
|
group => group.GetInfo()
|
||||||
|
@ -231,7 +265,9 @@ namespace Emby.Server.Implementations.Syncplay
|
||||||
// Otherwise show all available groups
|
// Otherwise show all available groups
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return _groups.Values.Select(
|
return _groups.Values.Where(
|
||||||
|
group => HasAccessToItem(user, group.GetPlayingItemId())
|
||||||
|
).Select(
|
||||||
group => group.GetInfo()
|
group => group.GetInfo()
|
||||||
).ToList();
|
).ToList();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user