Skip to content
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
28 changes: 14 additions & 14 deletions backend/modules/alert/graphql.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { withFilter } = require('graphql-subscriptions')
// const { RedisPubSub } = require('graphql-redis-subscriptions')
const { RedisPubSub } = require('graphql-redis-subscriptions')
const {
GraphQLString,
GraphQLObjectType,
Expand All @@ -11,12 +11,12 @@ const {
const { GraphQLDate } = require('graphql-iso-date')
const RegistrationController = require('../registration/controller')
const Event = require('../event/model')
// const Redis = require('ioredis')
const Redis = require('ioredis')

// const pubsub = new RedisPubSub({
// publisher: new Redis(process.env.REDISCLOUD_URL),
// subscriber: new Redis(process.env.REDISCLOUD_URL),
// })
const pubsub = new RedisPubSub({
publisher: new Redis(process.env.REDISCLOUD_URL),
subscriber: new Redis(process.env.REDISCLOUD_URL),
})

const AlertInput = new GraphQLInputObjectType({
name: 'AlertInput',
Expand Down Expand Up @@ -116,13 +116,13 @@ const Resolvers = {
throw new Error('You are not an organiser of this event')
}

// pubsub.publish('ALERT_SENT', {
// newAlert: {
// ...args.alert,
// sentAt: new Date(),
// sender: userId,
// },
// })
pubsub.publish('ALERT_SENT', {
newAlert: {
...args.alert,
sentAt: new Date(),
sender: userId,
},
})

return context.controller('Alert').send(args.alert, userId)
},
Expand All @@ -131,7 +131,7 @@ const Resolvers = {
newAlert: {
subscribe: withFilter(
() => {
// return pubsub.asyncIterator('ALERT_SENT')
return pubsub.asyncIterator('ALERT_SENT')
},
async ({ newAlert }, { eventId, slug }, { user }) => {
// Check authentication from context
Expand Down
8 changes: 8 additions & 0 deletions backend/modules/event/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const {
EventPageScriptInput,
ScoreCriteriaSettings,
ScoreCriteriaSettingsInput,
Certificate,
CertificateInput,
} = require('../graphql-shared-types')

const Organization = require('../organization/model')
Expand Down Expand Up @@ -318,6 +320,9 @@ const EventInput = new GraphQLInputObjectType({
experimental: {
type: GraphQLBoolean,
},
certificate: {
type: CertificateInput,
},
},
})

Expand Down Expand Up @@ -542,6 +547,9 @@ const EventType = new GraphQLObjectType({
experimental: {
type: GraphQLBoolean,
},
Certificate: {
type: Certificate,
},
}
},
})
Expand Down
28 changes: 14 additions & 14 deletions backend/modules/message/graphql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { GraphQLBoolean } = require('graphql')
const { withFilter } = require('graphql-subscriptions')
// const { RedisPubSub } = require('graphql-redis-subscriptions')
const { RedisPubSub } = require('graphql-redis-subscriptions')
const {
GraphQLString,
GraphQLObjectType,
Expand All @@ -10,12 +10,12 @@ const {
GraphQLInputObjectType,
} = require('graphql')
const { GraphQLDate } = require('graphql-iso-date')
// const Redis = require('ioredis')
const Redis = require('ioredis')

// const pubsub = new RedisPubSub({
// publisher: new Redis(process.env.REDISCLOUD_URL),
// subscriber: new Redis(process.env.REDISCLOUD_URL)
// })
const pubsub = new RedisPubSub({
publisher: new Redis(process.env.REDISCLOUD_URL),
subscriber: new Redis(process.env.REDISCLOUD_URL),
})
const MessageInput = new GraphQLInputObjectType({
name: 'MessageInput',
fields: {
Expand Down Expand Up @@ -118,13 +118,13 @@ const Resolvers = {
const userId = context.req.user ? context.req.user.sub : null
if (!userId) return null

// pubsub.publish('MESSAGE_SENT', {
// newMessage: {
// ...args.message,
// sentAt: new Date(),
// sender: userId,
// },
// })
pubsub.publish('MESSAGE_SENT', {
newMessage: {
...args.message,
sentAt: new Date(),
sender: userId,
},
})

return context.controller('Message').send(args.message, userId)
},
Expand All @@ -145,7 +145,7 @@ const Resolvers = {
newMessage: {
subscribe: withFilter(
() => {
// return pubsub.asyncIterator('MESSAGE_SENT')
return pubsub.asyncIterator('MESSAGE_SENT')
},
({ newMessage }, _, { user }) => {
// Check authentication from context
Expand Down
52 changes: 33 additions & 19 deletions backend/modules/team/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const {
NotFoundError,
} = require('../../common/errors/errors')

const maxTeamSize = 5

const controller = {}

controller.getRoles = (eventId, code) => {
Expand Down Expand Up @@ -51,6 +53,7 @@ controller.createNewTeam = (data, eventId, userId) => {
email,
telegram,
discord,
slack,
} = data
const team = new Team({
event: eventId,
Expand All @@ -64,6 +67,7 @@ controller.createNewTeam = (data, eventId, userId) => {
email,
telegram,
discord,
slack,
})
if (teamRoles && teamRoles.length > 0) {
team.teamRoles = teamRoles.map(role => ({
Expand Down Expand Up @@ -173,8 +177,10 @@ controller.joinTeam = (eventId, userId, code) => {
return controller.getTeamByCode(eventId, code).then(team => {
// TODO HIGH PRIORITY team size defined in event

if (team.members.length >= 4) {
throw new ForbiddenError('Teams can have at most 5 members')
if (team.members.length + 1 >= maxTeamSize) {
throw new ForbiddenError(
`Teams can have at most ${maxTeamSize} members`,
)
}
return controller
.getTeamsForEvent(eventId)
Expand Down Expand Up @@ -223,13 +229,14 @@ controller.joinTeam = (eventId, userId, code) => {
}
//TODO: optimize this process, slow with over 200 teams
controller.acceptCandidateToTeam = (eventId, userId, code, candidateId) => {

let teamToReturn
return controller
.getTeamByCode(eventId, code)
.then(team => {
if (team.members.length >= 4) {
throw new ForbiddenError('Teams can have at most 5 members')
if (team.members.length + 1 >= maxTeamSize) {
throw new ForbiddenError(
`Teams can have at most ${maxTeamSize} members`,
)
}
if (!_.includes([team.owner].concat(team.members), userId)) {
throw new InsufficientPrivilegesError(
Expand Down Expand Up @@ -493,7 +500,7 @@ controller.attachUserApplicant = (teams, userId) => {

controller.getTeamsForEvent = async (eventId, userId, page, size, filter) => {
if (page && size) {
console.log("filter", filter)
console.log('filter', filter)
if (filter) {
const found = await Team.find({
event: eventId,
Expand All @@ -507,8 +514,11 @@ controller.getTeamsForEvent = async (eventId, userId, page, size, filter) => {
return controller.attachUserApplicant(teams, userId)
}
})
const count = await Team.find({ event: eventId, challenge: filter }).countDocuments()
console.log("with filter", { data: found, count: count })
const count = await Team.find({
event: eventId,
challenge: filter,
}).countDocuments()
console.log('with filter', { data: found, count: count })
return { data: found, count: count }
} else {
const found = await Team.find({
Expand Down Expand Up @@ -537,14 +547,13 @@ controller.getTeamsForEvent = async (eventId, userId, page, size, filter) => {
return teams
})
const count = await Team.find({ event: eventId }).countDocuments()
console.log("getting all teams", count)
console.log('getting all teams', count)
return { data: found, count: count }
}
// TODO make the code not visible to participants on Redux store
}

controller.getAllTeamsForEvent = async (eventId, userId, page, size) => {

return await Team.find({
event: eventId,
})
Expand Down Expand Up @@ -590,26 +599,31 @@ controller.convertToFlatExportData = teamWithMeta => {
}
}

controller.organiserRemoveMemberFromTeam = (eventId, teamCode, userToRemove) => {
console.log("removing ", eventId, teamCode, userToRemove)
controller.organiserRemoveMemberFromTeam = (
eventId,
teamCode,
userToRemove,
) => {
console.log('removing ', eventId, teamCode, userToRemove)
return controller.getTeamByCode(eventId, teamCode).then(team => {

if (team.members.length === 0 && team.owner === userToRemove) {
console.log("deleting team")
console.log('deleting team')
controller.deleteTeamByCode(eventId, teamCode)
} else {
if (team.owner === userToRemove) {
console.log("new owner", team.members[0])
console.log('new owner', team.members[0])
team.owner = team.members[0]
team.members = team.members.slice(1)
} else {
console.log("removing member")
team.members = team.members.filter(member => member !== userToRemove)
console.log('removing member')
team.members = team.members.filter(
member => member !== userToRemove,
)
}
console.log("deleted ", team.members)
console.log('deleted ', team.members)
return team.save()
}
console.log("deleted team", team.members)
console.log('deleted team', team.members)
return team.save()
})
}
Expand Down
3 changes: 3 additions & 0 deletions backend/modules/team/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const TeamSchema = new mongoose.Schema({
discord: {
type: String,
},
slack: {
type: String,
},
})

TeamSchema.pre('save', async function (next) {
Expand Down
18 changes: 8 additions & 10 deletions frontend/package-lock.json

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

30 changes: 29 additions & 1 deletion frontend/src/components/Team/TeamCreateEditForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export default ({
{({ field, form }) => (
<FormControl
label="Team's contact email"
hint="Your team must have at least an email, a discord or a telegram channel"
hint="Your team must have at least an email, a slack, discord or a telegram channel"
touched={
form.touched[field.name] ||
formikProps.submitCount > 0
Expand All @@ -429,6 +429,34 @@ export default ({
)}
</FastField>
</div>
<div>
<FastField name="slack">
{({ field, form }) => (
<FormControl
label="Team's Slack"
touched={
form.touched[field.name] ||
formikProps.submitCount > 0
}
error={form.errors[field.name]}
>
<TextInput
value={field.value}
onChange={value =>
form.setFieldValue(
field.name,
value,
)
}
onBlur={() =>
form.setFieldTouched(field.name)
}
placeholder="Your team's Slack"
/>
</FormControl>
)}
</FastField>
</div>
<div>
<FastField name="telegram">
{({ field, form }) => (
Expand Down
17 changes: 15 additions & 2 deletions frontend/src/components/Team/TeamProfile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export default ({
enableActions = true,
teamData = {},
onClickLeave,
onClickDelete = () => { },
onClickDelete = () => {},
onClickEdit,
onRoleClick = () => { },
onRoleClick = () => {},
loading = false,
}) => {
const teamMembersArr = [...objToArr(teamData.meta)]
Expand Down Expand Up @@ -97,6 +97,19 @@ export default ({
<Email className={classes.socialIcon} />
</IconButton>
)}
{teamData?.slack && (
<FontAwesomeIcon
icon={['fab', 'slack']}
onClick={() =>
popupCenter({
url: teamData.slack,
title: 'Slack',
})
}
className={classes.socialIcon}
size="2x"
/>
)}
</div>
{/* TODO add socialLinks component from Damilare (@mrprotocoll) */}
{enableActions && (
Expand Down
Loading