diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/UnauthApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/UnauthApi.java index 52ddd41..ede6d1b 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/UnauthApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/UnauthApi.java @@ -2,6 +2,7 @@ package enseirb.myinpulse.controller; import enseirb.myinpulse.model.Entrepreneur; import enseirb.myinpulse.service.EntrepreneurApiService; +import enseirb.myinpulse.service.UtilsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -14,13 +15,15 @@ import org.springframework.web.bind.annotation.*; public class UnauthApi { private final EntrepreneurApiService entrepreneurApiService; + private final UtilsService utilsService; @Autowired - UnauthApi(EntrepreneurApiService entrepreneurApiService) { + UnauthApi(EntrepreneurApiService entrepreneurApiService, UtilsService utilsService) { this.entrepreneurApiService = entrepreneurApiService; + this.utilsService = utilsService; } - @GetMapping("/unauth/finalize") + @PostMapping("/unauth/finalize") public void createAccount(@AuthenticationPrincipal Jwt principal) { boolean sneeStatus; if (principal.getClaimAsString("sneeStatus") != null) { @@ -46,6 +49,13 @@ public class UnauthApi { course, sneeStatus, true); + entrepreneurApiService.createAccount(e); } + + @GetMapping("/unauth/check-if-not-pending") + public Boolean checkAccountStatus(@AuthenticationPrincipal Jwt principal) { + // Throws 404 if user not found + return utilsService.checkEntrepreneurNotPending(principal.getClaimAsString("email")); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java index f7412de..b8822e5 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java @@ -72,4 +72,10 @@ public class UtilsService { return false; } } + + public Boolean checkEntrepreneurNotPending(String email) { + // Throws 404 if user not found + User user = userService.getUserByEmail(email); + return !user.isPending(); + } } diff --git a/documentation/openapi/src/main.yaml b/documentation/openapi/src/main.yaml index 6239610..0f86e22 100644 --- a/documentation/openapi/src/main.yaml +++ b/documentation/openapi/src/main.yaml @@ -79,6 +79,10 @@ paths: $ref: "./unauthApi.yaml#/paths/~1unauth~1finalize" /unauth/request-join/{projectId}: $ref: "./unauthApi.yaml#/paths/~1unauth~1request-join~1{projectId}" + /unauth/request-admin-role: + $ref: "./unauthApi.yaml#/paths/~1unauth~1request-admin-role" + /unauth/check-if-not-pending: + $ref: "./unauthApi.yaml#/paths/~1unauth~1check-if-not-pending" # _ ____ __ __ ___ _ _ _ ____ ___ # / \ | _ \| \/ |_ _| \ | | / \ | _ \_ _| diff --git a/documentation/openapi/src/unauthApi.yaml b/documentation/openapi/src/unauthApi.yaml index 5150d99..fc7d555 100644 --- a/documentation/openapi/src/unauthApi.yaml +++ b/documentation/openapi/src/unauthApi.yaml @@ -53,7 +53,7 @@ paths: description: Bad Token - Invalid Keycloack configuration. /unauth/request-admin-role: post: - summary: Request to join an existing project + summary: Request to become an admin description: Submits a request for the authenticated user (keycloack authenticated) to become an admin. Their role is then changed to admin in server and Keycloak. This requires approval from a project admin. tags: - Unauth API @@ -65,4 +65,26 @@ paths: "401": description: Unauthorized. "403": - description: Bad Token - Invalid Keycloack configuration. \ No newline at end of file + description: Bad Token - Invalid Keycloack configuration. + + /unauth/check-if-not-pending: + get: + summary: Returns a boolean of whether the user's account is not pending + description: Returns a boolean with value `true` if the user's account is not pending and `false` if it is. + tags: + - Unauth API + responses: + "200": + description: Accepted - Become admin request submitted and pending approval. + content: + application/json: + schema: + type: boolean + "400": + description: Bad Request - Invalid project ID format or already member/request pending. + "401": + description: Unauthorized. + "404": + description: Bad Request - User not found in database. + "403": + description: Bad Token - Invalid Keycloack configuration.