Skip to content

Commit

Permalink
Added: Service exist invited users
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Apr 10, 2024
1 parent c0f6554 commit 55caf9e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,18 @@ public ResponseEntity<String> 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<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public List<String> 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 {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/de/samply/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public Set<User> 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> project = projectRepository.findByCode(projectCode);
if (project.isEmpty()) {
Expand Down

0 comments on commit 55caf9e

Please sign in to comment.