add user permissions for managing tv recordings

This commit is contained in:
Luke Pulverenti 2014-01-13 15:31:09 -05:00
parent c822bfc0cd
commit e206f27839
11 changed files with 81 additions and 21 deletions

View File

@ -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>

View File

@ -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);

View File

@ -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>

View File

@ -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;
}
}
}

View File

@ -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;
}

View File

@ -1011,24 +1011,31 @@ namespace MediaBrowser.Server.Implementations.LiveTv
.FirstOrDefault();
}
private async Task<SeriesTimerInfo> GetNewTimerDefaultsInternal(CancellationToken cancellationToken, ProgramInfo program = null)
{
var info = await ActiveService.GetNewTimerDefaultsAsync(cancellationToken, program).ConfigureAwait(false);
info.Id = null;
return info;
}
public async Task<SeriesTimerInfoDto> GetNewTimerDefaults(CancellationToken cancellationToken)
{
var service = ActiveService;
var info = await GetNewTimerDefaultsInternal(cancellationToken).ConfigureAwait(false);
var info = await service.GetNewTimerDefaultsAsync(cancellationToken).ConfigureAwait(false);
var obj = _tvDtoService.GetSeriesTimerInfoDto(info, service, null);
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;
}

View File

@ -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 || {});

View File

@ -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>

View File

@ -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" />

View File

@ -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>

View File

@ -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>