diff --git a/airbyte-api/src/main/openapi/config.yaml b/airbyte-api/src/main/openapi/config.yaml index 1af53da8a37..d232908c34c 100644 --- a/airbyte-api/src/main/openapi/config.yaml +++ b/airbyte-api/src/main/openapi/config.yaml @@ -3372,6 +3372,30 @@ paths: "422": $ref: "#/components/responses/InvalidInputResponse" + /v1/users/get_by_email: + post: + tags: + - user + summary: Find Airbyte user by email + operationId: getUserByEmail + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/UserEmailRequestBody" + required: true + responses: + "200": + description: Successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/UserRead" + "404": + $ref: "#/components/responses/NotFoundResponse" + "422": + $ref: "#/components/responses/InvalidInputResponse" + /v1/users/get_or_create_by_auth_id: post: tags: @@ -6801,6 +6825,14 @@ components: authUserId: type: string + UserEmailRequestBody: + type: object + required: + - email + properties: + email: + type: string + UserCreate: type: object required: diff --git a/airbyte-commons-server/src/main/java/io/airbyte/commons/server/handlers/UserHandler.java b/airbyte-commons-server/src/main/java/io/airbyte/commons/server/handlers/UserHandler.java index a5f8ec7f96f..d0c17bd6269 100644 --- a/airbyte-commons-server/src/main/java/io/airbyte/commons/server/handlers/UserHandler.java +++ b/airbyte-commons-server/src/main/java/io/airbyte/commons/server/handlers/UserHandler.java @@ -15,6 +15,7 @@ import io.airbyte.api.model.generated.PermissionType; import io.airbyte.api.model.generated.UserAuthIdRequestBody; import io.airbyte.api.model.generated.UserCreate; +import io.airbyte.api.model.generated.UserEmailRequestBody; import io.airbyte.api.model.generated.UserGetOrCreateByAuthIdResponse; import io.airbyte.api.model.generated.UserIdRequestBody; import io.airbyte.api.model.generated.UserRead; @@ -169,6 +170,24 @@ public UserRead getUserByAuthId(final UserAuthIdRequestBody userAuthIdRequestBod } } + /** + * Retrieves the user by email. + * + * @param userEmailRequestBody The {@link UserEmailRequestBody} that contains the email. + * @return The user associated with the email. + * @throws IOException if unable to retrieve the user. + * @throws JsonValidationException if unable to retrieve the user. + */ + public UserRead getUserByEmail(final UserEmailRequestBody userEmailRequestBody) + throws IOException, JsonValidationException, ConfigNotFoundException { + final Optional user = userPersistence.getUserByEmail(userEmailRequestBody.getEmail()); + if (user.isPresent()) { + return buildUserRead(user.get()); + } else { + throw new ConfigNotFoundException(ConfigSchema.USER, String.format("User not found by email request: %s", userEmailRequestBody)); + } + } + private UserRead buildUserRead(final UUID userId) throws ConfigNotFoundException, IOException, JsonValidationException { final Optional user = userPersistence.getUser(userId); if (user.isEmpty()) { diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/UserApiController.java b/airbyte-server/src/main/java/io/airbyte/server/apis/UserApiController.java index 3c380fcd3ce..d16dae03a4c 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/apis/UserApiController.java +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/UserApiController.java @@ -15,6 +15,7 @@ import io.airbyte.api.model.generated.OrganizationUserReadList; import io.airbyte.api.model.generated.UserAuthIdRequestBody; import io.airbyte.api.model.generated.UserCreate; +import io.airbyte.api.model.generated.UserEmailRequestBody; import io.airbyte.api.model.generated.UserGetOrCreateByAuthIdResponse; import io.airbyte.api.model.generated.UserIdRequestBody; import io.airbyte.api.model.generated.UserRead; @@ -70,6 +71,14 @@ public UserRead getUserByAuthId(final UserAuthIdRequestBody userAuthIdRequestBod return ApiHelper.execute(() -> userHandler.getUserByAuthId(userAuthIdRequestBody)); } + @Post("/get_by_email") + @SecuredUser + @Secured({ADMIN, SELF}) + @Override + public UserRead getUserByEmail(final UserEmailRequestBody userEmailRequestBody) { + return ApiHelper.execute(() -> userHandler.getUserByEmail(userEmailRequestBody)); + } + @Post("/delete") @SecuredUser @Secured({ADMIN, SELF})