From 0093416e6c3154d189934b4008262c98a9377459 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 26 Feb 2025 12:04:12 +0400 Subject: [PATCH] #6 -- Check permissions to the variable --- .../ru/ulstu/fc/rule/service/VariableService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/fc/rule/service/VariableService.java b/src/main/java/ru/ulstu/fc/rule/service/VariableService.java index 20cc790..732aebb 100644 --- a/src/main/java/ru/ulstu/fc/rule/service/VariableService.java +++ b/src/main/java/ru/ulstu/fc/rule/service/VariableService.java @@ -14,15 +14,18 @@ public class VariableService { private final VariableRepository variableRepository; private final ProjectService projectService; - public VariableService(VariableRepository variableRepository, ProjectService projectService) { + public VariableService(VariableRepository variableRepository, + ProjectService projectService) { this.variableRepository = variableRepository; this.projectService = projectService; } public Variable getById(Integer id) { - return variableRepository + Variable variable = variableRepository .findById(id) .orElseThrow(() -> new RuntimeException("Variable not found by id")); + checkIsCurrentUserVariableWithThrow(variable); + return variable; } public Variable save(VariableForm variableForm) { @@ -65,4 +68,8 @@ public class VariableService { public List getAllByProject(Integer projectId) { return variableRepository.getByProject(projectService.getById(projectId)); } + + public void checkIsCurrentUserVariableWithThrow(Variable variable) { + projectService.checkIsCurrentUserProjectWithThrow(variable.getProject()); + } }