|
2 | 2 |
|
3 | 3 | import io.openaev.aop.RBACAspect; |
4 | 4 | import io.openaev.database.model.*; |
| 5 | +import io.openaev.database.repository.EvaluationRepository; |
| 6 | +import io.openaev.database.repository.ObjectiveRepository; |
5 | 7 | import io.openaev.rest.exception.ElementNotFoundException; |
6 | 8 | import io.openaev.rest.inject.service.InjectService; |
7 | 9 | import io.openaev.rest.injector_contract.InjectorContractService; |
@@ -46,12 +48,18 @@ public class PermissionService { |
46 | 48 |
|
47 | 49 | private static final EnumSet<ResourceType> RESOURCES_USING_PARENT_PERMISSION = |
48 | 50 | EnumSet.of( |
49 | | - ResourceType.INJECT, ResourceType.NOTIFICATION_RULE, ResourceType.INJECTOR_CONTRACT); |
| 51 | + ResourceType.INJECT, |
| 52 | + ResourceType.NOTIFICATION_RULE, |
| 53 | + ResourceType.INJECTOR_CONTRACT, |
| 54 | + ResourceType.OBJECTIVE, |
| 55 | + ResourceType.EVALUATION); |
50 | 56 |
|
51 | 57 | private final GrantService grantService; |
52 | 58 | private final InjectService injectService; |
53 | 59 | private final NotificationRuleService notificationRuleService; |
54 | 60 | private final InjectorContractService injectorContractService; |
| 61 | + private final ObjectiveRepository objectiveRepository; |
| 62 | + private final EvaluationRepository evaluationRepository; |
55 | 63 |
|
56 | 64 | @Transactional |
57 | 65 | public boolean hasPermission( |
@@ -190,6 +198,27 @@ private Target resolveTarget( |
190 | 198 | return new Target(ic.getPayload().getId(), ResourceType.PAYLOAD, action); |
191 | 199 | } |
192 | 200 | return new Target(ic.getId(), ResourceType.INJECTOR_CONTRACT, action); |
| 201 | + } else if (resourceType == ResourceType.OBJECTIVE) { |
| 202 | + Objective objective = |
| 203 | + objectiveRepository |
| 204 | + .findById(resourceId) |
| 205 | + .orElseThrow( |
| 206 | + () -> new ElementNotFoundException("Objective not found with id: " + resourceId)); |
| 207 | + // parent action rule: anything non-READ becomes WRITE on the parent |
| 208 | + Action parentAction = (action == Action.READ) ? Action.READ : Action.WRITE; |
| 209 | + return new Target( |
| 210 | + objective.getParentResourceId(), objective.getParentResourceType(), parentAction); |
| 211 | + } else if (resourceType == ResourceType.EVALUATION) { |
| 212 | + Evaluation evaluation = |
| 213 | + evaluationRepository |
| 214 | + .findById(resourceId) |
| 215 | + .orElseThrow( |
| 216 | + () -> |
| 217 | + new ElementNotFoundException("Evaluation not found with id: " + resourceId)); |
| 218 | + // parent action rule: anything non-READ becomes WRITE on the parent |
| 219 | + Action parentAction = (action == Action.READ) ? Action.READ : Action.WRITE; |
| 220 | + return new Target( |
| 221 | + evaluation.getParentResourceId(), evaluation.getParentResourceType(), parentAction); |
193 | 222 | } |
194 | 223 | return new Target(resourceId, resourceType, action); |
195 | 224 | } |
|
0 commit comments