Skip to content

Commit 52e3c3b

Browse files
author
James Cori
committed
Merge branch 'develop'
2 parents 1041b03 + c37e43a commit 52e3c3b

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

scripts/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @return {string}
55
*/
66
const generateUrlCode = (str) => {
7-
return encodeURI(str.toLowerCase().replace(/ /g, '-'))
7+
return encodeURI(str.toLowerCase().replace(/[^a-zA-Z0-9 ]/g, '').replace(/ /g, '-'))
88
}
99

1010
module.exports = {

src/modules/user_management/handler.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const config = require('config')
22
const util = require('util')
3+
const constants = require('../../constants')
34
const logger = require('../../utils/logger.util')
45
const { manageRocketUser } = require('../../services/rokect')
56
const { manageVanillaUser } = require('../../services/vanilla')
@@ -18,6 +19,21 @@ if (config.VANILLA_ENABLED) {
1819
services.push(manageVanillaUser)
1920
}
2021

22+
function canProcessEvent (payload, topic) {
23+
if (topic === constants.KAFKA.TOPICS.CHALLENGE_NOTIFICATION_TOPIC) {
24+
const eventTypes = constants.KAFKA.CHALLENGE_NOTIFICATION_EVENT_TYPES
25+
const actionMap = {
26+
[eventTypes.USER_REGISTRATION]: constants.USER_ACTIONS.INVITE,
27+
[eventTypes.USER_UNREGISTRATION]: constants.USER_ACTIONS.KICK
28+
}
29+
if (!(payload.type in actionMap)) {
30+
logger.debug(`Not supported ${payload.type}. Only message types ${JSON.stringify(Object.keys(eventTypes))} are processed from '${topic}'`)
31+
return false
32+
}
33+
}
34+
return true
35+
}
36+
2137
/**
2238
* Handle a set of messages from the Kafka topic
2339
* @param {Array} messageSet
@@ -29,6 +45,10 @@ async function handler (messageSet, topic) {
2945
return
3046
}
3147
for (const item of messageSet) {
48+
if (!canProcessEvent(item, topic)) {
49+
continue
50+
}
51+
3252
const data = processPayload(item, topic)
3353
try {
3454
data.handle = data.handle || (await getUserHandle(data.userId))

src/modules/user_management/helpers.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ function processPayload (payload, topic) {
3030
action: constants.USER_ACTIONS.KICK
3131
}
3232
case constants.KAFKA.TOPICS.CHALLENGE_NOTIFICATION_TOPIC:
33-
if (!(payload.type in actionMap)) {
34-
throw new Error(`Not supported ${payload.type}. Only message types ${JSON.stringify(Object.keys(eventTypes))} are processed from '${topic}'`)
35-
}
36-
if(payload.detail && payload.detail.challengeId) {
37-
//hack due to inconsistent payload from USER_UNREGISTRATION event
33+
if (payload.detail && payload.detail.challengeId) {
34+
// hack due to inconsistent payload from USER_UNREGISTRATION event
3835
return {
3936
challengeId: payload.detail.challengeId,
4037
userId: payload.detail.userId,

src/utils/topcoder-api.util.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const config = require('config')
22
const _ = require('lodash')
33
const m2mAuth = require('tc-core-library-js').auth.m2m
44
const request = require('superagent')
5-
const logger = require('./logger.util')
65

76
let m2m = null
87

@@ -20,9 +19,6 @@ async function getM2MToken () {
2019
])
2120
)
2221
}
23-
logger.info(
24-
`Getting M2M token for client ID=${config.TOPCODER.AUTH0_CLIENT_ID}`
25-
)
2622

2723
return m2m.getMachineToken(
2824
config.TOPCODER.AUTH0_CLIENT_ID,

0 commit comments

Comments
 (0)