|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 The ORT Server Authors (See <https://github.com/eclipse-apoapsis/ort-server/blob/main/NOTICE>) |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + * License-Filename: LICENSE |
| 18 | + */ |
| 19 | + |
| 20 | +package org.eclipse.apoapsis.ortserver.model.util |
| 21 | + |
| 22 | +import org.eclipse.apoapsis.ortserver.model.CompoundHierarchyId |
| 23 | + |
| 24 | +/** |
| 25 | + * A data class that holds information about elements in the hierarchy the current user has access to. A filter |
| 26 | + * instance is created based on the user's permissions and can be used to generate `WHERE` conditions for database |
| 27 | + * queries to only select accessible entities. |
| 28 | + * |
| 29 | + * In ORT Server's role model, permissions granted on higher levels of the hierarchy inherit down to lower levels. |
| 30 | + * Therefore, if a user can access a specific element, the elements below in the hierarchy are accessible as well. |
| 31 | + * |
| 32 | + * There is also the case that an element on a higher level is implicitly accessible because the user has permissions |
| 33 | + * on lower levels. Such elements must be added to results, but not their child elements. |
| 34 | + * |
| 35 | + * All these conditions are reflected by the different properties of this class. |
| 36 | + */ |
| 37 | +data class HierarchyFilter( |
| 38 | + /** |
| 39 | + * A [Map] with the IDs of elements that should be included together with their child element, grouped by their |
| 40 | + * hierarchy level. |
| 41 | + */ |
| 42 | + val transitiveIncludes: Map<Int, List<CompoundHierarchyId>>, |
| 43 | + |
| 44 | + /** |
| 45 | + * A [Map] with the IDs of elements that should be included, but without their child elements, grouped by their |
| 46 | + * hierarchy level. |
| 47 | + */ |
| 48 | + val nonTransitiveIncludes: Map<Int, List<CompoundHierarchyId>>, |
| 49 | + |
| 50 | + /** |
| 51 | + * A flag whether this filter is a wildcard filter, which means that it matches all elements in the hierarchy. |
| 52 | + * If this is *true*, all other properties can be ignored, and no filter condition needs to be generated. Filters |
| 53 | + * of this type are created if the user has superuser rights. |
| 54 | + */ |
| 55 | + val isWildcard: Boolean = false |
| 56 | +) { |
| 57 | + companion object { |
| 58 | + /** |
| 59 | + * A special instance of [HierarchyFilter] that declares itself as a wildcard filter and therefore matches |
| 60 | + * all entities. This filter should not alter any query results. |
| 61 | + */ |
| 62 | + val WILDCARD = HierarchyFilter( |
| 63 | + transitiveIncludes = emptyMap(), |
| 64 | + nonTransitiveIncludes = emptyMap(), |
| 65 | + isWildcard = true |
| 66 | + ) |
| 67 | + } |
| 68 | +} |
0 commit comments