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

Commit a9c62ca

Browse files
#5 - Support multiple orgs for user creation
1 parent 7486776 commit a9c62ca

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

config/default.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ module.exports = {
2929
// When a user is not found, should we proceed to create the user or treat it as error
3030
CREATE_MISSING_USER_FLAG: process.env.CREATE_MISSING_USER_FLAG === 'true',
3131

32-
// The Topcoder organization to associate with a new user
33-
TOPCODER_ORGANIZATION_NAME: process.env.TOPCODER_ORGANIZATION_NAME || 'topcoder',
34-
3532
AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token', // Auth0 credentials
3633
AUTH0_UBAHN_AUDIENCE: process.env.AUTH0_UBAHN_AUDIENCE || 'https://u-bahn.topcoder.com/',
3734
AUTH0_TOPCODER_AUDIENCE: process.env.AUTH0_TOPCODER_AUDIENCE || 'https://m2m.topcoder-dev.com/',

src/services/ProcessorService.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,18 @@ async function createUserInTopcoder (user) {
5959
/**
6060
* Creates the user in UBahn api as well as Topcoder's Users api
6161
* @param {Object} user The user to create
62+
* @param {String} organizationId The org id to associate the new user with
6263
*/
63-
async function createUser (user) {
64+
async function createUser (user, organizationId) {
6465
// Create the user in Topcoder
6566
const topcoderUserId = await createUserInTopcoder(user)
6667

6768
// Create the user in UBahn api
6869
const ubahnUserId = await createUserInUbahn(user)
6970

70-
// Get the topcoder organization
71-
const topcoderOrg = await helper.getUbahnSingleRecord('/organizations', {
72-
name: config.TOPCODER_ORGANIZATION_NAME
73-
})
74-
7571
// Now, proceed to map the topcoder user id with the ubahn user id
7672
await helper.createUbahnRecord(`/users/${ubahnUserId}/externalProfiles`, {
77-
organizationId: topcoderOrg.id,
73+
organizationId,
7874
externalId: topcoderUserId
7975
})
8076

@@ -85,9 +81,10 @@ async function createUser (user) {
8581
/**
8682
* Function to get user id
8783
* @param {Object} user
84+
* @param {Object} organizationId The org id to associate a new user with
8885
* @returns {Promise}
8986
*/
90-
async function getUserId (user) {
87+
async function getUserId (user, organizationId) {
9188
const record = await helper.getUbahnSingleRecord('/users', {
9289
handle: user.handle
9390
}, true)
@@ -97,7 +94,7 @@ async function getUserId (user) {
9794

9895
// No user found. Should we create the user or treat it as an error?
9996
if (config.CREATE_MISSING_USER_FLAG) {
100-
return createUser(user)
97+
return createUser(user, organizationId)
10198
} else {
10299
throw new Error(`Could not find user with handle ${user.handle}`)
103100
}
@@ -194,11 +191,12 @@ async function createUserAttributes (userId, record) {
194191
* Function to process record
195192
* @param {Object} record
196193
* @param {Array} failedRecord then failed records container
194+
* @param {String} organizationId The org id to associate a new user with
197195
* @returns {Promise}
198196
*/
199-
async function processCreateRecord (record, failedRecord) {
197+
async function processCreateRecord (record, failedRecord, organizationId) {
200198
try {
201-
const userId = await getUserId(record)
199+
const userId = await getUserId(record, organizationId)
202200
await createUserSkill(userId, record.skillProviderName, record.skillName, record.skillCertifierId, record.skillCertifiedDate, record.metricValue)
203201
await createAchievement(userId, record.achievementsProviderName, record.achievementsCertifierId, record.achievementsCertifiedDate, record.achievementsName, record.achievementsUri)
204202
await createUserAttributes(userId, record)
@@ -221,7 +219,7 @@ async function processCreate (message) {
221219
const records = helper.parseExcel(file)
222220
const failedRecord = []
223221

224-
await Promise.map(records, record => processCreateRecord(record, failedRecord), { concurrency: config.PROCESS_CONCURRENCY_COUNT })
222+
await Promise.map(records, record => processCreateRecord(record, failedRecord, message.payload.organizationId), { concurrency: config.PROCESS_CONCURRENCY_COUNT })
225223

226224
if (failedRecord.length > 0) {
227225
await helper.uploadFailedRecord(failedRecord, message.payload.objectKey)
@@ -247,6 +245,7 @@ processCreate.schema = {
247245
resource: Joi.string().required(),
248246
objectKey: Joi.string().required(),
249247
status: Joi.string().required(),
248+
organizationId: Joi.string().required(),
250249
id: Joi.id()
251250
}).required().unknown(true)
252251
}).required()

0 commit comments

Comments
 (0)