Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8370777

Browse files
committedApr 12, 2021
#7 - Set external profile active or not
1 parent c5621e1 commit 8370777

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The following parameters can be set in config files or in env variables:
3535
- ATTRIBUTE_GROUP_NAME: The attribute group name
3636
- SKILL_PROVIDER_NAME: The skill provider name. Not in use anymore. Retained for any future use
3737
- ORGANIZATION_NAME: The organization name
38+
- MEMBER_PROFILE_URL_PREFIX: The member's profile url prefix. Defaults to `'https://www.topcoder.com/members/'` - don't forget the `/` at the end
3839

3940
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
4041

‎VERIFICATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ docker exec -it identity-data-processor_kafka /opt/kafka/bin/kafka-console-produ
1313
4. Write message: `{"topic":"identity.notification.create","originator":"identity-service","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"id":"10000001","modifiedBy":null,"modifiedAt":null,"createdBy":null,"createdAt":null,"handle":"theuserhandle","email":"theuserhandle@gmail.com","firstName":"User","lastName":"Member","credential":{"activationCode":"ABCDEFGHIJK","resetToken":null,"hasPassword":true},"profiles":null,"status":"U","country":{"code":"040","name":"Austria","isoAlpha2Code":"AT","isoAlpha3Code":"AUT"},"regSource":null,"utmSource":null,"utmMedium":null,"utmCampaign":null,"roles":null,"ssoLogin":false,"active":false,"profile":null,"emailActive":false}}`
1414
5. Watch the app console. It will show message successfully handled. The log should look like:
1515
```
16-
info: user: tezsachin78033 created
16+
info: user: theuserhandle created
1717
debug: Sleeping for 1000 ms
1818
info: external profile: 36ed815b-3da1-49f1-a043-aaed0a4e81ad created
1919
debug: Sleeping for 1000 ms

‎config/default.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ module.exports = {
3030
ORGANIZATION_NAME: process.env.ORGANIZATION_NAME,
3131
ATTRIBUTE_GROUP_NAME: process.env.ATTRIBUTE_GROUP_NAME,
3232
SKILL_PROVIDER_NAME: process.env.SKILL_PROVIDER_NAME,
33-
MEMBERS_API_URL: process.env.MEMBERS_API_URL || 'https://api.topcoder-dev.com/v5/members'
33+
MEMBERS_API_URL: process.env.MEMBERS_API_URL || 'https://api.topcoder-dev.com/v5/members',
34+
35+
MEMBER_PROFILE_URL_PREFIX: process.env.MEMBER_PROFILE_URL_PREFIX || 'https://www.topcoder.com/members/'
3436
}

‎src/common/helper.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ async function createExternalProfile (userId, body, token) {
223223
await axios.post(`${config.UBAHN_API_URL}/users/${userId}/externalProfiles`, body, { headers: { Authorization: `Bearer ${token}` } })
224224
}
225225

226+
/**
227+
* Update external profile
228+
* @param {String} userId
229+
* @param {String} organizationId
230+
* @param {Object} body
231+
* @param {String} token
232+
*/
233+
async function updateExternalProfile (userId, organizationId, body, token) {
234+
await axios.patch(`${config.UBAHN_API_URL}/users/${userId}/externalProfiles/${organizationId}`, body, { headers: { Authorization: `Bearer ${token}` } })
235+
}
236+
226237
/**
227238
* Create user skill
228239
* * Unused for now. Retained for any future use
@@ -251,5 +262,6 @@ module.exports = {
251262
createExternalProfile,
252263
createUserSkill,
253264
getUserId,
254-
updateUserAttribute
265+
updateUserAttribute,
266+
updateExternalProfile
255267
}

‎src/services/ProcessorService.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const _ = require('lodash')
66
const Joi = require('@hapi/joi')
77
const logger = require('../common/logger')
88
const helper = require('../common/helper')
9-
10-
const MEMBER_PROFILE_URL_PREFIX = 'https://www.topcoder.com/members/'
9+
const config = require('config')
1110

1211
/**
1312
* Process identity create entity message
@@ -60,7 +59,12 @@ async function processCreate (message, ubahnToken) {
6059
const userId = await helper.createUser(_.pick(message.payload, 'handle', 'firstName', 'lastName'), ubahnToken)
6160
logger.info(`user: ${message.payload.handle} created`)
6261
helper.sleep()
63-
await helper.createExternalProfile(userId, { organizationId, uri: `${MEMBER_PROFILE_URL_PREFIX}${message.payload.handle}`, externalId: message.payload.id, isInactive: false }, ubahnToken)
62+
await helper.createExternalProfile(userId, {
63+
organizationId,
64+
uri: `${config.MEMBER_PROFILE_URL_PREFIX}${message.payload.handle}`,
65+
externalId: message.payload.id,
66+
isInactive: !message.payload.active
67+
}, ubahnToken)
6468
logger.info(`external profile: ${organizationId} created`)
6569
helper.sleep()
6670
await helper.createUserAttribute(userId, _.get(attributes, 'isAvailable'), message.payload.active.toString(), ubahnToken)
@@ -90,8 +94,12 @@ async function processCreate (message, ubahnToken) {
9094
* @param {String} ubahnToken the auth token
9195
*/
9296
async function processUpdate (message, userId, ubahnToken) {
97+
const organizationId = await helper.getOrganizationId(ubahnToken)
9398
const attributes = await helper.getAttributes(ubahnToken)
9499

100+
await helper.updateExternalProfile(userId, organizationId, { isInactive: !message.payload.active }, ubahnToken)
101+
logger.info('user attribute: isAvailable updated')
102+
95103
await helper.updateUserAttribute(userId, _.get(attributes, 'isAvailable'), message.payload.active.toString(), ubahnToken)
96104
logger.info('user attribute: isAvailable updated')
97105
}

0 commit comments

Comments
 (0)
This repository has been archived.