diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-01-13 15:31:09 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-01-13 15:31:09 -0500 |
| commit | e206f27839a573b357ebce972994586c2bfa8681 (patch) | |
| tree | e78e9b582eb0a8d0d8fd6673635a5a8be28ca0fb | |
| parent | c822bfc0cd9a9450a5356b8848b72289d0a4bc60 (diff) | |
add user permissions for managing tv recordings
| -rw-r--r-- | MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs | 8 | ||||
| -rw-r--r-- | MediaBrowser.Api/LiveTv/LiveTvService.cs | 29 | ||||
| -rw-r--r-- | MediaBrowser.Controller/LiveTv/ILiveTvService.cs | 9 | ||||
| -rw-r--r-- | MediaBrowser.Model/Configuration/UserConfiguration.cs | 4 | ||||
| -rw-r--r-- | MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs | 25 | ||||
| -rw-r--r-- | MediaBrowser.WebDashboard/ApiClient.js | 11 | ||||
| -rw-r--r-- | MediaBrowser.WebDashboard/packages.config | 2 | ||||
| -rw-r--r-- | Nuget/MediaBrowser.Common.Internal.nuspec | 4 | ||||
| -rw-r--r-- | Nuget/MediaBrowser.Common.nuspec | 2 | ||||
| -rw-r--r-- | Nuget/MediaBrowser.Server.Core.nuspec | 4 |
11 files changed, 80 insertions, 20 deletions
diff --git a/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs b/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs index 82df791de..6cecbd0b6 100644 --- a/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs +++ b/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs @@ -81,6 +81,14 @@ namespace MediaBrowser.Api return 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.cs index f92c4932e..5b123eb97 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.LiveTv public void Delete(DeleteRecording request) { + AssertUserCanManageLiveTv(); + var task = _liveTvManager.DeleteRecording(request.Id); Task.WaitAll(task); @@ -422,6 +439,8 @@ namespace MediaBrowser.Api.LiveTv public void Delete(CancelTimer request) { + AssertUserCanManageLiveTv(); + var task = _liveTvManager.CancelTimer(request.Id); Task.WaitAll(task); @@ -429,6 +448,8 @@ namespace MediaBrowser.Api.LiveTv public void Post(UpdateTimer request) { + AssertUserCanManageLiveTv(); + var task = _liveTvManager.UpdateTimer(request, CancellationToken.None); Task.WaitAll(task); @@ -455,6 +476,8 @@ namespace MediaBrowser.Api.LiveTv public void Delete(CancelSeriesTimer request) { + AssertUserCanManageLiveTv(); + var task = _liveTvManager.CancelSeriesTimer(request.Id); Task.WaitAll(task); @@ -462,6 +485,8 @@ namespace MediaBrowser.Api.LiveTv public void Post(UpdateSeriesTimer request) { + AssertUserCanManageLiveTv(); + var task = _liveTvManager.UpdateSeriesTimer(request, CancellationToken.None); Task.WaitAll(task); @@ -494,6 +519,8 @@ namespace MediaBrowser.Api.LiveTv public void Post(CreateSeriesTimer request) { + AssertUserCanManageLiveTv(); + var task = _liveTvManager.CreateSeriesTimer(request, CancellationToken.None); Task.WaitAll(task); @@ -501,6 +528,8 @@ namespace MediaBrowser.Api.LiveTv public 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.cs index 81613c1df..004f0b452 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs @@ -119,12 +119,13 @@ namespace MediaBrowser.Controller.LiveTv Task<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.cs index 90accff94..7cc61e7fd 100644 --- a/MediaBrowser.Model/Configuration/UserConfiguration.cs +++ b/MediaBrowser.Model/Configuration/UserConfiguration.cs @@ -67,6 +67,8 @@ namespace MediaBrowser.Model.Configuration public 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.Configuration IsAdministrator = 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.cs index 121bf53d4..55a485318 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.cs index a8b62c5a7..b53b3b651 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.LiveTv info.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.js index b35341ebb..578f71176 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.config index b28f5655a..939ca9997 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 file diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 9c011b3f4..dd0a06615 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.nuspec index d0cd3a306..72fc2ac63 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.nuspec index cc15b8c4d..f5db426ca 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> |
