From 8a9f16ff6ae94fe1e86d93495b4908e253f7dba2 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 29 Dec 2014 15:18:48 -0500 Subject: enable user device access --- MediaBrowser.Api/Session/SessionsService.cs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Api/Session/SessionsService.cs') diff --git a/MediaBrowser.Api/Session/SessionsService.cs b/MediaBrowser.Api/Session/SessionsService.cs index 4f47b9f54..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; @@ -299,6 +300,7 @@ namespace MediaBrowser.Api.Session private readonly IUserManager _userManager; private readonly IAuthorizationContext _authContext; private readonly IAuthenticationRepository _authRepo; + private readonly IDeviceManager _deviceManager; /// /// Initializes a new instance of the class. @@ -307,12 +309,13 @@ namespace MediaBrowser.Api.Session /// The user manager. /// The authentication context. /// The authentication repo. - 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) @@ -382,6 +385,21 @@ namespace MediaBrowser.Api.Session { 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()); -- cgit v1.2.3