The Free Software Media System - Server Backend & API
add user permissions for managing tv recordings
Luke Pulverentie206f27839a5
diff --git a/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs b/MediaBrowser.Api/AuthorizationRequestFilterAttribute.csindex 82df791ded..6cecbd0b62 100644--- a/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs+++ b/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs@@ -81,6 +81,14 @@ namespace MediaBrowser.Apireturn GetAuthorization(auth);}+ public static User GetCurrentUser(IRequest httpReq, IUserManager userManager)+ {+ var info = GetAuthorization(httpReq);++ return string.IsNullOrEmpty(info.UserId) ? null :+ userManager.GetUserById(new Guid(info.UserId));+ }+/// <summary>/// Gets the authorization./// </summary>diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.csindex f92c4932e0..5b123eb974 100644--- a/MediaBrowser.Api/LiveTv/LiveTvService.cs+++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs@@ -275,6 +275,21 @@ namespace MediaBrowser.Api.LiveTv_userManager = userManager;}+ private void AssertUserCanManageLiveTv()+ {+ var user = AuthorizationRequestFilterAttribute.GetCurrentUser(Request, _userManager);++ if (user == null)+ {+ throw new UnauthorizedAccessException("Anonymous live tv management is not allowed.");+ }++ if (!user.Configuration.EnableLiveTvManagement)+ {+ throw new UnauthorizedAccessException("The current user does not have permission to manage live tv.");+ }+ }+public object Get(GetServices request){var services = _liveTvManager.Services@@ -415,6 +430,8 @@ namespace MediaBrowser.Api.LiveTvpublic void Delete(DeleteRecording request){+ AssertUserCanManageLiveTv();+var task = _liveTvManager.DeleteRecording(request.Id);Task.WaitAll(task);@@ -422,6 +439,8 @@ namespace MediaBrowser.Api.LiveTvpublic void Delete(CancelTimer request){+ AssertUserCanManageLiveTv();+var task = _liveTvManager.CancelTimer(request.Id);Task.WaitAll(task);@@ -429,6 +448,8 @@ namespace MediaBrowser.Api.LiveTvpublic void Post(UpdateTimer request){+ AssertUserCanManageLiveTv();+var task = _liveTvManager.UpdateTimer(request, CancellationToken.None);Task.WaitAll(task);@@ -455,6 +476,8 @@ namespace MediaBrowser.Api.LiveTvpublic void Delete(CancelSeriesTimer request){+ AssertUserCanManageLiveTv();+var task = _liveTvManager.CancelSeriesTimer(request.Id);Task.WaitAll(task);@@ -462,6 +485,8 @@ namespace MediaBrowser.Api.LiveTvpublic void Post(UpdateSeriesTimer request){+ AssertUserCanManageLiveTv();+var task = _liveTvManager.UpdateSeriesTimer(request, CancellationToken.None);Task.WaitAll(task);@@ -494,6 +519,8 @@ namespace MediaBrowser.Api.LiveTvpublic void Post(CreateSeriesTimer request){+ AssertUserCanManageLiveTv();+var task = _liveTvManager.CreateSeriesTimer(request, CancellationToken.None);Task.WaitAll(task);@@ -501,6 +528,8 @@ namespace MediaBrowser.Api.LiveTvpublic void Post(CreateTimer request){+ AssertUserCanManageLiveTv();+var task = _liveTvManager.CreateTimer(request, CancellationToken.None);Task.WaitAll(task);diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs b/MediaBrowser.Controller/LiveTv/ILiveTvService.csindex 81613c1df6..004f0b4525 100644--- a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs+++ b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs@@ -119,12 +119,13 @@ namespace MediaBrowser.Controller.LiveTvTask<IEnumerable<TimerInfo>> GetTimersAsync(CancellationToken cancellationToken);/// <summary>- /// Gets the timer defaults asynchronous.+ /// Gets the new timer defaults asynchronous./// </summary>/// <param name="cancellationToken">The cancellation token.</param>- /// <returns>Task{TimerInfo}.</returns>- Task<SeriesTimerInfo> GetNewTimerDefaultsAsync(CancellationToken cancellationToken);-+ /// <param name="program">The program.</param>+ /// <returns>Task{SeriesTimerInfo}.</returns>+ Task<SeriesTimerInfo> GetNewTimerDefaultsAsync(CancellationToken cancellationToken, ProgramInfo program = null);+/// <summary>/// Gets the series timers asynchronous./// </summary>diff --git a/MediaBrowser.Model/Configuration/UserConfiguration.cs b/MediaBrowser.Model/Configuration/UserConfiguration.csindex 90accff94c..7cc61e7fdd 100644--- a/MediaBrowser.Model/Configuration/UserConfiguration.cs+++ b/MediaBrowser.Model/Configuration/UserConfiguration.cs@@ -67,6 +67,8 @@ namespace MediaBrowser.Model.Configurationpublic bool BlockUnratedGames { get; set; }public bool BlockUnratedBooks { get; set; }+ public bool EnableLiveTvManagement { get; set; }+/// <summary>/// Initializes a new instance of the <see cref="UserConfiguration" /> class./// </summary>@@ -75,6 +77,8 @@ namespace MediaBrowser.Model.ConfigurationIsAdministrator = true;EnableRemoteControlOfOtherUsers = true;BlockNotRated = false;++ EnableLiveTvManagement = true;}}}diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.csindex 121bf53d49..55a485318d 100644--- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs@@ -70,7 +70,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV}// Without these movies that have the name season in them could cause the parent folder to be resolved as a series- if (filename.IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1 || filename.IndexOf("[tmdbid=", StringComparison.OrdinalIgnoreCase) != -1)+ if (filename.IndexOf("[tmdbid=", StringComparison.OrdinalIgnoreCase) != -1){return null;}diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.csindex a8b62c5a7b..b53b3b651b 100644--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs@@ -1011,24 +1011,31 @@ namespace MediaBrowser.Server.Implementations.LiveTv.FirstOrDefault();}- public async Task<SeriesTimerInfoDto> GetNewTimerDefaults(CancellationToken cancellationToken)+ private async Task<SeriesTimerInfo> GetNewTimerDefaultsInternal(CancellationToken cancellationToken, ProgramInfo program = null){- var service = ActiveService;+ var info = await ActiveService.GetNewTimerDefaultsAsync(cancellationToken, program).ConfigureAwait(false);- var info = await service.GetNewTimerDefaultsAsync(cancellationToken).ConfigureAwait(false);+ info.Id = null;- var obj = _tvDtoService.GetSeriesTimerInfoDto(info, service, null);+ return info;+ }++ public async Task<SeriesTimerInfoDto> GetNewTimerDefaults(CancellationToken cancellationToken)+ {+ var info = await GetNewTimerDefaultsInternal(cancellationToken).ConfigureAwait(false);- obj.Id = obj.ExternalId = string.Empty;+ var obj = _tvDtoService.GetSeriesTimerInfoDto(info, ActiveService, null);return obj;}public async Task<SeriesTimerInfoDto> GetNewTimerDefaults(string programId, CancellationToken cancellationToken){- var info = await GetNewTimerDefaults(cancellationToken).ConfigureAwait(false);+ var program = GetInternalProgram(programId).ProgramInfo;+ var programDto = await GetProgram(programId, cancellationToken).ConfigureAwait(false);- var program = await GetProgram(programId, cancellationToken).ConfigureAwait(false);+ var defaults = await GetNewTimerDefaultsInternal(cancellationToken, program).ConfigureAwait(false);+ var info = _tvDtoService.GetSeriesTimerInfoDto(defaults, ActiveService, null);info.Days = new List<DayOfWeek>{@@ -1039,13 +1046,13 @@ namespace MediaBrowser.Server.Implementations.LiveTvinfo.Name = program.Name;info.ChannelId = program.ChannelId;- info.ChannelName = program.ChannelName;+ info.ChannelName = programDto.ChannelName;info.EndDate = program.EndDate;info.StartDate = program.StartDate;info.Name = program.Name;info.Overview = program.Overview;info.ProgramId = program.Id;- info.ExternalProgramId = program.ExternalId;+ info.ExternalProgramId = programDto.ExternalId;return info;}diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.jsindex b35341ebb0..578f711760 100644--- a/MediaBrowser.WebDashboard/ApiClient.js+++ b/MediaBrowser.WebDashboard/ApiClient.js@@ -378,6 +378,17 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi});};+ self.getAuthorizedFeatures = function (options) {++ var url = self.getUrl("Users/AuthorizedFeatures", options || {});++ return self.ajax({+ type: "GET",+ url: url,+ dataType: "json"+ });+ };+self.getLiveTvServices = function (options) {var url = self.getUrl("LiveTv/Services", options || {});diff --git a/MediaBrowser.WebDashboard/packages.config b/MediaBrowser.WebDashboard/packages.configindex b28f5655a4..939ca9997a 100644--- a/MediaBrowser.WebDashboard/packages.config+++ b/MediaBrowser.WebDashboard/packages.config@@ -1,4 +1,4 @@<?xml version="1.0" encoding="utf-8"?><packages>- <package id="MediaBrowser.ApiClient.Javascript" version="3.0.226" targetFramework="net45" />+ <package id="MediaBrowser.ApiClient.Javascript" version="3.0.228" targetFramework="net45" /></packages>\ No newline at end of filediff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspecindex 9c011b3f41..dd0a066153 100644--- a/Nuget/MediaBrowser.Common.Internal.nuspec+++ b/Nuget/MediaBrowser.Common.Internal.nuspec@@ -2,7 +2,7 @@<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"><metadata><id>MediaBrowser.Common.Internal</id>- <version>3.0.299</version>+ <version>3.0.300</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.299" />+ <dependency id="MediaBrowser.Common" version="3.0.300" /><dependency id="NLog" version="2.1.0" /><dependency id="SimpleInjector" version="2.4.0" /><dependency id="sharpcompress" version="0.10.2" />diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspecindex d0cd3a3069..72fc2ac63a 100644--- a/Nuget/MediaBrowser.Common.nuspec+++ b/Nuget/MediaBrowser.Common.nuspec@@ -2,7 +2,7 @@<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"><metadata><id>MediaBrowser.Common</id>- <version>3.0.299</version>+ <version>3.0.300</version><title>MediaBrowser.Common</title><authors>Media Browser Team</authors><owners>ebr,Luke,scottisafool</owners>diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspecindex cc15b8c4d1..f5db426ca2 100644--- a/Nuget/MediaBrowser.Server.Core.nuspec+++ b/Nuget/MediaBrowser.Server.Core.nuspec@@ -2,7 +2,7 @@<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"><metadata><id>MediaBrowser.Server.Core</id>- <version>3.0.299</version>+ <version>3.0.300</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.299" />+ <dependency id="MediaBrowser.Common" version="3.0.300" /></dependencies></metadata><files>