aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Library/Search/SearchQueryAccessFilter.cs
diff options
context:
space:
mode:
authorKGT1 <kilian.gamn@gmx.de>2026-10-17 16:51:55 +0200
committerGitHub <noreply@github.com>2026-10-17 16:51:55 +0200
commit292b13d1daf36316274211a8b3c13385c60efdb5 (patch)
tree1204df8423af2f317dbf3171aa7a42b1413b4e2e /Emby.Server.Implementations/Library/Search/SearchQueryAccessFilter.cs
parent0be145c4e202bac0edc36b769f8b4db2232ad216 (diff)
parent08c2ba6e0b6499122822f1c5b18bc426104538b4 (diff)
Merge branch 'jellyfin:master' into removeGenericConfigurationEndpoint
Diffstat (limited to 'Emby.Server.Implementations/Library/Search/SearchQueryAccessFilter.cs')
-rw-r--r--Emby.Server.Implementations/Library/Search/SearchQueryAccessFilter.cs38
1 files changed, 38 insertions, 0 deletions
diff --git a/Emby.Server.Implementations/Library/Search/SearchQueryAccessFilter.cs b/Emby.Server.Implementations/Library/Search/SearchQueryAccessFilter.cs
new file mode 100644
index 0000000000..6e3f01de13
--- /dev/null
+++ b/Emby.Server.Implementations/Library/Search/SearchQueryAccessFilter.cs
@@ -0,0 +1,38 @@
+using Jellyfin.Database.Implementations.Entities;
+using Jellyfin.Extensions;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Library;
+
+namespace Emby.Server.Implementations.Library.Search;
+
+/// <summary>
+/// Builds the access filter that decides which items a search may return for a user.
+/// </summary>
+internal static class SearchQueryAccessFilter
+{
+ /// <summary>
+ /// Builds an access filter carrying the search's library access and type filters.
+ /// </summary>
+ /// <param name="user">The user the search runs for.</param>
+ /// <param name="query">The search query.</param>
+ /// <param name="libraryManager">The library manager.</param>
+ /// <returns>The access filter.</returns>
+ public static InternalItemsQuery Build(User user, SearchProviderQuery query, ILibraryManager libraryManager)
+ {
+ // The type filters have to travel with the access filter: a by-name item belongs to no
+ // library, so it carries no TopParentId to match, and the library filter only knows to
+ // exempt it when the query says those types are wanted. A search scoped to a parent gets
+ // no exemption because a by-name item has no parent to descend from either.
+ var accessFilter = new InternalItemsQuery(user)
+ {
+ IncludeItemTypes = query.IncludeItemTypes,
+ ExcludeItemTypes = query.ExcludeItemTypes,
+ IncludeItemsByName = !query.ParentId.HasValue || query.ParentId.Value.IsEmpty()
+ };
+
+ // ConfigureUserAccess populates TopParentIds for the libraries the user may open.
+ libraryManager.ConfigureUserAccess(accessFilter, user);
+
+ return accessFilter;
+ }
+}