Skip to content

Remove challenge.notification.events #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ services:
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
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"
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"
192 changes: 4 additions & 188 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions sample-data/challenge.notification.events-registeration.json

This file was deleted.

13 changes: 0 additions & 13 deletions sample-data/challenge.notification.events-unregisteration.json

This file was deleted.

9 changes: 1 addition & 8 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ module.exports = {
CHALLENGE_CREATE_TOPIC: 'challenge.notification.create',
// For challenge update
CHALLENGE_UPDATE_TOPIC: 'challenge.notification.update',
// For member registrations and de-registrations
CHALLENGE_NOTIFICATION_TOPIC: 'challenge.notification.events',
// For co-pilots,PMs,etc.
// For member registrations and de-registrations, co-pilots,PMs,etc.
RESOURCE_CREATE_TOPIC: 'challenge.action.resource.create',
RESOURCE_DELETE_TOPIC: 'challenge.action.resource.delete'
},
// Values of `type` in payload of challenge.notification.events
CHALLENGE_NOTIFICATION_EVENT_TYPES: {
USER_REGISTRATION: 'USER_REGISTRATION',
USER_UNREGISTRATION: 'USER_UNREGISTRATION'
}
},
TEMPLATES: {
Expand Down
17 changes: 5 additions & 12 deletions src/modules/user_management/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,10 @@ if (config.VANILLA_ENABLED) {
services.push(manageVanillaUser)
}

function canProcessEvent (payload, topic) {
if (topic === constants.KAFKA.TOPICS.CHALLENGE_NOTIFICATION_TOPIC) {
const eventTypes = constants.KAFKA.CHALLENGE_NOTIFICATION_EVENT_TYPES
const actionMap = {
[eventTypes.USER_REGISTRATION]: constants.USER_ACTIONS.INVITE,
[eventTypes.USER_UNREGISTRATION]: constants.USER_ACTIONS.KICK
}
if (!(payload.type in actionMap)) {
logger.debug(`Not supported ${payload.type}. Only message types ${JSON.stringify(Object.keys(eventTypes))} are processed from '${topic}'`)
return false
}
function canProcessEvent (topic) {
if (!_.includes([constants.KAFKA.TOPICS.RESOURCE_CREATE_TOPIC, constants.KAFKA.TOPICS.RESOURCE_DELETE_TOPIC], topic)) {
logger.debug('Not supported topic.')
return false
}
return true
}
Expand Down Expand Up @@ -65,7 +58,7 @@ async function handler (messageSet, topic) {
return
}
for (const item of messageSet) {
if (!canProcessEvent(item, topic)) {
if (!canProcessEvent(topic)) {
continue
}
if (_.isArray(item)) {
Expand Down
19 changes: 0 additions & 19 deletions src/modules/user_management/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ const topcoderApi = require('../../utils/topcoder-api.util')
* @param {String} topic
*/
function processPayload (payload, topic) {
const eventTypes = constants.KAFKA.CHALLENGE_NOTIFICATION_EVENT_TYPES
const actionMap = {
[eventTypes.USER_REGISTRATION]: constants.USER_ACTIONS.INVITE,
[eventTypes.USER_UNREGISTRATION]: constants.USER_ACTIONS.KICK
}
switch (topic) {
case constants.KAFKA.TOPICS.RESOURCE_CREATE_TOPIC:
return {
Expand All @@ -29,20 +24,6 @@ function processPayload (payload, topic) {
handle: payload.memberHandle,
action: constants.USER_ACTIONS.KICK
}
case constants.KAFKA.TOPICS.CHALLENGE_NOTIFICATION_TOPIC:
if (payload.detail && payload.detail.challengeId) {
// hack due to inconsistent payload from USER_UNREGISTRATION event
return {
challengeId: payload.detail.challengeId,
userId: payload.detail.userId,
action: actionMap[payload.type]
}
}
return {
challengeId: payload.data.challengeId,
userId: payload.data.userId,
action: actionMap[payload.type]
}
default:
throw new Error(`Received message from unrecognized '${topic}'`)
}
Expand Down
1 change: 0 additions & 1 deletion src/modules/user_management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const handler = require('./handler')

module.exports = {
topics: [
constants.KAFKA.TOPICS.CHALLENGE_NOTIFICATION_TOPIC,
constants.KAFKA.TOPICS.RESOURCE_CREATE_TOPIC,
constants.KAFKA.TOPICS.RESOURCE_DELETE_TOPIC
],
Expand Down