Add Result<> in all methods response in Registry controller.
This commit is contained in:
parent
a8acb08826
commit
4804ab40c8
|
@ -4,6 +4,7 @@ import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.Conflict
|
|||
import eu.dnetlib.uoaauthorizationlibrary.authorization.security.AuthorizationService;
|
||||
import eu.dnetlib.uoausermanagment.dto.*;
|
||||
import eu.dnetlib.uoausermanagment.entities.RoleVerification;
|
||||
import eu.dnetlib.uoausermanagment.entities.VerificationType;
|
||||
import eu.dnetlib.uoausermanagment.services.RoleManagementService;
|
||||
import eu.dnetlib.uoausermanagment.services.RoleVerificationService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
@ -73,10 +74,10 @@ public class RegistryController {
|
|||
*/
|
||||
@RequestMapping(value = "/invite/{type}/{id}/manager", method = RequestMethod.POST)
|
||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, @AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
||||
public ResponseEntity<Invitation> inviteManager(HttpServletRequest request, @PathVariable("type") String type, @PathVariable("id") String id,
|
||||
public ResponseEntity<Result<Invitation>> inviteManager(HttpServletRequest request, @PathVariable("type") String type, @PathVariable("id") String id,
|
||||
@RequestBody EmailDetails details) {
|
||||
if(!roleManagementService.isManager(type, id, details.getEmail().getRecipient(), request)) {
|
||||
return ResponseEntity.ok(roleVerificationService.inviteManager(details, type, id));
|
||||
return ResponseEntity.ok(new Result<>(authorizationService.manager(type, id), roleVerificationService.inviteManager(details, type, id)));
|
||||
}
|
||||
throw new ConflictException("User has been already manager of this " + type);
|
||||
}
|
||||
|
@ -87,10 +88,10 @@ public class RegistryController {
|
|||
*/
|
||||
@RequestMapping(value = "/invite/{type}/{id}/member", method = RequestMethod.POST)
|
||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, @AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
||||
public ResponseEntity<Invitation> inviteMember(HttpServletRequest request, @PathVariable("type") String type, @PathVariable("id") String id,
|
||||
public ResponseEntity<Result<Invitation>> inviteMember(HttpServletRequest request, @PathVariable("type") String type, @PathVariable("id") String id,
|
||||
@RequestBody EmailDetails details) {
|
||||
if(!roleManagementService.isMember(type, id, details.getEmail().getRecipient(), request)) {
|
||||
return ResponseEntity.ok(roleVerificationService.inviteMember(details, type, id));
|
||||
return ResponseEntity.ok(new Result<>(authorizationService.member(type, id), roleVerificationService.inviteMember(details, type, id)));
|
||||
}
|
||||
throw new ConflictException("User has been already member of this " + type);
|
||||
}
|
||||
|
@ -121,8 +122,8 @@ public class RegistryController {
|
|||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
||||
@RequestMapping(value = "/invite/{type}/{id}/managers", method = RequestMethod.GET)
|
||||
public ResponseEntity<List<String>> getInvitedManagers(@PathVariable("type") String type, @PathVariable("id") String id) {
|
||||
return ResponseEntity.ok(roleVerificationService.getInvitedManagers(type, id));
|
||||
public ResponseEntity<Result<List<String>>> getInvitedManagers(@PathVariable("type") String type, @PathVariable("id") String id) {
|
||||
return ResponseEntity.ok(new Result<>(authorizationService.manager(type, id), roleVerificationService.getInvitedMembers(type, id)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -132,8 +133,8 @@ public class RegistryController {
|
|||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
||||
@RequestMapping(value = "/invite/{type}/{id}/members", method = RequestMethod.GET)
|
||||
public ResponseEntity<List<String>> getInviteMembers(@PathVariable("type") String type, @PathVariable("id") String id) {
|
||||
return ResponseEntity.ok(roleVerificationService.getInvitedMembers(type, id));
|
||||
public ResponseEntity<Result<List<String>>> getInviteMembers(@PathVariable("type") String type, @PathVariable("id") String id) {
|
||||
return ResponseEntity.ok(new Result<>(authorizationService.member(type, id), roleVerificationService.getInvitedMembers(type, id)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,8 +142,13 @@ public class RegistryController {
|
|||
*/
|
||||
@PreAuthorize("@Verification.isMyVerification(#id)")
|
||||
@RequestMapping(value = "/verification/{id}", method = RequestMethod.GET)
|
||||
public ResponseEntity<RoleVerification> getVerification(@PathVariable("id") String id) {
|
||||
return ResponseEntity.ok(roleVerificationService.getRoleVerification(id));
|
||||
public ResponseEntity<Result<RoleVerification>> getVerification(@PathVariable("id") String id) {
|
||||
RoleVerification roleVerification = roleVerificationService.getRoleVerification(id);
|
||||
if(roleVerification.getVerificationType().equals(VerificationType.MANAGER)) {
|
||||
return ResponseEntity.ok(new Result<>(authorizationService.manager(roleVerification.getType(), roleVerification.getEntity()), roleVerification));
|
||||
} else {
|
||||
return ResponseEntity.ok(new Result<>(authorizationService.member(roleVerification.getType(), roleVerification.getEntity()), roleVerification));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -222,7 +228,7 @@ public class RegistryController {
|
|||
* Get infos of the curators of a type(Community, etc.)
|
||||
*/
|
||||
@RequestMapping(value = "/{type}/{id}/members", method = RequestMethod.GET)
|
||||
public ResponseEntity<Result<?>> getMembers(HttpServletRequest request, @PathVariable("type") String type, @PathVariable("id") String id) {
|
||||
public ResponseEntity<Result<UserDetails[]>> getMembers(HttpServletRequest request, @PathVariable("type") String type, @PathVariable("id") String id) {
|
||||
return ResponseEntity.ok(new Result<>(authorizationService.member(type, id), roleManagementService.getAllMembers(type, id, request)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue