Skip to content

Commit bf6d90c

Browse files
committed
feat(model): Add HierarchyFilter class
This class allows defining filters for elements in the hierarchy based on element IDs. This is going to be used to select only the elements a user has access to. Signed-off-by: Oliver Heger <[email protected]>
1 parent b21de68 commit bf6d90c

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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. It
31+
* is, however, possible that permissions on specific elements are restricted on lower levels by explicit role
32+
* assignments. Such elements must then be excluded.
33+
*
34+
* There is also the case that an element on a higher level is implicitly accessible because the user has permissions
35+
* on lower levels. Such elements must be added to results, but not their child elements.
36+
*
37+
* All these conditions are reflected by the different properties of this class.
38+
*/
39+
data class HierarchyFilter(
40+
/**
41+
* A [Map] with the IDs of elements that should be included together with their child element, grouped by their
42+
* hierarchy level.
43+
*/
44+
val transitiveIncludes: Map<Int, List<CompoundHierarchyId>>,
45+
46+
/**
47+
* A [Map] with the IDs of elements that should be included, but without their child elements, grouped by their
48+
* hierarchy level.
49+
*/
50+
val nonTransitiveIncludes: Map<Int, List<CompoundHierarchyId>>,
51+
52+
/**
53+
* A [Map] with the IDs of elements that should be excluded because of restricted permissions on lower levels of
54+
* the hierarchy, grouped by their hierarchy level.
55+
*/
56+
val excludes: Map<Int, List<CompoundHierarchyId>>,
57+
58+
/**
59+
* A flag whether this filter is a wildcard filter, which means that it matches all elements in the hierarchy.
60+
* If this is *true*, all other properties can be ignored, and no filter condition needs to be generated. Filters
61+
* of this type are created if the user has superuser rights.
62+
*/
63+
val isWildcard: Boolean = false
64+
) {
65+
companion object {
66+
/**
67+
* A special instance of [HierarchyFilter] that declares itself as a wildcard filter and therefore matches
68+
* all entities. This filter should not alter any query results.
69+
*/
70+
val WILDCARD = HierarchyFilter(
71+
transitiveIncludes = emptyMap(),
72+
nonTransitiveIncludes = emptyMap(),
73+
excludes = emptyMap(),
74+
isWildcard = true
75+
)
76+
}
77+
}

0 commit comments

Comments
 (0)