| | | 1 | | using Jellyfin.Database.Implementations.Entities; |
| | | 2 | | using Jellyfin.Extensions; |
| | | 3 | | using MediaBrowser.Controller.Entities; |
| | | 4 | | using MediaBrowser.Controller.Library; |
| | | 5 | | |
| | | 6 | | namespace Emby.Server.Implementations.Library.Search; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Builds the access filter that decides which items a search may return for a user. |
| | | 10 | | /// </summary> |
| | | 11 | | internal static class SearchQueryAccessFilter |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Builds an access filter carrying the search's library access and type filters. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="user">The user the search runs for.</param> |
| | | 17 | | /// <param name="query">The search query.</param> |
| | | 18 | | /// <param name="libraryManager">The library manager.</param> |
| | | 19 | | /// <returns>The access filter.</returns> |
| | | 20 | | public static InternalItemsQuery Build(User user, SearchProviderQuery query, ILibraryManager libraryManager) |
| | | 21 | | { |
| | | 22 | | // The type filters have to travel with the access filter: a by-name item belongs to no |
| | | 23 | | // library, so it carries no TopParentId to match, and the library filter only knows to |
| | | 24 | | // exempt it when the query says those types are wanted. A search scoped to a parent gets |
| | | 25 | | // no exemption because a by-name item has no parent to descend from either. |
| | 0 | 26 | | var accessFilter = new InternalItemsQuery(user) |
| | 0 | 27 | | { |
| | 0 | 28 | | IncludeItemTypes = query.IncludeItemTypes, |
| | 0 | 29 | | ExcludeItemTypes = query.ExcludeItemTypes, |
| | 0 | 30 | | IncludeItemsByName = !query.ParentId.HasValue || query.ParentId.Value.IsEmpty() |
| | 0 | 31 | | }; |
| | | 32 | | |
| | | 33 | | // ConfigureUserAccess populates TopParentIds for the libraries the user may open. |
| | 0 | 34 | | libraryManager.ConfigureUserAccess(accessFilter, user); |
| | | 35 | | |
| | 0 | 36 | | return accessFilter; |
| | | 37 | | } |
| | | 38 | | } |