Implement syncplay permissions for a user

This commit is contained in:
gion 2020-04-04 17:59:16 +02:00
parent f273995f5b
commit 459297211e
3 changed files with 71 additions and 0 deletions

View File

@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Session;
using MediaBrowser.Controller.Syncplay; using MediaBrowser.Controller.Syncplay;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Syncplay; using MediaBrowser.Model.Syncplay;
namespace Emby.Server.Implementations.Syncplay namespace Emby.Server.Implementations.Syncplay
@ -21,6 +22,11 @@ namespace Emby.Server.Implementations.Syncplay
/// </summary> /// </summary>
private readonly ILogger _logger; private readonly ILogger _logger;
/// <summary>
/// The user manager.
/// </summary>
private readonly IUserManager _userManager;
/// <summary> /// <summary>
/// The session manager. /// The session manager.
/// </summary> /// </summary>
@ -42,9 +48,11 @@ namespace Emby.Server.Implementations.Syncplay
public SyncplayManager( public SyncplayManager(
ILogger<SyncplayManager> logger, ILogger<SyncplayManager> logger,
IUserManager userManager,
ISessionManager sessionManager) ISessionManager sessionManager)
{ {
_logger = logger; _logger = logger;
_userManager = userManager;
_sessionManager = sessionManager; _sessionManager = sessionManager;
_sessionManager.SessionEnded += _sessionManager_SessionEnded; _sessionManager.SessionEnded += _sessionManager_SessionEnded;
@ -125,8 +133,16 @@ namespace Emby.Server.Implementations.Syncplay
/// <inheritdoc /> /// <inheritdoc />
public void NewGroup(SessionInfo session) public void NewGroup(SessionInfo session)
{ {
var user = _userManager.GetUserById(session.UserId);
if (user.Policy.SyncplayAccess != SyncplayAccess.CreateAndJoinGroups)
{ {
// TODO: shall an error message be sent back to the client?
return;
}
if (IsSessionInGroup(session)) if (IsSessionInGroup(session))
{
LeaveGroup(session); LeaveGroup(session);
} }
@ -139,6 +155,14 @@ namespace Emby.Server.Implementations.Syncplay
/// <inheritdoc /> /// <inheritdoc />
public void JoinGroup(SessionInfo session, string groupId) public void JoinGroup(SessionInfo session, string groupId)
{ {
var user = _userManager.GetUserById(session.UserId);
if (user.Policy.SyncplayAccess == SyncplayAccess.None)
{
// TODO: shall an error message be sent back to the client?
return;
}
if (IsSessionInGroup(session)) if (IsSessionInGroup(session))
{ {
if (GetSessionGroup(session).Equals(groupId)) return; if (GetSessionGroup(session).Equals(groupId)) return;
@ -163,6 +187,8 @@ namespace Emby.Server.Implementations.Syncplay
/// <inheritdoc /> /// <inheritdoc />
public void LeaveGroup(SessionInfo session) public void LeaveGroup(SessionInfo session)
{ {
// TODO: what happens to users that are in a group and get their permissions revoked?
ISyncplayController group; ISyncplayController group;
_sessionToGroupMap.TryGetValue(session.Id, out group); _sessionToGroupMap.TryGetValue(session.Id, out group);
@ -186,6 +212,13 @@ namespace Emby.Server.Implementations.Syncplay
/// <inheritdoc /> /// <inheritdoc />
public List<GroupInfoView> ListGroups(SessionInfo session) public List<GroupInfoView> ListGroups(SessionInfo session)
{ {
var user = _userManager.GetUserById(session.UserId);
if (user.Policy.SyncplayAccess == SyncplayAccess.None)
{
return new List<GroupInfoView>();
}
// Filter by playing item if the user is viewing something already // Filter by playing item if the user is viewing something already
if (session.NowPlayingItem != null) if (session.NowPlayingItem != null)
{ {
@ -207,6 +240,14 @@ namespace Emby.Server.Implementations.Syncplay
/// <inheritdoc /> /// <inheritdoc />
public void HandleRequest(SessionInfo session, SyncplayRequestInfo request) public void HandleRequest(SessionInfo session, SyncplayRequestInfo request)
{ {
var user = _userManager.GetUserById(session.UserId);
if (user.Policy.SyncplayAccess == SyncplayAccess.None)
{
// TODO: same as LeaveGroup
return;
}
ISyncplayController group; ISyncplayController group;
_sessionToGroupMap.TryGetValue(session.Id, out group); _sessionToGroupMap.TryGetValue(session.Id, out group);

View File

@ -0,0 +1,23 @@
namespace MediaBrowser.Model.Configuration
{
/// <summary>
/// Enum SyncplayAccess.
/// </summary>
public enum SyncplayAccess
{
/// <summary>
/// User can create groups and join them.
/// </summary>
CreateAndJoinGroups,
/// <summary>
/// User can only join already existing groups.
/// </summary>
JoinGroups,
/// <summary>
/// Syncplay is disabled for the user.
/// </summary>
None
}
}

View File

@ -80,6 +80,12 @@ namespace MediaBrowser.Model.Users
public string AuthenticationProviderId { get; set; } public string AuthenticationProviderId { get; set; }
public string PasswordResetProviderId { get; set; } public string PasswordResetProviderId { get; set; }
/// <summary>
/// Gets or sets a value indicating what Syncplay features the user can access.
/// </summary>
/// <value>Access level to Syncplay features.</value>
public SyncplayAccess SyncplayAccess { get; set; }
public UserPolicy() public UserPolicy()
{ {
IsHidden = true; IsHidden = true;
@ -125,6 +131,7 @@ namespace MediaBrowser.Model.Users
EnableContentDownloading = true; EnableContentDownloading = true;
EnablePublicSharing = true; EnablePublicSharing = true;
EnableRemoteAccess = true; EnableRemoteAccess = true;
SyncplayAccess = SyncplayAccess.CreateAndJoinGroups;
} }
} }
} }