Skip to content

Commit

Permalink
Add get user by email endpoint (#10230)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencecho committed Dec 7, 2023
1 parent 07f5699 commit 13b286c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
32 changes: 32 additions & 0 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -6801,6 +6825,14 @@ components:
authUserId:
type: string

UserEmailRequestBody:
type: object
required:
- email
properties:
email:
type: string

UserCreate:
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> 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> user = userPersistence.getUser(userId);
if (user.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit 13b286c

Please sign in to comment.