From 55caf9e3b53b6a63025b6fc76a877993ea045753 Mon Sep 17 00:00:00 2001 From: djuarezgf Date: Wed, 10 Apr 2024 21:22:59 +0200 Subject: [PATCH] Added: Service exist invited users --- CHANGELOG.md | 3 ++- src/main/java/de/samply/app/ProjectManagerConst.java | 2 ++ .../java/de/samply/app/ProjectManagerController.java | 12 ++++++++++++ .../samply/token/DataShieldTokenManagerService.java | 2 +- src/main/java/de/samply/user/UserService.java | 4 ++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81fd22e..ceaa9b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [0.0.1 - 2024-04-05] +## [0.0.1 - 2024-04-10] ### Added - First version of the project - Spring Application @@ -122,3 +122,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Email Types: NEW_PROJECT_ACCEPTED, NEW_VOTUM, REQUEST_TECHNICAL_APPROVAL, NEW_PUBLICATION - Email config for types NEW_PROJECT_ACCEPTED, NEW_VOTUM, REQUEST_TECHNICAL_APPROVAL, NEW_PUBLICATION - Fetch label of application form, label and script +- Service exist invited users diff --git a/src/main/java/de/samply/app/ProjectManagerConst.java b/src/main/java/de/samply/app/ProjectManagerConst.java index 0e1ccd1..4189205 100644 --- a/src/main/java/de/samply/app/ProjectManagerConst.java +++ b/src/main/java/de/samply/app/ProjectManagerConst.java @@ -80,6 +80,7 @@ public class ProjectManagerConst { public final static String FETCH_DATASHIELD_STATUS_ACTION = "FETCH_DATASHIELD_STATUS"; public final static String FETCH_USERS_FOR_AUTOCOMPLETE_ACTION = "FETCH_USERS_FOR_AUTOCOMPLETE"; public final static String FETCH_PROJECT_USERS_ACTION = "FETCH_PROJECT_USERS"; + public final static String EXIST_INVITED_USERS_ACTION = "EXIST_INVITED_USERS"; public final static String FETCH_PROJECT_CONFIGURATIONS_ACTION = "FETCH_PROJECT_CONFIGURATIONS"; public final static String EXISTS_AUTHENTICATION_SCRIPT_ACTION = "EXISTS_AUTHENTICATION_SCRIPT"; public final static String FETCH_CURRENT_PROJECT_CONFIGURATION_ACTION = "FETCH_CURRENT_PROJECT_CONFIGURATION"; @@ -160,6 +161,7 @@ public class ProjectManagerConst { public final static String FETCH_ALL_REGISTERED_BRIDGEHEADS = "/bridgeheads"; public final static String FETCH_USERS_FOR_AUTOCOMPLETE = "/autocomplete-users"; public final static String FETCH_PROJECT_USERS = "/project-users"; + public final static String EXIST_INVITED_USERS = "/exist-invited-users"; // REST Parameters public final static String PROJECT_CODE = "project-code"; diff --git a/src/main/java/de/samply/app/ProjectManagerController.java b/src/main/java/de/samply/app/ProjectManagerController.java index 13fabec..c1d8f14 100644 --- a/src/main/java/de/samply/app/ProjectManagerController.java +++ b/src/main/java/de/samply/app/ProjectManagerController.java @@ -1084,6 +1084,18 @@ public ResponseEntity fetchProjectUsers( return convertToResponseEntity(() -> this.userService.fetchProjectUsers(projectCode, bridgehead)); } + @RoleConstraints(projectRoles = {ProjectRole.BRIDGEHEAD_ADMIN}) + @StateConstraints(projectStates = {ProjectState.DEVELOP, ProjectState.PILOT, ProjectState.FINAL}) + @FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.USER_MODULE) + @FrontendAction(action = ProjectManagerConst.EXIST_INVITED_USERS_ACTION) + @GetMapping(value = ProjectManagerConst.EXIST_INVITED_USERS) + public ResponseEntity existInvitedUsers( + @ProjectCode @RequestParam(name = ProjectManagerConst.PROJECT_CODE) String projectCode, + @Bridgehead @RequestParam(name = ProjectManagerConst.BRIDGEHEAD) String bridgehead + ) { + return convertToResponseEntity(() -> this.userService.existInvatedUsers(projectCode, bridgehead)); + } + private ResponseEntity convertToResponseEntity(RunnableWithException runnable) { try { diff --git a/src/main/java/de/samply/token/DataShieldTokenManagerService.java b/src/main/java/de/samply/token/DataShieldTokenManagerService.java index ffb4bd9..6e66d62 100644 --- a/src/main/java/de/samply/token/DataShieldTokenManagerService.java +++ b/src/main/java/de/samply/token/DataShieldTokenManagerService.java @@ -127,7 +127,7 @@ public List fetchProjectBridgeheads(String projectCode, String bridgehea } ProjectRole userProjectRole = projectBridgeheadUser.get().getProjectRole(); if (userProjectRole == ProjectRole.DEVELOPER || userProjectRole == ProjectRole.PILOT) { - return List.of(bridgehead); + return (filter.apply(projectBridgeheadUser.get().getProjectBridgehead())) ? List.of(bridgehead) : List.of(); } else if (userProjectRole == ProjectRole.FINAL) { return projectBridgeheadRepository.findByProject(project).stream().filter(filter::apply).map(projectBridgehead -> projectBridgehead.getBridgehead()).toList(); } else { diff --git a/src/main/java/de/samply/user/UserService.java b/src/main/java/de/samply/user/UserService.java index 96dfa47..b3fcb3c 100644 --- a/src/main/java/de/samply/user/UserService.java +++ b/src/main/java/de/samply/user/UserService.java @@ -165,6 +165,10 @@ public Set fetchProjectUsers(@NotNull String projectCode, @NotNull String }).stream().map(DtoFactory::convert).collect(Collectors.toSet()); } + public boolean existInvatedUsers(@NotNull String projectCode, @NotNull String bridgehead) throws UserServiceException { + return !fetchProjectUsers(projectCode, bridgehead).isEmpty(); + } + private ProjectBridgehead fetchProjectBridgehead(String projectCode, String bridgehead) throws UserServiceException { Optional project = projectRepository.findByCode(projectCode); if (project.isEmpty()) {