From 4ce43ce019e24344f08ee6743c0efef7a03875a9 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 22 Jan 2014 21:19:04 -0500 Subject: [PATCH] fixes #683 - Support disabling playback per user --- MediaBrowser.Api/Playback/BaseStreamingService.cs | 7 +++++++ MediaBrowser.Model/Configuration/UserConfiguration.cs | 3 +++ .../Session/SessionManager.cs | 10 ++++++++++ 3 files changed, 20 insertions(+) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 6761c272de..394ca69d5a 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1007,6 +1007,13 @@ namespace MediaBrowser.Api.Playback throw new InvalidOperationException("You asked for a debug error, you got one."); } + var user = AuthorizationRequestFilterAttribute.GetCurrentUser(Request, UserManager); + + if (user != null && !user.Configuration.EnableMediaPlayback) + { + throw new ArgumentException(string.Format("{0} is not allowed to play media.", user.Name)); + } + var url = Request.PathInfo; if (!request.AudioCodec.HasValue) diff --git a/MediaBrowser.Model/Configuration/UserConfiguration.cs b/MediaBrowser.Model/Configuration/UserConfiguration.cs index 7cc61e7fdd..ba47269563 100644 --- a/MediaBrowser.Model/Configuration/UserConfiguration.cs +++ b/MediaBrowser.Model/Configuration/UserConfiguration.cs @@ -68,6 +68,8 @@ namespace MediaBrowser.Model.Configuration public bool BlockUnratedBooks { get; set; } public bool EnableLiveTvManagement { get; set; } + + public bool EnableMediaPlayback { get; set; } /// /// Initializes a new instance of the class. @@ -79,6 +81,7 @@ namespace MediaBrowser.Model.Configuration BlockNotRated = false; EnableLiveTvManagement = true; + EnableMediaPlayback = true; } } } diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index d24de75cb7..fd78d1aaa6 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -604,6 +604,16 @@ namespace MediaBrowser.Server.Implementations.Session { var session = GetSessionForRemoteControl(sessionId); + if (session.UserId.HasValue) + { + var user = _userManager.GetUserById(session.UserId.Value); + + if (!user.Configuration.EnableMediaPlayback) + { + throw new ArgumentException(string.Format("{0} is not allowed to play media.", user.Name)); + } + } + var items = command.ItemIds.Select(i => _libraryManager.GetItemById(new Guid(i))) .ToList();