-
Notifications
You must be signed in to change notification settings - Fork 55
Description
This is one of the tasks on the way to complete migration to V5 standards #435
Overview
Our current implementation of invite related endpoints doesn't follow the RESTful style and has a very custom logic. Also, there are some minor peculiarities that blocks us from implementing new features. So in this challenge we would like to update existent endpoints to be more RESTful and support some minor features we need.
Individual requirements
- All the invite related endpoints have to use the next URL route as a base:
/v5/projects/:projectId(\\d+)/invites(currently we have a mix of slightly different routes like/v5/projects/:projectId(\\d+)/members/invite(s)).
POST /v5/projects/:projectId(\\d+)/invites
- [Question 1] As a part of the Connect App task, we want to avoid calling
Member Service searchendpoint client-side. To achieve this, we also have to change the body of create invite endpoint from:to{ "userId": 123, // we send userId now "email": "[email protected]" }though, the downside is that such a request would be less RESTfull as{ "handle": "userhandle", // send handle instead of userId "email": "[email protected]" }MemberInvitemodel doesn't havehandlefield and has onlyuserIdfield, see https://github.com/topcoder-platform/tc-project-service/blob/develop/src/models/projectMemberInvite.js#L9.- NOTE that if we send
handleinstead ofuserIdthan it would the job of Project Service to call Member Service search endpoint to finduserIdfor the invited user.
- NOTE that if we send
GET /v5/projects/:projectId(\\d+)/invites
As per Topcoder V5 standard in the GET endpoints, we always read data from the ES first and if no data is found, we fallback to DB.
-
Currently, when request data from ES we use a very specific query which has 2 disadvantages (see code):
- we must specify the maximum number of invites to return as we use inner hits, but we want to get all of them
- this specific query is slower than if we just retrieve the whole project by
id - So we have to replace it with a simple request to get the whole
projectdocument from ES. And just get the list of invites from the project document asproject.invites. If the project is not found in ES or the list of invites is empty, we should fallback to DB.
-
Currently, only users who can "view" the project may call this endpoint. We should allow ALL logged-in the users to call this endpoint. But, we should filter the results:
- users who can "view" the project should get the full list of invites as they can do now
- users who cannot "view" the project but is logged-in should get only invitations for themself. So if invitation has
userIdORemailof the currently authorized user, we return such invitations. - non-logged-in users should get error 401
GET /v5/projects/:projectId(\\d+)/invites/:inviteId(\\d+)
- Currently, this endpoint doesn't use
inviteIdand it gets the invite for the user who is calling this endpoint. Instead, it should return an invitation byinviteId. - Any user who can "view" project can get an invitation by id.
- We should get data from ES first, and fallback to DB if invitation with the requested id is not found in ES.
PATCH /v5/projects/:projectId(\\d+)/invites/:inviteId(\\d+)
- Use
PATCHinstead ofPUT - This endpoint should find an invitation to update
inviteIdinstead ofuserIdoremail - Only
statuscan be updated - The rest logic should be kept as it is, like: we should only be able to update invites in status
pendingorrequestedand so on.
DELETE /v5/projects/:projectId(\\d+)/invites/:inviteId(\\d+)
- [Question 2] We don't have such an endpoint and look like we still don't need it as instead of deleting we updated invitations to have the status
canceled.
References
- Create a new "PUT /v4/projects/:projectId(\\d+)/members/invites/:inviteId" endpoint #422
- Cannot remove invitation by email after masking emails appirio-tech/connect-app#3413
- When successfully invite user by email it's not cleared from the input appirio-tech/connect-app#3412
- Masking email to be shown under Team management container appirio-tech/connect-app#3388