Skip to content

Commit 700151f

Browse files
MikaVohlJoshua Zhou
authored andcommitted
Added hackboard role support
1 parent 794c97b commit 700151f

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

constants/general.constant.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const SAMPLE_DIET_RESTRICTIONS = [
7272
const HACKER = "Hacker";
7373
const VOLUNTEER = "Volunteer";
7474
const STAFF = "Staff";
75+
const HACKBOARD = "Hackboard";
7576
const SPONSOR = "Sponsor";
7677

7778
const SPONSOR_T1 = "SponsorT1";
@@ -109,8 +110,9 @@ POST_ROLES[SPONSOR_T4] = "postSponsor";
109110
POST_ROLES[SPONSOR_T5] = "postSponsor";
110111
POST_ROLES[VOLUNTEER] = "postVolunteer";
111112
POST_ROLES[STAFF] = "postStaff";
113+
POST_ROLES[HACKBOARD] = "Hackboard";
112114

113-
const USER_TYPES = [HACKER, VOLUNTEER, STAFF, SPONSOR];
115+
const USER_TYPES = [HACKER, VOLUNTEER, STAFF, HACKBOARD, SPONSOR];
114116
const SPONSOR_TIERS = [
115117
SPONSOR_T1,
116118
SPONSOR_T2,
@@ -122,6 +124,7 @@ const EXTENDED_USER_TYPES = [
122124
HACKER,
123125
VOLUNTEER,
124126
STAFF,
127+
HACKBOARD,
125128
SPONSOR_T1,
126129
SPONSOR_T2,
127130
SPONSOR_T3,
@@ -168,6 +171,9 @@ CREATE_ACC_EMAIL_SUBJECTS[
168171
CREATE_ACC_EMAIL_SUBJECTS[
169172
STAFF
170173
] = `You've been invited to create a staff account for ${HACKATHON_NAME}`;
174+
CREATE_ACC_EMAIL_SUBJECTS[
175+
HACKBOARD
176+
] = `You've been invited to create a hackboard account for ${HACKATHON_NAME}`;
171177

172178
const CACHE_TIMEOUT_STATS = 5 * 60 * 1000;
173179
const CACHE_KEY_STATS = "hackerStats";
@@ -211,6 +217,7 @@ module.exports = {
211217
SPONSOR: SPONSOR,
212218
VOLUNTEER: VOLUNTEER,
213219
STAFF: STAFF,
220+
HACKBOARD: HACKBOARD,
214221
SPONSOR_T1: SPONSOR_T1,
215222
SPONSOR_T2: SPONSOR_T2,
216223
SPONSOR_T3: SPONSOR_T3,

constants/role.constant.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,31 @@ const accountRole = {
2020
]
2121
};
2222

23+
const hackboardRestrictedRoutes = [ // hackboard permissions is all staff routes minus these routes
24+
Constants.Routes.hackerRoutes.postAnySendWeekOfEmail,
25+
Constants.Routes.hackerRoutes.postSelfSendWeekOfEmail,
26+
Constants.Routes.hackerRoutes.postAnySendDayOfEmail,
27+
Constants.Routes.hackerRoutes.postSelfSendDayOfEmail,
28+
Constants.Routes.hackerRoutes.patchAcceptHackerById,
29+
Constants.Routes.hackerRoutes.patchAcceptHackerByEmail,
30+
Constants.Routes.hackerRoutes.patchAcceptHackerByArrayOfIds,
31+
Constants.Routes.hackerRoutes.patchAnyStatusById,
32+
Constants.Routes.settingsRoutes.getSettings,
33+
Constants.Routes.settingsRoutes.patchSettings
34+
];
35+
2336
const adminRole = {
2437
_id: mongoose.Types.ObjectId.createFromTime(1),
2538
name: Constants.General.STAFF,
2639
routes: Constants.Routes.listAllRoutes()
2740
};
2841

42+
const hackboardRole = {
43+
_id: mongoose.Types.ObjectId.createFromTime(9),
44+
name: "Hackboard",
45+
routes: createHackboardRoutes()
46+
};
47+
2948
const hackerRole = {
3049
_id: mongoose.Types.ObjectId.createFromTime(2),
3150
name: Constants.General.HACKER,
@@ -143,6 +162,15 @@ const singularRoles = createAllSingularRoles();
143162
const allRolesObject = createAllRoles();
144163
const allRolesArray = Object.values(allRolesObject);
145164

165+
function createHackboardRoutes() {
166+
const restrictedRouteIds = new Set(
167+
hackboardRestrictedRoutes.map((route) => route._id.toString())
168+
);
169+
return Constants.Routes.listAllRoutes().filter((route) => {
170+
return !restrictedRouteIds.has(route._id.toString());
171+
});
172+
}
173+
146174
/**
147175
* Creates all the roles that are of a specific uri and request type
148176
* @return {Role[]}
@@ -185,6 +213,7 @@ function createAllRoles() {
185213
let allRolesObject = {
186214
accountRole: accountRole,
187215
adminRole: adminRole,
216+
hackboardRole: hackboardRole,
188217
hackerRole: hackerRole,
189218
volunteerRole: volunteerRole,
190219
sponsorT1Role: sponsorT1Role,
@@ -208,6 +237,7 @@ function createAllRoles() {
208237
module.exports = {
209238
accountRole: accountRole,
210239
adminRole: adminRole,
240+
hackboardRole: hackboardRole,
211241
hackerRole: hackerRole,
212242
volunteerRole: volunteerRole,
213243
sponsorT1Role: sponsorT1Role,

middlewares/auth.middleware.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ async function addCreationRoleBindings(req, res, next) {
477477
req.body.account.id,
478478
Constants.Role.adminRole.name
479479
);
480+
} else if (req.body.account.accountType === Constants.General.HACKBOARD) {
481+
await Services.RoleBinding.createRoleBindingByRoleName(
482+
req.body.account.id,
483+
Constants.Role.hackboardRole.name
484+
);
480485
} else {
481486
// Get the default role for the account type given
482487
const roleName =

services/accountConfirmation.service.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ function generateAccountInvitationEmail(address, receiverEmail, type, token) {
172172
emailSubject = Constants.CREATE_ACC_EMAIL_SUBJECTS[Constants.SPONSOR];
173173
} else if (type === Constants.STAFF) {
174174
emailSubject = Constants.CREATE_ACC_EMAIL_SUBJECTS[Constants.STAFF];
175+
} else if (type === Constants.HACKBOARD) {
176+
emailSubject = Constants.CREATE_ACC_EMAIL_SUBJECTS[Constants.HACKBOARD];
175177
}
176178
const handlebarPath = path.join(
177179
__dirname,

tests/util/roleBinding.test.util.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ function createRoleBinding(accountId, accountType = null, specificRoles = []) {
2525
case Constants.General.STAFF:
2626
roleBinding.roles.push(Constants.Role.adminRole);
2727
break;
28+
case Constants.General.HACKBOARD:
29+
roleBinding.roles.push(Constants.Role.hackboardRole);
30+
break;
2831
case Constants.General.SPONSOR_T1:
2932
roleBinding.roles.push(Constants.Role.sponsorT1Role);
3033
break;

0 commit comments

Comments
 (0)