Skip to content

Revert "Add new endpoint GET /taas-teams/me" #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions docs/Topcoder-bookings-api.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -4694,36 +4694,6 @@
}
},
"response": []
},
{
"name": "GET /taas-teams/me",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{token_member}}"
}
],
"url": {
"raw": "{{URL}}/taas-teams/me?enrich=true",
"host": [
"{{URL}}"
],
"path": [
"taas-teams",
"me"
],
"query": [
{
"key": "enrich",
"value": "true"
}
]
}
},
"response": []
}
]
},
Expand Down
58 changes: 1 addition & 57 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1894,59 +1894,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'

/taas-teams/me:
get:
tags:
- Teams
description: |
Return details about the current user.
security:
- bearerAuth: []
parameters:
- in: query
name: enrich
required: false
schema:
type: boolean
description: whether to return enriched data or not.
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/UbahnUser'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: Not authenticated
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description: Not Found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/health:
get:
tags:
Expand Down Expand Up @@ -2772,13 +2719,10 @@ components:
example: 'xxx@xxx.com'
ProjectMember:
type: object
example: {"id": 14329, "userId": 40159097, "role": "customer", "createdAt": "2021-02-24T12:34:45.074Z", "updatedAt": "2021-02-24T12:34:45.075Z", "createdBy": -101, "updatedBy": -101, "handle": "tester1234", "photoURL": null, "workingHourStart": "9:00", "workingHourEnd": "17:00", "timeZone": "Asia/Kolkata", "email": "xxx@xxx.com"}
example: {"id": 14329, "userId": 40159097, "role": "customer", "createdAt": "2021-02-24T12:34:45.074Z", "updatedAt": "2021-02-24T12:34:45.075Z", "createdBy": -101, "updatedBy": -101, "handle": "tester1234", "photoURL": null, "workingHourStart": "9:00", "workingHourEnd": "17:00", "timeZone": "Asia/Kolkata", "email": "sathya.jayabal@gmail.com"}
ProjectMemberInvite:
type: object
example: {"createdAt": "2021-02-24T11:02:12.673Z", "deletedAt": null, "role": "customer", "updatedBy": -101, "createdBy": -101, "id": 3686, "projectId": 16705, "userId": 23008602, "email": null, "deletedBy": null, "updatedAt": "2021-02-24T11:02:12.674Z", "status": "pending"}
UbahnUser:
type: object
example: {"lastName": "DeLaurentis", "updatedBy": "tcAdmin", "achievements": [{"certifierId": "certifierId", "updatedBy": "tcAdmin", "createdBy": "tc-user", "certifiedDate": "2020-05-04T07:36:28.036Z", "created": "2020-05-13T08:44:27.244Z", "name": "Topcoder", "id": "a49e1013-fd42-4c08-bc12-492510cadb96", "achievementsProviderId": "ce05133f-129e-484d-9ef9-72bf51ff81f9", "uri": "http://www.google.com/xx", "updated": "2021-01-05T10:58:32.429Z", "userId": "0bcb0d86-09bb-410a-b2b1-fba90d1a7699", "achievementprovider": {"updatedBy": "tcAdmin", "createdBy": "tc-user", "created": "2020-05-13T08:42:41.877Z", "name": "achievementsProviders_02", "id": "ce05133f-129e-484d-9ef9-72bf51ff81f9", "updated": "2021-01-05T10:58:32.341Z"}}], "created": "2020-05-05T10:18:03.882Z", "handle": "lazybaer", "skills": [{"certifierId": null, "skillId": "d67f35c3-fa42-4866-a0f9-0a4b84fcf4a9", "updatedBy": "tcAdmin", "createdBy": "lazybaer", "certifiedDate": null, "created": "2020-10-23T16:22:11.208Z", "skill": {"updatedBy": "tcAdmin", "skillprovider": {"updatedBy": "tcAdmin", "createdBy": "TonyJ", "created": "2020-08-31T12:30:00.543Z", "name": "Wipro Digital", "id": "26fb37b1-5f9f-4727-baa9-f3c87de84ab1", "updated": "2021-01-05T10:58:32.836Z"}, "createdBy": "0", "created": "2020-09-01T21:59:21.554Z", "skillProviderId": "26fb37b1-5f9f-4727-baa9-f3c87de84ab1", "name": "GitHub", "externalId": null, "id": "d67f35c3-fa42-4866-a0f9-0a4b84fcf4a9", "uri": null, "updated": "2021-01-05T10:58:33.332Z"}, "metricValue": null, "id": "8a84c1b4-1884-4a3c-90b2-eb86bf469bb6", "updated": "2021-01-05T10:58:34.080Z", "userId": "0bcb0d86-09bb-410a-b2b1-fba90d1a7699"}], "firstName": "Christopher", "externalProfiles": [{"organizationId": "0d2320f9-be61-4ba4-973e-edc3bb682a69", "updatedBy": "tcAdmin", "createdBy": "TonyJ", "isInactive": false, "created": "2020-08-31T12:30:38.495Z", "organization": {"updatedBy": "tcAdmin", "createdBy": "TonyJ", "created": "2020-08-31T12:29:58.081Z", "name": "Wipro Digital", "skillProviders": [{"organizationId": "0d2320f9-be61-4ba4-973e-edc3bb682a69", "updatedBy": "tcAdmin", "createdBy": "TonyJ", "created": "2020-08-31T12:30:08.410Z", "skillProviderId": "26fb37b1-5f9f-4727-baa9-f3c87de84ab1", "id": "5b26cdd3-fe68-4b30-85c5-ceaf280bd688", "updated": "2021-01-05T10:58:32.919Z"}], "id": "0d2320f9-be61-4ba4-973e-edc3bb682a69", "updated": "2021-01-05T10:58:32.261Z"}, "externalId": "8547899", "id": "870af97b-8c3b-4659-92d6-cac126bbe9de", "uri": null, "updated": "2021-01-05T10:58:32.724Z", "userId": "0bcb0d86-09bb-410a-b2b1-fba90d1a7699"}], "createdBy": "tc-Copilot", "attributes": [{"attributeId": "d709276a-80c3-491c-9b29-a4f065b2a56f", "updatedBy": "tcAdmin", "createdBy": "tc-Admin", "created": "2020-05-13T08:19:13.709Z", "id": "21de9324-900d-41ea-b127-f297dfb9a873", "attribute": {"updatedBy": "tcAdmin", "attributegroup": {"organizationId": "36ed815b-3da1-49f1-a043-aaed0a4e81ad", "updatedBy": "tc-Admin", "createdBy": "tc-Admin", "created": "2020-05-13T07:15:01.215Z", "name": "group 03", "id": "84634bbd-8191-40cf-a03e-9962d7e39fda", "updated": "2020-05-13T07:16:20.636Z"}, "createdBy": "tc-Admin", "created": "2020-05-13T07:32:03.128Z", "name": "Billing Account", "id": "d709276a-80c3-491c-9b29-a4f065b2a56f", "attributeGroupId": "84634bbd-8191-40cf-a03e-9962d7e39fda", "updated": "2021-01-05T10:58:32.604Z"}, "value": "74314457", "updated": "2021-01-05T10:58:33.739Z", "userId": "0bcb0d86-09bb-410a-b2b1-fba90d1a7699"}], "id": "0bcb0d86-09bb-410a-b2b1-fba90d1a7699", "updated": "2021-01-05T10:58:32.113Z"}
Error:
required:
- message
Expand Down
37 changes: 17 additions & 20 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,18 +598,17 @@ function encodeQueryString (queryObj, nesting = '') {
}

/**
* Function to list users by external id.
* @param {Integer} externalId the legacy user id
* @param {Boolean} enrich whether to return enriched data or not
* @returns {Array} the users found
* Function to get user ids
* @param {Integer} userId user id from jwt token
* @returns {String} user id.
*/
async function listUsersByExternalId (externalId, enrich = false) {
async function getUserIds (userId) {
const token = await getM2MUbahnToken()
const q = {
enrich,
enrich: true,
externalProfile: {
organizationId: config.ORG_ID,
externalId
externalId: userId
}
}
const url = `${config.TC_API}/users?${encodeQueryString(q)}`
Expand All @@ -618,22 +617,21 @@ async function listUsersByExternalId (externalId, enrich = false) {
.set('Authorization', `Bearer ${token}`)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
localLogger.debug({ context: 'listUserByExternalId', message: `response body: ${JSON.stringify(res.body)}` })
localLogger.debug({ context: 'getUserIds', message: `response body: ${JSON.stringify(res.body)}` })
return res.body
}

/**
* Function to get user by external id.
* @param {Integer} externalId the legacy user id
* @param {Boolean} enrich whether to return enriched data or not
* @returns {Object} the user
* Function to get user id
* @param {Integer} userId user id from jwt token
* @returns {String} user id.
*/
async function getUserByExternalId (externalId, enrich) {
const users = await listUsersByExternalId(externalId, enrich)
if (_.isEmpty(users)) {
throw new errors.NotFoundError(`externalId: ${externalId} "user" not found`)
async function getUserId (userId) {
const ids = await getUserIds(userId)
if (_.isEmpty(ids)) {
throw new errors.NotFoundError(`userId: ${userId} "user" not found`)
}
return users[0]
return ids[0].id
}

/**
Expand Down Expand Up @@ -885,7 +883,7 @@ async function getSkillById (skillId) {
}

/**
* Encapsulate the getUserByExternalId function.
* Encapsulate the getUserId function.
* Make sure a user exists in ubahn(/v5/users) and return the id of the user.
*
* In the case the user does not exist in /v5/users but can be found in /v3/users
Expand All @@ -896,7 +894,7 @@ async function getSkillById (skillId) {
*/
async function ensureUbahnUserId (currentUser) {
try {
return (await getUserByExternalId(currentUser.userId, true)).id
return await getUserId(currentUser.userId)
} catch (err) {
if (!(err instanceof errors.NotFoundError)) {
throw err
Expand Down Expand Up @@ -1140,7 +1138,6 @@ module.exports = {
}
return ensureUbahnUserId({ userId })
},
getUserByExternalId,
getM2MToken,
getM2MUbahnToken,
postEvent,
Expand Down
12 changes: 1 addition & 11 deletions src/controllers/TeamController.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ async function deleteMember (req, res) {
res.status(HttpStatus.NO_CONTENT).end()
}

/**
* Return details about the current user.
* @param req the request
* @param res the response
*/
async function getMe (req, res) {
res.send(await service.getMe(req.authUser, req.query))
}

module.exports = {
searchTeams,
getTeam,
Expand All @@ -100,6 +91,5 @@ module.exports = {
addMembers,
searchMembers,
searchInvites,
deleteMember,
getMe
deleteMember
}
8 changes: 0 additions & 8 deletions src/routes/TeamRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ module.exports = {
scopes: [constants.Scopes.READ_TAAS_TEAM]
}
},
'/taas-teams/me': {
get: {
controller: 'TeamController',
method: 'getMe',
auth: 'jwt',
scopes: [constants.Scopes.READ_TAAS_TEAM]
}
},
'/taas-teams/:id': {
get: {
controller: 'TeamController',
Expand Down
21 changes: 1 addition & 20 deletions src/services/TeamService.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,24 +513,6 @@ deleteMember.schema = Joi.object().keys({
projectMemberId: Joi.number().integer().required()
}).required()

/**
* Return details about the current user.
*
* @param {Object} currentUser the user who perform this operation.
* @params {Object} criteria the search criteria
* @returns {Object} the user data for current user
*/
async function getMe (currentUser, criteria) {
return helper.getUserByExternalId(currentUser.userId, criteria.enrich)
}

getMe.schema = Joi.object().keys({
currentUser: Joi.object().required(),
criteria: Joi.object().keys({
enrich: Joi.boolean()
}).required()
}).required()

module.exports = {
searchTeams,
getTeam,
Expand All @@ -539,6 +521,5 @@ module.exports = {
addMembers,
searchMembers,
searchInvites,
deleteMember,
getMe
deleteMember
}