Skip to content

Commit 36e9893

Browse files
authored
Merge pull request #52 from topcoder-platform/hot-fix-master/clean-up-legacy-events
Remove challenge.notification.events
2 parents 1e02c6b + 8ccb59d commit 36e9893

8 files changed

+11
-255
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ services:
1717
KAFKA_ADVERTISED_HOST_NAME: localhost
1818
KAFKA_ADVERTISED_PORT: 9092
1919
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
20-
KAFKA_CREATE_TOPICS: "challenge.notification.create:1:1,challenge.notification.update:1:1,challenge.notification.events:1:1,challenge.action.resource.create:1:1,challenge.action.resource.delete:1:1"
20+
KAFKA_CREATE_TOPICS: "challenge.notification.create:1:1,challenge.notification.update:1:1,challenge.action.resource.create:1:1,challenge.action.resource.delete:1:1"

package-lock.json

Lines changed: 4 additions & 188 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sample-data/challenge.notification.events-registeration.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

sample-data/challenge.notification.events-unregisteration.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/constants.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,9 @@ module.exports = {
1111
CHALLENGE_CREATE_TOPIC: 'challenge.notification.create',
1212
// For challenge update
1313
CHALLENGE_UPDATE_TOPIC: 'challenge.notification.update',
14-
// For member registrations and de-registrations
15-
CHALLENGE_NOTIFICATION_TOPIC: 'challenge.notification.events',
16-
// For co-pilots,PMs,etc.
14+
// For member registrations and de-registrations, co-pilots,PMs,etc.
1715
RESOURCE_CREATE_TOPIC: 'challenge.action.resource.create',
1816
RESOURCE_DELETE_TOPIC: 'challenge.action.resource.delete'
19-
},
20-
// Values of `type` in payload of challenge.notification.events
21-
CHALLENGE_NOTIFICATION_EVENT_TYPES: {
22-
USER_REGISTRATION: 'USER_REGISTRATION',
23-
USER_UNREGISTRATION: 'USER_UNREGISTRATION'
2417
}
2518
},
2619
TEMPLATES: {

src/modules/user_management/handler.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,10 @@ if (config.VANILLA_ENABLED) {
2222
services.push(manageVanillaUser)
2323
}
2424

25-
function canProcessEvent (payload, topic) {
26-
if (topic === constants.KAFKA.TOPICS.CHALLENGE_NOTIFICATION_TOPIC) {
27-
const eventTypes = constants.KAFKA.CHALLENGE_NOTIFICATION_EVENT_TYPES
28-
const actionMap = {
29-
[eventTypes.USER_REGISTRATION]: constants.USER_ACTIONS.INVITE,
30-
[eventTypes.USER_UNREGISTRATION]: constants.USER_ACTIONS.KICK
31-
}
32-
if (!(payload.type in actionMap)) {
33-
logger.debug(`Not supported ${payload.type}. Only message types ${JSON.stringify(Object.keys(eventTypes))} are processed from '${topic}'`)
34-
return false
35-
}
25+
function canProcessEvent (topic) {
26+
if (!_.includes([constants.KAFKA.TOPICS.RESOURCE_CREATE_TOPIC, constants.KAFKA.TOPICS.RESOURCE_DELETE_TOPIC], topic)) {
27+
logger.debug('Not supported topic.')
28+
return false
3629
}
3730
return true
3831
}
@@ -65,7 +58,7 @@ async function handler (messageSet, topic) {
6558
return
6659
}
6760
for (const item of messageSet) {
68-
if (!canProcessEvent(item, topic)) {
61+
if (!canProcessEvent(topic)) {
6962
continue
7063
}
7164
if (_.isArray(item)) {

src/modules/user_management/helpers.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ const topcoderApi = require('../../utils/topcoder-api.util')
99
* @param {String} topic
1010
*/
1111
function processPayload (payload, topic) {
12-
const eventTypes = constants.KAFKA.CHALLENGE_NOTIFICATION_EVENT_TYPES
13-
const actionMap = {
14-
[eventTypes.USER_REGISTRATION]: constants.USER_ACTIONS.INVITE,
15-
[eventTypes.USER_UNREGISTRATION]: constants.USER_ACTIONS.KICK
16-
}
1712
switch (topic) {
1813
case constants.KAFKA.TOPICS.RESOURCE_CREATE_TOPIC:
1914
return {
@@ -29,20 +24,6 @@ function processPayload (payload, topic) {
2924
handle: payload.memberHandle,
3025
action: constants.USER_ACTIONS.KICK
3126
}
32-
case constants.KAFKA.TOPICS.CHALLENGE_NOTIFICATION_TOPIC:
33-
if (payload.detail && payload.detail.challengeId) {
34-
// hack due to inconsistent payload from USER_UNREGISTRATION event
35-
return {
36-
challengeId: payload.detail.challengeId,
37-
userId: payload.detail.userId,
38-
action: actionMap[payload.type]
39-
}
40-
}
41-
return {
42-
challengeId: payload.data.challengeId,
43-
userId: payload.data.userId,
44-
action: actionMap[payload.type]
45-
}
4627
default:
4728
throw new Error(`Received message from unrecognized '${topic}'`)
4829
}

src/modules/user_management/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const handler = require('./handler')
44

55
module.exports = {
66
topics: [
7-
constants.KAFKA.TOPICS.CHALLENGE_NOTIFICATION_TOPIC,
87
constants.KAFKA.TOPICS.RESOURCE_CREATE_TOPIC,
98
constants.KAFKA.TOPICS.RESOURCE_DELETE_TOPIC
109
],

0 commit comments

Comments
 (0)