[BUG] Incorrect logic of creating user in database
Change Type:
-
Feature -
Bugfix -
Refactoring
Context and Scope
Currently, the user creation possible only while adding them in a group.
The endpoint POST /groups/:group_email/members
does a lot of work. For example, it:
- Defines the type of member (user or group);
- Tries to find the user. Creates the new record in db if it does not exist;
- Adds the member into the group.
Request structure
The endpoint gets the body of format:
{
"email": "test-user@osdu-gcp.go3-nrg.projects.epam.com",
"role": "MEMBER"
}
Where:
-
email
can be both user or group email -
role
can only be MEMBER or OWNER
Error codes
- If
group_email
does not exist, endpoint will return 404 - If the group was passed in the body and it does not exist, endpoint will return 404
- If passed member already a member of the group, endpoint will return 409
Decision
Add a new logic that will be clear for end user (e.g. user creation endpoint)
Rational
The only endpoint that could create user is POST /groups/:group_email/members
. This is not correct in terms of UX, because the user was not created by dedicated endpoint. This behaviour is a bit confusing.
Consequences
To resolve the bug, we may:
- Add a new endpoint e.g.
POST /members/{user}
to create the user in database - Remove the user creation logic in the
POST /groups/:group_email/members
endpoint