|  | @@ -3,13 +3,14 @@ using System.Collections.Generic;
 | 
	
		
			
				|  |  |  using System.Globalization;
 | 
	
		
			
				|  |  |  using System.Linq;
 | 
	
		
			
				|  |  |  using System.Threading;
 | 
	
		
			
				|  |  | -using Microsoft.Extensions.Logging;
 | 
	
		
			
				|  |  | -using MediaBrowser.Controller.Entities;
 | 
	
		
			
				|  |  | +using Jellyfin.Data.Entities;
 | 
	
		
			
				|  |  | +using Jellyfin.Data.Enums;
 | 
	
		
			
				|  |  |  using MediaBrowser.Controller.Library;
 | 
	
		
			
				|  |  |  using MediaBrowser.Controller.Session;
 | 
	
		
			
				|  |  |  using MediaBrowser.Controller.SyncPlay;
 | 
	
		
			
				|  |  |  using MediaBrowser.Model.Configuration;
 | 
	
		
			
				|  |  |  using MediaBrowser.Model.SyncPlay;
 | 
	
		
			
				|  |  | +using Microsoft.Extensions.Logging;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |  {
 | 
	
	
		
			
				|  | @@ -102,14 +103,6 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |              _disposed = true;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void CheckDisposed()
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            if (_disposed)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                throw new ObjectDisposedException(GetType().Name);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          private void OnSessionManagerSessionEnded(object sender, SessionEventArgs e)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              var session = e.SessionInfo;
 | 
	
	
		
			
				|  | @@ -143,37 +136,26 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              // Check ParentalRating access
 | 
	
		
			
				|  |  |              var hasParentalRatingAccess = true;
 | 
	
		
			
				|  |  | -            if (user.Policy.MaxParentalRating.HasValue)
 | 
	
		
			
				|  |  | +            if (user.MaxParentalAgeRating.HasValue)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                hasParentalRatingAccess = item.InheritedParentalRatingValue <= user.Policy.MaxParentalRating;
 | 
	
		
			
				|  |  | +                hasParentalRatingAccess = item.InheritedParentalRatingValue <= user.MaxParentalAgeRating.Value;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (!user.Policy.EnableAllFolders && hasParentalRatingAccess)
 | 
	
		
			
				|  |  | +            if (!user.HasPermission(PermissionKind.EnableAllFolders) && hasParentalRatingAccess)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  var collections = _libraryManager.GetCollectionFolders(item).Select(
 | 
	
		
			
				|  |  | -                    folder => folder.Id.ToString("N", CultureInfo.InvariantCulture)
 | 
	
		
			
				|  |  | -                );
 | 
	
		
			
				|  |  | -                var intersect = collections.Intersect(user.Policy.EnabledFolders);
 | 
	
		
			
				|  |  | -                return intersect.Any();
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            else
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                return hasParentalRatingAccess;
 | 
	
		
			
				|  |  | +                    folder => folder.Id.ToString("N", CultureInfo.InvariantCulture));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                return collections.Intersect(user.GetPreference(PreferenceKind.EnabledFolders)).Any();
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return hasParentalRatingAccess;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          private Guid? GetSessionGroup(SessionInfo session)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            ISyncPlayController group;
 | 
	
		
			
				|  |  | -            _sessionToGroupMap.TryGetValue(session.Id, out group);
 | 
	
		
			
				|  |  | -            if (group != null)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                return group.GetGroupId();
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            else
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                return null;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +            _sessionToGroupMap.TryGetValue(session.Id, out var group);
 | 
	
		
			
				|  |  | +            return group?.GetGroupId();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          /// <inheritdoc />
 | 
	
	
		
			
				|  | @@ -181,7 +163,7 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              var user = _userManager.GetUserById(session.UserId);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (user.Policy.SyncPlayAccess != SyncPlayAccess.CreateAndJoinGroups)
 | 
	
		
			
				|  |  | +            if (user.SyncPlayAccess != SyncPlayAccess.CreateAndJoinGroups)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  _logger.LogWarning("NewGroup: {0} does not have permission to create groups.", session.Id);
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -189,7 +171,7 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  |                      Type = GroupUpdateType.CreateGroupDenied
 | 
	
		
			
				|  |  |                  };
 | 
	
		
			
				|  |  | -                _sessionManager.SendSyncPlayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
 | 
	
		
			
				|  |  | +                _sessionManager.SendSyncPlayGroupUpdate(session.Id, error, CancellationToken.None);
 | 
	
		
			
				|  |  |                  return;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -212,7 +194,7 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              var user = _userManager.GetUserById(session.UserId);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (user.Policy.SyncPlayAccess == SyncPlayAccess.None)
 | 
	
		
			
				|  |  | +            if (user.SyncPlayAccess == SyncPlayAccess.None)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  _logger.LogWarning("JoinGroup: {0} does not have access to SyncPlay.", session.Id);
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -220,7 +202,7 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  |                      Type = GroupUpdateType.JoinGroupDenied
 | 
	
		
			
				|  |  |                  };
 | 
	
		
			
				|  |  | -                _sessionManager.SendSyncPlayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
 | 
	
		
			
				|  |  | +                _sessionManager.SendSyncPlayGroupUpdate(session.Id, error, CancellationToken.None);
 | 
	
		
			
				|  |  |                  return;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -237,7 +219,7 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |                      {
 | 
	
		
			
				|  |  |                          Type = GroupUpdateType.GroupDoesNotExist
 | 
	
		
			
				|  |  |                      };
 | 
	
		
			
				|  |  | -                    _sessionManager.SendSyncPlayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
 | 
	
		
			
				|  |  | +                    _sessionManager.SendSyncPlayGroupUpdate(session.Id, error, CancellationToken.None);
 | 
	
		
			
				|  |  |                      return;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -250,7 +232,7 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |                          GroupId = group.GetGroupId().ToString(),
 | 
	
		
			
				|  |  |                          Type = GroupUpdateType.LibraryAccessDenied
 | 
	
		
			
				|  |  |                      };
 | 
	
		
			
				|  |  | -                    _sessionManager.SendSyncPlayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
 | 
	
		
			
				|  |  | +                    _sessionManager.SendSyncPlayGroupUpdate(session.Id, error, CancellationToken.None);
 | 
	
		
			
				|  |  |                      return;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -285,7 +267,7 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |                      {
 | 
	
		
			
				|  |  |                          Type = GroupUpdateType.NotInGroup
 | 
	
		
			
				|  |  |                      };
 | 
	
		
			
				|  |  | -                    _sessionManager.SendSyncPlayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
 | 
	
		
			
				|  |  | +                    _sessionManager.SendSyncPlayGroupUpdate(session.Id, error, CancellationToken.None);
 | 
	
		
			
				|  |  |                      return;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -304,7 +286,7 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              var user = _userManager.GetUserById(session.UserId);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (user.Policy.SyncPlayAccess == SyncPlayAccess.None)
 | 
	
		
			
				|  |  | +            if (user.SyncPlayAccess == SyncPlayAccess.None)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  return new List<GroupInfoView>();
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -334,7 +316,7 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              var user = _userManager.GetUserById(session.UserId);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (user.Policy.SyncPlayAccess == SyncPlayAccess.None)
 | 
	
		
			
				|  |  | +            if (user.SyncPlayAccess == SyncPlayAccess.None)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  _logger.LogWarning("HandleRequest: {0} does not have access to SyncPlay.", session.Id);
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -342,7 +324,7 @@ namespace Emby.Server.Implementations.SyncPlay
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  |                      Type = GroupUpdateType.JoinGroupDenied
 | 
	
		
			
				|  |  |                  };
 | 
	
		
			
				|  |  | -                _sessionManager.SendSyncPlayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
 | 
	
		
			
				|  |  | +                _sessionManager.SendSyncPlayGroupUpdate(session.Id, error, CancellationToken.None);
 | 
	
		
			
				|  |  |                  return;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 |