Skip to content

Commit 27137ce

Browse files
authored
Merge pull request #22 from hackjunction/Junction-Platform-2.0
Updating STAG to Junction platform 2.0
2 parents 40752dd + 821fda1 commit 27137ce

484 files changed

Lines changed: 142179 additions & 28327 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

azure-pipelines-1.yml

Lines changed: 436 additions & 19 deletions
Large diffs are not rendered by default.

backend/common/errors/errors.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,20 @@ class UnauthorizedError extends CustomError {
6565
}
6666
}
6767

68+
class AlreadyExistsError extends CustomError {
69+
constructor(message) {
70+
const name = 'AlreadyExistsError'
71+
const code = 7
72+
super(message, name, code)
73+
}
74+
}
75+
6876
module.exports = {
6977
InsufficientPrivilegesError,
7078
EmailVerificationError,
7179
NotFoundError,
7280
ValidationError,
7381
ForbiddenError,
7482
UnauthorizedError,
83+
AlreadyExistsError,
7584
}

backend/common/middleware/events.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ function isOrganiser(user, event) {
4747
return null
4848
}
4949

50+
function isPartner(user, event) {
51+
console.log('isPartner func running')
52+
if (!event) {
53+
return new NotFoundError('Event does not exist')
54+
}
55+
if (event.recruiters.length > 0) {
56+
const recruiterIds = event.recruiters.map(recruiter => {
57+
return recruiter.recruiterId
58+
})
59+
if (recruiterIds.indexOf(user.sub) === -1) {
60+
return new InsufficientPrivilegesError(
61+
'Must be partner in the of event',
62+
)
63+
}
64+
}
65+
return null
66+
}
67+
5068
function canRegister(user, event) {
5169
if (!event) {
5270
return new NotFoundError('Event does not exist')
@@ -178,7 +196,6 @@ const EventMiddleware = {
178196
isEventOrganiser: async (req, res, next) => {
179197
// TODO this method is called quite often. Not really problem here, but a reminder to run a profiler on the frontend at some point
180198
const event = await getEventFromParams(req.params)
181-
// TODO what the fuck is the logic with these? :D if true, return null?
182199
const superAdminError = isSuperAdmin(req.user)
183200
const error = isOrganiser(req.user, event)
184201
if (error && superAdminError) {
@@ -188,6 +205,19 @@ const EventMiddleware = {
188205
next()
189206
}
190207
},
208+
isEventPartner: async (req, res, next) => {
209+
console.log('isEventPartner running')
210+
// TODO this method is called quite often. Not really problem here, but a reminder to run a profiler on the frontend at some point
211+
const event = await getEventFromParams(req.params)
212+
const superAdminError = isSuperAdmin(req.user)
213+
const error = isPartner(req.user, event)
214+
if (error && superAdminError) {
215+
next(error)
216+
} else {
217+
req.event = event
218+
next()
219+
}
220+
},
191221
isEventOwner: async (req, res, next) => {
192222
const event = await getEventFromParams(req.params)
193223
const superAdminError = isSuperAdmin(req.user)
@@ -237,6 +267,24 @@ const EventMiddleware = {
237267
next()
238268
}
239269
},
270+
isOrganiserOrCanSubmitProject: async (req, res, next) => {
271+
const event = await getEventFromParams(req.params)
272+
const [registration, team] = await Promise.all([
273+
getRegistration(req.user, event),
274+
getTeamWithMeta(req.user, event),
275+
])
276+
const superAdminError = isSuperAdmin(req.user)
277+
const organiserError = isOrganiser(req.user, event)
278+
const projectError = canSubmitProject(event, registration, team)
279+
if ((organiserError && superAdminError) && projectError) {
280+
next(error)
281+
} else {
282+
req.event = event
283+
req.registration = registration
284+
req.team = team
285+
next()
286+
}
287+
},
240288
hasPartnerToken: async (req, res, next) => {
241289
/* const [match, ...other] = await hasPartnerToken(
242290
req.event,

backend/common/plugins/allowPublish.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function allowPublishPlugin(schema, { defaultPublished = false } = {}) {
2424
`must be set before the event can be published!`,
2525
],
2626
}
27+
//console.log("error with publishing", "options", options, "path", path)//TODO: migrate the publish button to the end and show errors
2728
delete newOptions.requiredForPublish
2829
schema.path(path, newOptions)
2930
}

backend/common/services/google-calendar/google-calendar.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const { updateMeetingGoogleInfo } = require('../../../modules/meeting/helpers')
66

77
const TOKEN_PATH = `${__dirname}/token.json`
88
const install = {
9-
client_id: "752565208443-0g0ui7afokfi2b1t1von4qankq1vh62h.apps.googleusercontent.com",//"758477701769-hasb17jt161beprjr34kgqjma0sb815h.apps.googleusercontent.com",//global.gConfig.GOOGLE_CLIENT_ID,
10-
project_id: "prod-calendar-386407",//"junction-calendar-375014",//global.gConfig.GOOGLE_PROJECT_ID,
11-
auth_uri: "https://accounts.google.com/o/oauth2/auth",//"https://accounts.google.com/o/oauth2/auth", //global.gConfig.GOOGLE_AUTH_URI,
12-
token_uri: "https://oauth2.googleapis.com/token",//"https://oauth2.googleapis.com/token", //global.gConfig.GOOGLE_TOKEN_URI,
13-
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",//"https://www.googleapis.com/oauth2/v1/certs", //global.gConfig.GOOGLE_AUTH_PROVIDER,
14-
client_secret: "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",//"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", //global.gConfig.GOOGLE_CLIENT_SECRET,
15-
redirect_uris:["http://localhost","https://app.hackjunction.com","https://eu.junctionplatform.com"]//["http://localhost","https://app.hackjunction.com"], //[ global.gConfig.GOOGLE_REDIRECT]
9+
client_id: "752565208443-0g0ui7afokfi2b1t1von4qankq1vh62h.apps.googleusercontent.com",//"758477701769-hasb17jt161beprjr34kgqjma0sb815h.apps.googleusercontent.com",//global.gConfig.GOOGLE_CLIENT_ID,
10+
project_id: "prod-calendar-386407",//"junction-calendar-375014",//global.gConfig.GOOGLE_PROJECT_ID,
11+
auth_uri: "https://accounts.google.com/o/oauth2/auth",//"https://accounts.google.com/o/oauth2/auth", //global.gConfig.GOOGLE_AUTH_URI,
12+
token_uri: "https://oauth2.googleapis.com/token",//"https://oauth2.googleapis.com/token", //global.gConfig.GOOGLE_TOKEN_URI,
13+
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",//"https://www.googleapis.com/oauth2/v1/certs", //global.gConfig.GOOGLE_AUTH_PROVIDER,
14+
client_secret: "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",//"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", //global.gConfig.GOOGLE_CLIENT_SECRET,
15+
redirect_uris: ["http://localhost", "https://app.hackjunction.com", "https://eu.junctionplatform.com"]//["http://localhost","https://app.hackjunction.com"], //[ global.gConfig.GOOGLE_REDIRECT]
1616
}
1717
const credentialsJ = {
1818
installed: install
@@ -39,9 +39,9 @@ function authorize(credentials, callback, callbackParameter = null) {
3939
console.log('Error loading google calendar token file')
4040
return false
4141
}
42-
console.log("got token",token)
42+
4343
oAuth2Client.setCredentials(JSON.parse(token))
44-
console.log("oAuth2Client, callbackParameter",callback(oAuth2Client, callbackParameter))
44+
4545
callback(oAuth2Client, callbackParameter)
4646
})
4747

@@ -60,7 +60,7 @@ function authorize(credentials, callback, callbackParameter = null) {
6060
}
6161

6262
const insertEvent = (auth, eventInfo) => {
63-
console.log("inserting")
63+
6464
const calendar = google.calendar({ version: 'v3', auth })
6565
calendar.events.insert(
6666
{
@@ -76,7 +76,6 @@ const insertEvent = (auth, eventInfo) => {
7676
)
7777
// cancelMeeting(eventInfo.meetingId)
7878
} else {
79-
console.log(res)
8079
updateMeetingGoogleInfo(
8180
eventInfo.meetingId,
8281
res.data.id,
@@ -116,7 +115,7 @@ const deleteGoogleEvent = eventId => {
116115
return true
117116
})*/
118117

119-
authorize(JSON.parse(JSON.stringify(credentialsJ)),deleteEvent,eventId)
118+
authorize(JSON.parse(JSON.stringify(credentialsJ)), deleteEvent, eventId)
120119
return true
121120

122121
} catch (err) {
@@ -167,8 +166,7 @@ const createGoogleEvent = event => {
167166
168167
})*/
169168

170-
console.log(credentialsJ)
171-
authorize(JSON.parse(JSON.stringify(credentialsJ)),insertEvent,eventInfo)
169+
authorize(JSON.parse(JSON.stringify(credentialsJ)), insertEvent, eventInfo)
172170
console.log("success")
173171
return true
174172
} catch (err) {

backend/common/services/sendgrid.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const SendgridService = {
9999
subtitle: event.emailConfig.acceptanceEmail.subtitle || `You've been accepted to ${event.name}!`,
100100
body: replaceBodyTags(event.emailConfig.acceptanceEmail.body, event, user),
101101
cta_text: 'Event dashboard',
102-
cta_link: `${global.gConfig.FRONTEND_URL}/dashboard/${event.slug}`,
102+
cta_link: `${global.gConfig.FRONTEND_URL}/dashboard/event/${event.slug}`,
103103
},
104104
)
105105
return SendgridService.send(msg)
@@ -137,7 +137,7 @@ const SendgridService = {
137137
subtitle: event.emailConfig.registrationEmail.subtitle || 'Awesome! Now just sit back and relax.',
138138
body: replaceBodyTags(event.emailConfig.registrationEmail.body, event, user),
139139
cta_text: 'Event dashboard',
140-
cta_link: `${global.gConfig.FRONTEND_URL}/dashboard/${event.slug}`,
140+
cta_link: `${global.gConfig.FRONTEND_URL}/dashboard/event/${event.slug}`,
141141
},
142142
)
143143
} else {
@@ -193,7 +193,7 @@ const SendgridService = {
193193
Psst, please note that the transaction will be made in Euros, so please make sure you have a bank account able to receive Euro payments available.
194194
`,
195195
cta_text: 'Event dashboard',
196-
cta_link: `${global.gConfig.FRONTEND_URL}/dashboard/${event.slug}`,
196+
cta_link: `${global.gConfig.FRONTEND_URL}/dashboard/event/${event.slug}`,
197197
},
198198
)
199199

@@ -228,7 +228,7 @@ const SendgridService = {
228228
accept someone from the waitlist.
229229
`,
230230
cta_text: 'Event dashboard',
231-
cta_link: `${global.gConfig.FRONTEND_URL}/dashboard/${event.slug}`,
231+
cta_link: `${global.gConfig.FRONTEND_URL}/dashboard/event/${event.slug}`,
232232
},
233233
)
234234

@@ -285,7 +285,7 @@ const SendgridService = {
285285
<br />
286286
Please refer to finance@hackjunction.com (by replying to this email) with any further questions on the matter.
287287
`,
288-
cta_link: `${global.gConfig.FRONTEND_URL}/dashboard/${event.slug}/travel-grant`,
288+
cta_link: `${global.gConfig.FRONTEND_URL}/dashboard/event/${event.slug}/travel-grant`,
289289
cta_text: 'Edit your details',
290290
reply_to: 'finance@hackjunction.com',
291291
},
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//TODO move this code into the user profile helpers
2+
3+
const userProfileUtils = {
4+
publicProfileBuilder: profileData => {
5+
return {
6+
userId: profileData.userId,
7+
profile: {
8+
firstName: profileData.firstName,
9+
lastName: profileData.lastName,
10+
email: profileData.email,
11+
gender: profileData.gender,
12+
nationality: profileData.nationality,
13+
countryOfResidence: profileData.countryOfResidence,
14+
dateOfBirth: profileData.dateOfBirth,
15+
spokenLanguages: profileData.spokenLanguages,
16+
// TODO remove profilePicture and replace with avatar property
17+
profilePicture: profileData.avatar || null,
18+
avatar: profileData.avatar || null,
19+
headline: profileData.headline,
20+
biography: profileData.biography,
21+
},
22+
skills: profileData.skills,
23+
roles: profileData.roles,
24+
industriesOfInterest: profileData.industriesOfInterest,
25+
themesOfInterest: profileData.themesOfInterest,
26+
education: profileData.education,
27+
social: {
28+
github: profileData.github,
29+
linkedin: profileData.linkedin,
30+
portfolio: profileData.portfolio,
31+
curriculumVitae: profileData.curriculumVitae,
32+
},
33+
}
34+
},
35+
recruitmentProfileBuilder: function (profileData) {
36+
return {
37+
...this.publicProfileBuilder(profileData),
38+
recruitmentOptions: profileData.recruitmentOptions,
39+
registrations: profileData.registrations,
40+
}
41+
},
42+
}
43+
44+
module.exports = userProfileUtils

backend/index.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,31 @@ app.use(require('./common/errors/errorHandler'))
6666

6767
/* Database connection */
6868
require('./misc/db').connect()
69+
//let gfs = require('./misc/db').gfs
6970

71+
// const storage = require('./misc/gridfs').storage
72+
// const upload = require('./misc/gridfs').upload
7073
const migrations = require('./migrations/index')
7174

7275
/** A clone of the npm library throng, with a minor edit. See the file for details. */
7376
const throng = require('./misc/throng')
7477

78+
const memoryUsage = () => {
79+
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`
80+
81+
const memoryData = process.memoryUsage()
82+
83+
const memoryUsage = {
84+
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`,
85+
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
86+
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
87+
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`,
88+
}
89+
90+
console.log(memoryUsage)
91+
92+
}
93+
7594
throng({
7695
workers: process.env.WEB_CONCURRENCY || 1,
7796
grace: 1000,
@@ -91,10 +110,20 @@ throng({
91110
httpServer.listen(PORT, () => {
92111
logger.info(
93112
`Worker ${process.pid} started, listening on port ${httpServer.address().port}`,
94-
113+
95114
)
115+
96116
})
117+
118+
memoryUsage()
119+
120+
121+
122+
97123
},
124+
125+
126+
98127
/** This is run only if the master function errors out, which means the
99128
* server could not start properly. Workers are automatically revived on failure, if e.g.
100129
* the app crashes or runs out of memory while processing a request.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const mongoose = require('mongoose')
2+
const Promise = require('bluebird')
3+
4+
module.exports = {
5+
index: 9,
6+
name: '09-add-challengesenabled-false',
7+
description: 'if no challenges, set challengesEnabled to false',
8+
run: async () => {
9+
const nres = await mongoose
10+
.model('Event')
11+
.updateMany(
12+
{ challenges: { $exists: true, $size: 0 } },
13+
{ $set: { challengesEnabled: false } },
14+
)
15+
console.info('Done with challengesEnabled to false', nres.n, nres.nModified)
16+
return Promise.resolve()
17+
},
18+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const mongoose = require('mongoose')
2+
const Promise = require('bluebird')
3+
4+
module.exports = {
5+
index: 11,
6+
name: '11-add-emailConfig-to-event',
7+
description: 'Add emailConfig to event',
8+
run: async () => {
9+
// Update emailConfig field
10+
const resEmailConfig = await mongoose.model('Event').updateMany(
11+
{ emailConfig: { $exists: false } },
12+
{
13+
$set: {
14+
emailConfig: {
15+
senderName: '',
16+
senderEmail: 'noreply@hackjunction.com',
17+
acceptanceEmail: {
18+
title: '',
19+
subtitle: '',
20+
body: '',
21+
},
22+
rejectionEmail: {
23+
title: '',
24+
subtitle: '',
25+
body: '',
26+
},
27+
registrationEmail: {
28+
title: '',
29+
subtitle: '',
30+
body: '',
31+
},
32+
},
33+
},
34+
},
35+
)
36+
console.log(
37+
'Done updating emailConfig field',
38+
resEmailConfig.n,
39+
resEmailConfig.nModified,
40+
)
41+
42+
return Promise.resolve()
43+
},
44+
}

0 commit comments

Comments
 (0)