Skip to content
Open
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
9 changes: 8 additions & 1 deletion constants/general.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const SAMPLE_DIET_RESTRICTIONS = [
const HACKER = "Hacker";
const VOLUNTEER = "Volunteer";
const STAFF = "Staff";
const HACKBOARD = "Hackboard";
const SPONSOR = "Sponsor";

const SPONSOR_T1 = "SponsorT1";
Expand Down Expand Up @@ -109,8 +110,9 @@ POST_ROLES[SPONSOR_T4] = "postSponsor";
POST_ROLES[SPONSOR_T5] = "postSponsor";
POST_ROLES[VOLUNTEER] = "postVolunteer";
POST_ROLES[STAFF] = "postStaff";
POST_ROLES[HACKBOARD] = "Hackboard";

const USER_TYPES = [HACKER, VOLUNTEER, STAFF, SPONSOR];
const USER_TYPES = [HACKER, VOLUNTEER, STAFF, HACKBOARD, SPONSOR];
const SPONSOR_TIERS = [
SPONSOR_T1,
SPONSOR_T2,
Expand All @@ -122,6 +124,7 @@ const EXTENDED_USER_TYPES = [
HACKER,
VOLUNTEER,
STAFF,
HACKBOARD,
SPONSOR_T1,
SPONSOR_T2,
SPONSOR_T3,
Expand Down Expand Up @@ -168,6 +171,9 @@ CREATE_ACC_EMAIL_SUBJECTS[
CREATE_ACC_EMAIL_SUBJECTS[
STAFF
] = `You've been invited to create a staff account for ${HACKATHON_NAME}`;
CREATE_ACC_EMAIL_SUBJECTS[
HACKBOARD
] = `You've been invited to create a hackboard account for ${HACKATHON_NAME}`;

const CACHE_TIMEOUT_STATS = 5 * 60 * 1000;
const CACHE_KEY_STATS = "hackerStats";
Expand Down Expand Up @@ -211,6 +217,7 @@ module.exports = {
SPONSOR: SPONSOR,
VOLUNTEER: VOLUNTEER,
STAFF: STAFF,
HACKBOARD: HACKBOARD,
SPONSOR_T1: SPONSOR_T1,
SPONSOR_T2: SPONSOR_T2,
SPONSOR_T3: SPONSOR_T3,
Expand Down
30 changes: 30 additions & 0 deletions constants/role.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,31 @@ const accountRole = {
]
};

const hackboardRestrictedRoutes = [ // hackboard permissions is all staff routes minus these routes
Constants.Routes.hackerRoutes.postAnySendWeekOfEmail,
Constants.Routes.hackerRoutes.postSelfSendWeekOfEmail,
Constants.Routes.hackerRoutes.postAnySendDayOfEmail,
Constants.Routes.hackerRoutes.postSelfSendDayOfEmail,
Constants.Routes.hackerRoutes.patchAcceptHackerById,
Constants.Routes.hackerRoutes.patchAcceptHackerByEmail,
Constants.Routes.hackerRoutes.patchAcceptHackerByArrayOfIds,
Constants.Routes.hackerRoutes.patchAnyStatusById,
Constants.Routes.settingsRoutes.getSettings,
Constants.Routes.settingsRoutes.patchSettings
];

const adminRole = {
_id: mongoose.Types.ObjectId.createFromTime(1),
name: Constants.General.STAFF,
routes: Constants.Routes.listAllRoutes()
};

const hackboardRole = {
_id: mongoose.Types.ObjectId.createFromTime(9),
name: "Hackboard",
routes: createHackboardRoutes()
};

const hackerRole = {
_id: mongoose.Types.ObjectId.createFromTime(2),
name: Constants.General.HACKER,
Expand Down Expand Up @@ -143,6 +162,15 @@ const singularRoles = createAllSingularRoles();
const allRolesObject = createAllRoles();
const allRolesArray = Object.values(allRolesObject);

function createHackboardRoutes() {
const restrictedRouteIds = new Set(
hackboardRestrictedRoutes.map((route) => route._id.toString())
);
return Constants.Routes.listAllRoutes().filter((route) => {
return !restrictedRouteIds.has(route._id.toString());
});
}

/**
* Creates all the roles that are of a specific uri and request type
* @return {Role[]}
Expand Down Expand Up @@ -185,6 +213,7 @@ function createAllRoles() {
let allRolesObject = {
accountRole: accountRole,
adminRole: adminRole,
hackboardRole: hackboardRole,
hackerRole: hackerRole,
volunteerRole: volunteerRole,
sponsorT1Role: sponsorT1Role,
Expand All @@ -208,6 +237,7 @@ function createAllRoles() {
module.exports = {
accountRole: accountRole,
adminRole: adminRole,
hackboardRole: hackboardRole,
hackerRole: hackerRole,
volunteerRole: volunteerRole,
sponsorT1Role: sponsorT1Role,
Expand Down
5 changes: 5 additions & 0 deletions middlewares/auth.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ async function addCreationRoleBindings(req, res, next) {
req.body.account.id,
Constants.Role.adminRole.name
);
} else if (req.body.account.accountType === Constants.General.HACKBOARD) {
await Services.RoleBinding.createRoleBindingByRoleName(
req.body.account.id,
Constants.Role.hackboardRole.name
);
} else {
// Get the default role for the account type given
const roleName =
Expand Down
2 changes: 2 additions & 0 deletions services/accountConfirmation.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ function generateAccountInvitationEmail(address, receiverEmail, type, token) {
emailSubject = Constants.CREATE_ACC_EMAIL_SUBJECTS[Constants.SPONSOR];
} else if (type === Constants.STAFF) {
emailSubject = Constants.CREATE_ACC_EMAIL_SUBJECTS[Constants.STAFF];
} else if (type === Constants.HACKBOARD) {
emailSubject = Constants.CREATE_ACC_EMAIL_SUBJECTS[Constants.HACKBOARD];
}
const handlebarPath = path.join(
__dirname,
Expand Down
3 changes: 3 additions & 0 deletions tests/util/roleBinding.test.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ function createRoleBinding(accountId, accountType = null, specificRoles = []) {
case Constants.General.STAFF:
roleBinding.roles.push(Constants.Role.adminRole);
break;
case Constants.General.HACKBOARD:
roleBinding.roles.push(Constants.Role.hackboardRole);
break;
case Constants.General.SPONSOR_T1:
roleBinding.roles.push(Constants.Role.sponsorT1Role);
break;
Expand Down
Loading