Skip to content

proxy endpoint for member suggestion #393

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
Jul 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
2 changes: 2 additions & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ module.exports = {
TOPCODER_USERS_API: process.env.TOPCODER_USERS_API || 'https://api.topcoder-dev.com/v3/users',
// the api to find topcoder members
TOPCODER_MEMBERS_API: process.env.TOPCODER_MEMBERS_API || 'https://api.topcoder-dev.com/v5/members',
// the v3 api to find topcoder members
TOPCODER_MEMBERS_API_V3: process.env.TOPCODER_MEMBERS_API_V3 || 'https://api.topcoder-dev.com/v3/members',
// rate limit of requests to user api
MAX_PARALLEL_REQUEST_TOPCODER_USERS_API: process.env.MAX_PARALLEL_REQUEST_TOPCODER_USERS_API || 100,

Expand Down
243 changes: 242 additions & 1 deletion docs/Topcoder-bookings-api.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "15f10b58-dda5-4aaf-96e5-061a5c901717",
"_postman_id": "87477d86-2d08-40b6-93c6-99a394193e28",
"name": "Topcoder-bookings-api",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
Expand Down Expand Up @@ -19312,6 +19312,247 @@
}
]
},
{
"name": "Member Suggestion",
"item": [
{
"name": "get member suggestion successfully with administrator",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test('Status code is 200', function () {\r",
" pm.response.to.have.status(200);\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{token_administrator}}"
}
],
"url": {
"raw": "{{URL}}/taas-teams/members-suggest/maxceem",
"host": [
"{{URL}}"
],
"path": [
"taas-teams",
"members-suggest",
"maxceem"
]
}
},
"response": []
},
{
"name": "get member suggestion successfully with booking manager",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test('Status code is 200', function () {\r",
" pm.response.to.have.status(200);\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{token_bookingManager}}"
}
],
"url": {
"raw": "{{URL}}/taas-teams/members-suggest/isbilir",
"host": [
"{{URL}}"
],
"path": [
"taas-teams",
"members-suggest",
"isbilir"
]
}
},
"response": []
},
{
"name": "get member suggestion with connect manager",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test('Status code is 403', function () {\r",
" pm.response.to.have.status(403);\r",
" const response = pm.response.json()\r",
" pm.expect(response.message).to.eq(\"You are not allowed to perform this action!\")\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{token_connect_manager_pshahcopmanag2}}"
}
],
"url": {
"raw": "{{URL}}/taas-teams/members-suggest/isbilir",
"host": [
"{{URL}}"
],
"path": [
"taas-teams",
"members-suggest",
"isbilir"
]
}
},
"response": []
},
{
"name": "get member suggestion with member",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test('Status code is 403', function () {\r",
" pm.response.to.have.status(403);\r",
" const response = pm.response.json()\r",
" pm.expect(response.message).to.eq(\"You are not allowed to perform this action!\")\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{token_member}}"
}
],
"url": {
"raw": "{{URL}}/taas-teams/members-suggest/isbilir",
"host": [
"{{URL}}"
],
"path": [
"taas-teams",
"members-suggest",
"isbilir"
]
}
},
"response": []
},
{
"name": "get member suggestion with m2m",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test('Status code is 403', function () {\r",
" pm.response.to.have.status(403);\r",
" const response = pm.response.json()\r",
" pm.expect(response.message).to.eq(\"You are not allowed to perform this action!\")\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{token_m2m_all_job}}"
}
],
"url": {
"raw": "{{URL}}/taas-teams/members-suggest/isbilir",
"host": [
"{{URL}}"
],
"path": [
"taas-teams",
"members-suggest",
"isbilir"
]
}
},
"response": []
},
{
"name": "get member suggestion with invalid token",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test('Status code is 401', function () {\r",
" pm.response.to.have.status(401);\r",
" const response = pm.response.json()\r",
" pm.expect(response.message).to.eq(\"Invalid Token.\")\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer invalid"
}
],
"url": {
"raw": "{{URL}}/taas-teams/members-suggest/isbilir",
"host": [
"{{URL}}"
],
"path": [
"taas-teams",
"members-suggest",
"isbilir"
]
}
},
"response": []
}
]
},
{
"name": "GET /taas-teams",
"request": {
Expand Down
61 changes: 61 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3296,6 +3296,41 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error"
/taas-teams/members-suggest/{fragment}:
get:
tags:
- Teams
description: |
Returns suggested members for the given handle fragment
security:
- bearerAuth: []
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/SuggestedMember"
"401":
description: Not authenticated
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
"403":
description: Forbidden
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
"500":
description: Internal Server Error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/taas-roles:
post:
tags:
Expand Down Expand Up @@ -5404,6 +5439,32 @@ components:
type: string
format: uuid
description: "The user Id who updated the role last time.(Will get the user info from the token)"
SuggestedMember:
properties:
userId:
type: number
example: 40157055
description: the user id
handle:
type: string
example: maxceemdev
description: the user handle
photoURL:
type: string
example: https://topcoder-dev-media.s3.amazonaws.com/member/profile/maxceem13-1587184611143.jpeg
description: the photo url
firstName:
type: string
example: Max
description: the firstname of the user
lastName:
type: string
example: Max
description: the lastname of the user
maxRating:
type: number
example: 1200
description: the maximum rating of the user
RoleRequestBody:
required:
- name
Expand Down
23 changes: 22 additions & 1 deletion src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,26 @@ function removeTextFormatting (text) {
return text
}

/**
* Function to get member suggestions
* @param {string} fragment the handle fragment
* @return the request result
*/
async function getMembersSuggest (fragment) {
const token = await getM2MToken()
const url = `${config.TOPCODER_MEMBERS_API_V3}/_suggest/${encodeURIComponent(fragment)}`
const res = await request
.get(url)
.set('Authorization', `Bearer ${token}`)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
localLogger.debug({
context: 'getMembersSuggest',
message: `response body: ${JSON.stringify(res.body)}`
})
return res.body
}

module.exports = {
getParamFromCliArgs,
promptUser,
Expand Down Expand Up @@ -2048,5 +2068,6 @@ module.exports = {
substituteStringByObject,
createProject,
getMemberGroups,
removeTextFormatting
removeTextFormatting,
getMembersSuggest
}
12 changes: 11 additions & 1 deletion src/controllers/TeamController.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ async function searchSkills (req, res) {
res.send(result.result)
}

/**
* Suggest members
* @param req the request
* @param res the response
*/
async function suggestMembers (req, res) {
res.send(await service.suggestMembers(req.authUser, req.params.fragment))
}

module.exports = {
searchTeams,
getTeam,
Expand All @@ -159,5 +168,6 @@ module.exports = {
getSkillsByJobDescription,
roleSearchRequest,
createTeam,
searchSkills
searchSkills,
suggestMembers
}
Loading