Skip to content

Commit c592e68

Browse files
MikaVohltektaxi
andauthored
Added hackboard role support (#955)
* Added hackboard role support * minor edits to hackboard permissions --------- Co-authored-by: Tavi Pollard <tavienpollard@gmail.com>
1 parent a8415da commit c592e68

File tree

6 files changed

+53
-3
lines changed

6 files changed

+53
-3
lines changed

constants/general.constant.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ const SAMPLE_DIET_RESTRICTIONS = [
134134
const HACKER = "Hacker";
135135
const VOLUNTEER = "Volunteer";
136136
const STAFF = "Staff";
137+
const HACKBOARD = "Hackboard";
137138
const SPONSOR = "Sponsor";
138139

139140
const SPONSOR_T1 = "SponsorT1";
@@ -171,8 +172,9 @@ POST_ROLES[SPONSOR_T4] = "postSponsor";
171172
POST_ROLES[SPONSOR_T5] = "postSponsor";
172173
POST_ROLES[VOLUNTEER] = "postVolunteer";
173174
POST_ROLES[STAFF] = "postStaff";
175+
POST_ROLES[HACKBOARD] = "Hackboard";
174176

175-
const USER_TYPES = [HACKER, VOLUNTEER, STAFF, SPONSOR];
177+
const USER_TYPES = [HACKER, VOLUNTEER, STAFF, HACKBOARD, SPONSOR];
176178
const SPONSOR_TIERS = [
177179
SPONSOR_T1,
178180
SPONSOR_T2,
@@ -184,6 +186,7 @@ const EXTENDED_USER_TYPES = [
184186
HACKER,
185187
VOLUNTEER,
186188
STAFF,
189+
HACKBOARD,
187190
SPONSOR_T1,
188191
SPONSOR_T2,
189192
SPONSOR_T3,
@@ -230,6 +233,9 @@ CREATE_ACC_EMAIL_SUBJECTS[
230233
CREATE_ACC_EMAIL_SUBJECTS[
231234
STAFF
232235
] = `You've been invited to create a staff account for ${HACKATHON_NAME}`;
236+
CREATE_ACC_EMAIL_SUBJECTS[
237+
HACKBOARD
238+
] = `You've been invited to create a hackboard account for ${HACKATHON_NAME}`;
233239

234240
const CACHE_TIMEOUT_STATS = 5 * 60 * 1000;
235241
const CACHE_KEY_STATS = "hackerStats";
@@ -282,6 +288,7 @@ module.exports = {
282288
SPONSOR: SPONSOR,
283289
VOLUNTEER: VOLUNTEER,
284290
STAFF: STAFF,
291+
HACKBOARD: HACKBOARD,
285292
SPONSOR_T1: SPONSOR_T1,
286293
SPONSOR_T2: SPONSOR_T2,
287294
SPONSOR_T3: SPONSOR_T3,

constants/role.constant.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,32 @@ 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.staffRoutes.postAutomatedStatusEmails,
29+
Constants.Routes.staffRoutes.getAutomatedStatusEmailCount,
30+
Constants.Routes.hackerRoutes.patchAcceptHackerById,
31+
Constants.Routes.hackerRoutes.patchAcceptHackerByEmail,
32+
Constants.Routes.hackerRoutes.patchAcceptHackerByArrayOfIds,
33+
Constants.Routes.settingsRoutes.getSettings,
34+
Constants.Routes.settingsRoutes.patchSettings
35+
];
36+
2337
const adminRole = {
2438
_id: mongoose.Types.ObjectId.createFromTime(1),
2539
name: Constants.General.STAFF,
2640
routes: Constants.Routes.listAllRoutes()
2741
};
2842

43+
const hackboardRole = {
44+
_id: mongoose.Types.ObjectId.createFromTime(9),
45+
name: "Hackboard",
46+
routes: createHackboardRoutes()
47+
};
48+
2949
const hackerRole = {
3050
_id: mongoose.Types.ObjectId.createFromTime(2),
3151
name: Constants.General.HACKER,
@@ -143,6 +163,15 @@ const singularRoles = createAllSingularRoles();
143163
const allRolesObject = createAllRoles();
144164
const allRolesArray = Object.values(allRolesObject);
145165

166+
function createHackboardRoutes() {
167+
const restrictedRouteIds = new Set(
168+
hackboardRestrictedRoutes.map((route) => route._id.toString())
169+
);
170+
return Constants.Routes.listAllRoutes().filter((route) => {
171+
return !restrictedRouteIds.has(route._id.toString());
172+
});
173+
}
174+
146175
/**
147176
* Creates all the roles that are of a specific uri and request type
148177
* @return {Role[]}
@@ -185,6 +214,7 @@ function createAllRoles() {
185214
let allRolesObject = {
186215
accountRole: accountRole,
187216
adminRole: adminRole,
217+
hackboardRole: hackboardRole,
188218
hackerRole: hackerRole,
189219
volunteerRole: volunteerRole,
190220
sponsorT1Role: sponsorT1Role,
@@ -208,6 +238,7 @@ function createAllRoles() {
208238
module.exports = {
209239
accountRole: accountRole,
210240
adminRole: adminRole,
241+
hackboardRole: hackboardRole,
211242
hackerRole: hackerRole,
212243
volunteerRole: volunteerRole,
213244
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 =

routes/api/hacker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,12 @@ module.exports = {
269269

270270
/**
271271
* @api {patch} /hacker/status/:id update a hacker's status - DOES NOT trigger an email to the hacker
272+
* updates all hacker data fields passed
272273
* @apiName patchHackerStatus
273274
* @apiGroup Hacker
274275
* @apiVersion 0.0.9
275276
*
276-
* @apiParam (body) {string} [status] Status of the hacker's application ("None"|"Applied"|"Accepted"|"Declined"|"Waitlisted"|"Confirmed"|"Withdrawn"|"Checked-in")
277+
* @apiParam (body) {string} [status] Status of the hacker's application ("None"|"Applied"|"Accepted"|"Declined"|"Waitlisted"|"Confirmed"|"Withdrawn"|"Checked-in") as well as reviewer fields and any other hacker data in hacker data object
277278
* @apiSuccess {string} message Success message
278279
* @apiSuccess {object} data Hacker object
279280
* @apiSuccessExample {object} Success-Response:
@@ -283,7 +284,8 @@ module.exports = {
283284
* "status": "Accepted"
284285
* }
285286
* }
286-
* @apiPermission Administrator
287+
* @apiPermission Administrator / Hackboard
288+
*
287289
*/
288290
hackerRouter.route("/status/:id").patch(
289291
Middleware.Validator.RouteParam.idValidator,

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)