From 025888204de529d21bc54b68de9d19fa4ab5c56b Mon Sep 17 00:00:00 2001 From: PrplHaz4 Date: Mon, 30 Mar 2020 17:14:59 -0400 Subject: [PATCH 1/3] Fix permission setting on Channels Currently, permission settings on Channels are not taken into account prior to returning `{UserName} is not permitted to access Library {ItemName}.`. Whether or not a user can see items within the Channel is solely dependent on `EnableAllFolders`, so you cannot view a plugin's Channels unless you can also see ALL libraries. This PR enables does two things for Channel-providing Plugins: 1. Fixes functionality of "EnableAllChannels" 2. Allows users with Channel permissions to access all folders within that Channel I'm not 100% sure on 2 but I wasn't able to see an obvious way to propagate permissions downward into specific Folders inside a Channel. I tested on a fairly simple library with two channel-providing plugins (ServerWMC, LazyMan) and it seems to work, but this behavior should also be tested by someone with more content/collections. --- MediaBrowser.Api/UserLibrary/ItemsService.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index c7b5051712..46082cdc3f 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -214,6 +214,10 @@ namespace MediaBrowser.Api.UserLibrary } bool isInEnabledFolder = user.Policy.EnabledFolders.Any(i => new Guid(i) == item.Id); + + // Assume all folders inside an EnabledChannel are enabled + isInEnabledFolder = isInEnabledFolder || user.Policy.EnabledChannels.Any(i => new Guid(i) == item.Id); + var collectionFolders = _libraryManager.GetCollectionFolders(item); foreach (var collectionFolder in collectionFolders) { @@ -225,7 +229,7 @@ namespace MediaBrowser.Api.UserLibrary } } - if (!(item is UserRootFolder) && !user.Policy.EnableAllFolders && !isInEnabledFolder) + if (!(item is UserRootFolder) && !user.Policy.EnableAllFolders && !isInEnabledFolder && !user.Policy.EnableAllChannels) { Logger.LogWarning("{UserName} is not permitted to access Library {ItemName}.", user.Name, item.Name); return new QueryResult From b05e04c0cb349e5e9e07ecc585b1388f71b85427 Mon Sep 17 00:00:00 2001 From: PrplHaz4 Date: Sun, 5 Apr 2020 06:42:15 -0400 Subject: [PATCH 2/3] Collapse IsInEnabledFolder to single expression Co-Authored-By: Vasily --- MediaBrowser.Api/UserLibrary/ItemsService.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 46082cdc3f..7f24a5722d 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -213,10 +213,9 @@ namespace MediaBrowser.Api.UserLibrary request.IncludeItemTypes = "Playlist"; } - bool isInEnabledFolder = user.Policy.EnabledFolders.Any(i => new Guid(i) == item.Id); - - // Assume all folders inside an EnabledChannel are enabled - isInEnabledFolder = isInEnabledFolder || user.Policy.EnabledChannels.Any(i => new Guid(i) == item.Id); + bool isInEnabledFolder = user.Policy.EnabledFolders.Any(i => new Guid(i) == item.Id) || + // Assume all folders inside an EnabledChannel are enabled + user.Policy.EnabledChannels.Any(i => new Guid(i) == item.Id); var collectionFolders = _libraryManager.GetCollectionFolders(item); foreach (var collectionFolder in collectionFolders) From 46453549b5aa59f5f3e0f30fa858236ccb54832b Mon Sep 17 00:00:00 2001 From: PrplHaz4 Date: Sun, 5 Apr 2020 07:26:21 -0400 Subject: [PATCH 3/3] Start line with Boolean --- MediaBrowser.Api/UserLibrary/ItemsService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 7f24a5722d..22e4eea0b8 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -213,9 +213,9 @@ namespace MediaBrowser.Api.UserLibrary request.IncludeItemTypes = "Playlist"; } - bool isInEnabledFolder = user.Policy.EnabledFolders.Any(i => new Guid(i) == item.Id) || + bool isInEnabledFolder = user.Policy.EnabledFolders.Any(i => new Guid(i) == item.Id) // Assume all folders inside an EnabledChannel are enabled - user.Policy.EnabledChannels.Any(i => new Guid(i) == item.Id); + || user.Policy.EnabledChannels.Any(i => new Guid(i) == item.Id); var collectionFolders = _libraryManager.GetCollectionFolders(item); foreach (var collectionFolder in collectionFolders)