diff options
Diffstat (limited to 'MediaBrowser.Api/Session/SessionsService.cs')
| -rw-r--r-- | MediaBrowser.Api/Session/SessionsService.cs | 79 |
1 files changed, 71 insertions, 8 deletions
diff --git a/MediaBrowser.Api/Session/SessionsService.cs b/MediaBrowser.Api/Session/SessionsService.cs index e2c10c0c8..59b8e85c2 100644 --- a/MediaBrowser.Api/Session/SessionsService.cs +++ b/MediaBrowser.Api/Session/SessionsService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Devices; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Security; using MediaBrowser.Controller.Session; @@ -235,19 +236,43 @@ namespace MediaBrowser.Api.Session [ApiMember(Name = "SupportsMediaControl", Description = "Determines whether media can be played remotely.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")] public bool SupportsMediaControl { get; set; } + + [ApiMember(Name = "SupportsContentUploading", Description = "Determines whether camera upload is supported.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")] + public bool SupportsContentUploading { get; set; } + + [ApiMember(Name = "SupportsSync", Description = "Determines whether sync is supported.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")] + public bool SupportsSync { get; set; } + + [ApiMember(Name = "SupportsUniqueIdentifier", Description = "Determines whether the device supports a unique identifier.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")] + public bool SupportsUniqueIdentifier { get; set; } + } + + [Route("/Sessions/Capabilities/Full", "POST", Summary = "Updates capabilities for a device")] + [Authenticated] + public class PostFullCapabilities : ClientCapabilities, IReturnVoid + { + /// <summary> + /// Gets or sets the id. + /// </summary> + /// <value>The id.</value> + [ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] + public string Id { get; set; } } [Route("/Sessions/Logout", "POST", Summary = "Reports that a session has ended")] + [Authenticated] public class ReportSessionEnded : IReturnVoid { } [Route("/Auth/Keys", "GET")] + [Authenticated(Roles = "Admin")] public class GetApiKeys { } [Route("/Auth/Keys/{Key}", "DELETE")] + [Authenticated(Roles = "Admin")] public class RevokeKey { [ApiMember(Name = "Key", Description = "Auth Key", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] @@ -255,6 +280,7 @@ namespace MediaBrowser.Api.Session } [Route("/Auth/Keys", "POST")] + [Authenticated(Roles = "Admin")] public class CreateKey { [ApiMember(Name = "App", Description = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] @@ -274,6 +300,7 @@ namespace MediaBrowser.Api.Session private readonly IUserManager _userManager; private readonly IAuthorizationContext _authContext; private readonly IAuthenticationRepository _authRepo; + private readonly IDeviceManager _deviceManager; /// <summary> /// Initializes a new instance of the <see cref="SessionsService" /> class. @@ -282,12 +309,13 @@ namespace MediaBrowser.Api.Session /// <param name="userManager">The user manager.</param> /// <param name="authContext">The authentication context.</param> /// <param name="authRepo">The authentication repo.</param> - public SessionsService(ISessionManager sessionManager, IUserManager userManager, IAuthorizationContext authContext, IAuthenticationRepository authRepo) + public SessionsService(ISessionManager sessionManager, IUserManager userManager, IAuthorizationContext authContext, IAuthenticationRepository authRepo, IDeviceManager deviceManager) { _sessionManager = sessionManager; _userManager = userManager; _authContext = authContext; _authRepo = authRepo; + _deviceManager = deviceManager; } public void Delete(RevokeKey request) @@ -348,10 +376,30 @@ namespace MediaBrowser.Api.Session var user = _userManager.GetUserById(request.ControllableByUserId.Value); - if (!user.Configuration.EnableRemoteControlOfOtherUsers) + if (!user.Policy.EnableRemoteControlOfOtherUsers) { - result = result.Where(i => !i.UserId.HasValue || i.ContainsUser(request.ControllableByUserId.Value)); + result = result.Where(i => i.ContainsUser(request.ControllableByUserId.Value)); } + + if (!user.Policy.EnableSharedDeviceControl) + { + result = result.Where(i => !i.UserId.HasValue); + } + + result = result.Where(i => + { + var deviceId = i.DeviceId; + + if (!string.IsNullOrWhiteSpace(deviceId)) + { + if (!_deviceManager.CanAccessDevice(user.Id.ToString("N"), deviceId)) + { + return false; + } + } + + return true; + }); } return ToOptimizedResult(result.Select(_sessionManager.GetSessionInfoDto).ToList()); @@ -494,16 +542,31 @@ namespace MediaBrowser.Api.Session { request.Id = GetSession().Id; } - _sessionManager.ReportCapabilities(request.Id, new SessionCapabilities + _sessionManager.ReportCapabilities(request.Id, new ClientCapabilities { - PlayableMediaTypes = request.PlayableMediaTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(), + PlayableMediaTypes = (request.PlayableMediaTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(), - SupportedCommands = request.SupportedCommands.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(), + SupportedCommands = (request.SupportedCommands ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(), SupportsMediaControl = request.SupportsMediaControl, - MessageCallbackUrl = request.MessageCallbackUrl + MessageCallbackUrl = request.MessageCallbackUrl, + + SupportsContentUploading = request.SupportsContentUploading, + + SupportsSync = request.SupportsSync, + + SupportsUniqueIdentifier = request.SupportsUniqueIdentifier }); } + + public void Post(PostFullCapabilities request) + { + if (string.IsNullOrWhiteSpace(request.Id)) + { + request.Id = GetSession().Id; + } + _sessionManager.ReportCapabilities(request.Id, request); + } } }
\ No newline at end of file |
