Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 3e1ac4e

Browse files
author
sachin-maheshwari
authored
Merge pull request #6 from topcoder-platform/develop
Shapeup#2: v5 user fortification
2 parents 19c3820 + e5005be commit 3e1ac4e

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ The following parameters can be set in config files or in env variables:
2929
- TOKEN_CACHE_TIME: The token cache time
3030
- SLEEP_TIME: The pause time between two create operations, default value: 1000 ms
3131
- UBAHN_API_URL: The ubahn api url, default value: 'https://api.topcoder-dev.com/v5'
32-
- MEMBERS_API_URL: The topcoder member api url, default value: 'https://api.topcoder-dev.com/v5/members'
32+
- MEMBERS_API_URL: The topcoder member api url, default value: 'https://api.topcoder-dev.com/v5/members'. Not in use anymore. Retained for any future use
3333
- ATTRIBUTE_GROUP_NAME: The attribute group name
34-
- SKILL_PROVIDER_NAME: The skill provider name
34+
- SKILL_PROVIDER_NAME: The skill provider name. Not in use anymore. Retained for any future use
3535
- ORGANIZATION_NAME: The organization name
3636

3737
There is a `/health` endpoint that checks for the health of the app. This sets up an expressjs server and listens on the environment variable `PORT`. It's not part of the configuration file and needs to be passed as an environment variable

VERIFICATION.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"credential":{"activationCode":"FOOBAR2","resetToken":null,"hasPassword":false},
2020
"profiles":null,
2121
"status":"A",
22-
"country":null,
22+
"country":{
23+
"isoAlpha3Code": "IND"
24+
},
2325
"regSource":"null",
2426
"utmSource":"null",
2527
"utmMedium":"null",
@@ -44,5 +46,5 @@ docker exec -it identity-data-processor_kafka /opt/kafka/bin/kafka-console-produ
4446
`{"recipients":[],"notificationType":"useractivation"}`
4547
3. Watch the app console, It will show error message.
4648
4. write message:
47-
`{"topic":"identity.notification.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"id":"90064000","modifiedBy":null,"modifiedAt":"2021-01-05T14:01:40.336Z","createdBy":null,"createdAt":"2021-01-05T14:01:40.336Z","handle":"theuserhandle","email":"[email protected]","firstName":"theuserfirstname","lastName":"theuserlastname","credential":{"activationCode":"FOOBAR2","resetToken":null,"hasPassword":false},"profiles":null,"status":"A","country":null,"regSource":"null","utmSource":"null","utmMedium":"null","utmCampaign":"null","roles":null,"ssoLogin":false,"active":true,"profile":null,"emailActive":true}}`
49+
`{"topic":"identity.notification.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"id":"90064000","modifiedBy":null,"modifiedAt":"2021-01-05T14:01:40.336Z","createdBy":null,"createdAt":"2021-01-05T14:01:40.336Z","handle":"theuserhandle","email":"[email protected]","firstName":"theuserfirstname","lastName":"theuserlastname","credential":{"activationCode":"FOOBAR2","resetToken":null,"hasPassword":false},"profiles":null,"status":"A","country":{"isoAlpha3Code":"IND"},"regSource":"null","utmSource":"null","utmMedium":"null","utmCampaign":"null","roles":null,"ssoLogin":false,"active":true,"profile":null,"emailActive":true}}`
4850
5. Watch the app console, It will show message successfully handled.

src/common/helper.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async function getUbahnToken () {
5353
/**
5454
* Function to get M2M token
5555
* (U-Bahn APIs only)
56+
* * Unused for now. Retained for any future use
5657
* @returns {Promise}
5758
*/
5859
async function getTopcoderToken () {
@@ -96,6 +97,7 @@ async function getAttributes (token) {
9697

9798
/**
9899
* Get all skills
100+
* * Unused for now. Retained for any future use
99101
* @param {String} token
100102
* @returns a map (name -> id)
101103
*/
@@ -108,6 +110,7 @@ async function getSkillProviderId (token) {
108110

109111
/**
110112
* Get the skillId
113+
* * Unused for now. Retained for any future use
111114
* @param {String} skillProviderId
112115
* @param {String} name
113116
* @param {String} token
@@ -121,6 +124,7 @@ async function getSkillId (skillProviderId, name, token) {
121124

122125
/**
123126
* Returns the member location for the member handle
127+
* * Unused for now. Retained for any future use
124128
* @param {String} handle The member handle
125129
*/
126130
async function getMemberLocation (handle, token) {
@@ -131,6 +135,7 @@ async function getMemberLocation (handle, token) {
131135

132136
/**
133137
* Returns the member's skills
138+
* * Unused for now. Retained for any future use
134139
* @param {String} handle The member's handle
135140
*/
136141
async function getMemberSkills (handle, token) {
@@ -185,6 +190,7 @@ async function createExternalProfile (userId, body, token) {
185190

186191
/**
187192
* Create user skill
193+
* * Unused for now. Retained for any future use
188194
* @param {String} userId
189195
* @param {String} skillId
190196
* @param {String} metricValue

src/services/ProcessorService.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ const helper = require('../common/helper')
1313
*/
1414
async function processCreate (message) {
1515
const ubahnToken = await helper.getUbahnToken()
16-
const topcoderToken = await helper.getTopcoderToken()
1716
const organizationId = await helper.getOrganizationId(ubahnToken)
1817
const attributes = await helper.getAttributes(ubahnToken)
19-
const skillProviderId = await helper.getSkillProviderId(ubahnToken)
20-
const location = await helper.getMemberLocation(message.payload.handle, topcoderToken)
21-
const userSkills = await helper.getMemberSkills(message.payload.handle, topcoderToken)
18+
const location = message.payload.country.isoAlpha3Code
2219

2320
const userId = await helper.createUser(_.pick(message.payload, 'handle', 'firstName', 'lastName'), ubahnToken)
2421
logger.info(`user: ${message.payload.handle} created`)
@@ -37,16 +34,6 @@ async function processCreate (message) {
3734
helper.sleep()
3835
await helper.createUserAttribute(userId, _.get(attributes, 'location'), location, ubahnToken)
3936
logger.info('user attribute: location created')
40-
for (const userSkill of userSkills) {
41-
helper.sleep()
42-
const skillId = await helper.getSkillId(skillProviderId, userSkill.name, ubahnToken)
43-
if (skillId) {
44-
await helper.createUserSkill(userId, skillId, userSkill.score, ubahnToken)
45-
logger.info(`user skill: ${userSkill.name}:${userSkill.score} created`)
46-
} else {
47-
throw Error(`Cannot find skill with name ${userSkill.name} and skill provider id ${skillProviderId} in u-bahn`)
48-
}
49-
}
5037
}
5138

5239
processCreate.schema = {
@@ -59,7 +46,10 @@ processCreate.schema = {
5946
id: Joi.string().required(),
6047
handle: Joi.string().required(),
6148
firstName: Joi.string().required(),
62-
lastName: Joi.string().required()
49+
lastName: Joi.string().required(),
50+
country: Joi.object().keys({
51+
isoAlpha3Code: Joi.string().required()
52+
}).required().unknown(true)
6353
}).required().unknown(true)
6454
}).required().unknown(true)
6555
}

0 commit comments

Comments
 (0)