From 70b4b585b000ee171189bc3d2455f9d9f811ca83 Mon Sep 17 00:00:00 2001 From: Daniel Kristiansen Date: Mon, 25 Aug 2025 15:55:16 +0200 Subject: [PATCH 1/8] Election committe now able to see applications from the law committee --- backend/controllers/committeeController.ts | 8 +++++--- backend/utils/constants.ts | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/controllers/committeeController.ts b/backend/controllers/committeeController.ts index 297e82a9..e43ee19e 100644 --- a/backend/controllers/committeeController.ts +++ b/backend/controllers/committeeController.ts @@ -1,7 +1,7 @@ import { NextFunction, Request, Response } from 'express' import { CustomError, UnauthorizedUserError } from 'ntnui-tools/customError' import { CommitteeModel } from '../models/Committee' -import { ELECTION_COMMITTEE_ID, MAIN_BOARD_ID } from '../utils/constants' +import { ELECTION_COMMITTEE_ID, MAIN_BOARD_ID, LAW_COMMITTEE_ID } from '../utils/constants' import { RequestWithNtnuiNo } from '../utils/request' import { getUserRoleInCommitteeByUserId } from '../utils/userCommittee' @@ -32,9 +32,11 @@ async function acceptAdmissions( // If user is organizer, allow toggle of all except main board (userCommittee.committee === MAIN_BOARD_ID && committee._id !== MAIN_BOARD_ID) || - // If user part of election committee, allow toggle of own and main board + // If user part of election committee, allow toggle of own, main board and the law committee (userCommittee.committee === ELECTION_COMMITTEE_ID && - committee._id === MAIN_BOARD_ID) || + committee._id === userCommittee.committee || + committee._id === MAIN_BOARD_ID || + committee._id === LAW_COMMITTEE_ID) ||
 // If user is board member of the committee and is not in the main board (userCommittee.committee === committee._id && committee._id !== MAIN_BOARD_ID) diff --git a/backend/utils/constants.ts b/backend/utils/constants.ts index 51195ce2..029aea43 100644 --- a/backend/utils/constants.ts +++ b/backend/utils/constants.ts @@ -1,8 +1,10 @@ -/* eslint-disable no-console */ +
/* eslint-disable no-console */ const MAIN_BOARD_ID = Number(process.env.MAIN_BOARD_ID) || 52 const ELECTION_COMMITTEE_ID = Number(process.env.ELECTION_COMMITTEE_ID) || 71 +const LAW_COMMITTEE_ID = Number(process.env.ELECTION_COMMITTEE_ID) || 72 console.log(`🔗 MAIN_BOARD_ID set to ${MAIN_BOARD_ID}`) console.log(`🔗 ELECTION_COMMITTEE_ID set to ${ELECTION_COMMITTEE_ID}`) +console.log(`🔗 LAW_COMMITTEE_ID set to ${LAW_COMMITTEE_ID}`) -export { MAIN_BOARD_ID, ELECTION_COMMITTEE_ID } +export { MAIN_BOARD_ID, ELECTION_COMMITTEE_ID, LAW_COMMITTEE_ID } From 0af8c924c587b496be522f8fe779047868083f44 Mon Sep 17 00:00:00 2001 From: Daniel Kristiansen Date: Mon, 25 Aug 2025 16:00:08 +0200 Subject: [PATCH 2/8] Prettier fix --- backend/controllers/committeeController.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/controllers/committeeController.ts b/backend/controllers/committeeController.ts index e43ee19e..45bf2ff4 100644 --- a/backend/controllers/committeeController.ts +++ b/backend/controllers/committeeController.ts @@ -1,7 +1,11 @@ import { NextFunction, Request, Response } from 'express' import { CustomError, UnauthorizedUserError } from 'ntnui-tools/customError' import { CommitteeModel } from '../models/Committee' -import { ELECTION_COMMITTEE_ID, MAIN_BOARD_ID, LAW_COMMITTEE_ID } from '../utils/constants' +import { + ELECTION_COMMITTEE_ID, + MAIN_BOARD_ID, + LAW_COMMITTEE_ID, +} from '../utils/constants' import { RequestWithNtnuiNo } from '../utils/request' import { getUserRoleInCommitteeByUserId } from '../utils/userCommittee' @@ -14,7 +18,7 @@ const getCommittees = (_req: Request, res: Response) => { async function acceptAdmissions( req: RequestWithNtnuiNo, res: Response, - next: NextFunction + next: NextFunction, ) { try { const { ntnuiNo } = req @@ -34,12 +38,12 @@ async function acceptAdmissions( committee._id !== MAIN_BOARD_ID) || // If user part of election committee, allow toggle of own, main board and the law committee (userCommittee.committee === ELECTION_COMMITTEE_ID && - committee._id === userCommittee.committee || - committee._id === MAIN_BOARD_ID || - committee._id === LAW_COMMITTEE_ID) ||
 + committee._id === userCommittee.committee) || + committee._id === MAIN_BOARD_ID || + committee._id === LAW_COMMITTEE_ID || // If user is board member of the committee and is not in the main board (userCommittee.committee === committee._id && - committee._id !== MAIN_BOARD_ID) + committee._id !== MAIN_BOARD_ID), ) if (isAuthorized) { // Toggle accepts_admissions for a committee @@ -50,13 +54,13 @@ async function acceptAdmissions( .then(() => res.status(200).json({ accepts_admissions: committee.accepts_admissions, - }) + }), ) .catch((err) => res.status(500).json({ message: err.message })) } throw new CustomError( 'You are not authorized to change the admission status of this committee', - 403 + 403, ) } catch (error) { return next(error) From fed67203a007ed5c8b1fbdb25ac19d5a277aaa35 Mon Sep 17 00:00:00 2001 From: Daniel Kristiansen Date: Mon, 25 Aug 2025 16:14:52 +0200 Subject: [PATCH 3/8] Fix typo and prettier fix --- backend/controllers/committeeController.ts | 17 ++++++++++------- backend/utils/constants.ts | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/controllers/committeeController.ts b/backend/controllers/committeeController.ts index 45bf2ff4..91cd0ff7 100644 --- a/backend/controllers/committeeController.ts +++ b/backend/controllers/committeeController.ts @@ -37,13 +37,16 @@ async function acceptAdmissions( (userCommittee.committee === MAIN_BOARD_ID && committee._id !== MAIN_BOARD_ID) || // If user part of election committee, allow toggle of own, main board and the law committee - (userCommittee.committee === ELECTION_COMMITTEE_ID && - committee._id === userCommittee.committee) || - committee._id === MAIN_BOARD_ID || - committee._id === LAW_COMMITTEE_ID || - // If user is board member of the committee and is not in the main board - (userCommittee.committee === committee._id && - committee._id !== MAIN_BOARD_ID), + ( + userCommittee.committee === ELECTION_COMMITTEE_ID && + (committee._id === userCommittee.committee || + committee._id === MAIN_BOARD_ID || + committee._id === LAW_COMMITTEE_ID) + )( + // If user is board member of the committee and is not in the main board + userCommittee.committee === committee._id && + committee._id !== MAIN_BOARD_ID, + ), ) if (isAuthorized) { // Toggle accepts_admissions for a committee diff --git a/backend/utils/constants.ts b/backend/utils/constants.ts index 029aea43..4c61e82c 100644 --- a/backend/utils/constants.ts +++ b/backend/utils/constants.ts @@ -1,7 +1,7 @@ -
/* eslint-disable no-console */ +/* eslint-disable no-console */ const MAIN_BOARD_ID = Number(process.env.MAIN_BOARD_ID) || 52 const ELECTION_COMMITTEE_ID = Number(process.env.ELECTION_COMMITTEE_ID) || 71 -const LAW_COMMITTEE_ID = Number(process.env.ELECTION_COMMITTEE_ID) || 72 +const LAW_COMMITTEE_ID = Number(process.env.LAW_COMMITTEE_ID) || 72 console.log(`🔗 MAIN_BOARD_ID set to ${MAIN_BOARD_ID}`) console.log(`🔗 ELECTION_COMMITTEE_ID set to ${ELECTION_COMMITTEE_ID}`) From fce0324f28f6e9b640900fe8ca4d9f3981f48829 Mon Sep 17 00:00:00 2001 From: Daniel Kristiansen Date: Mon, 25 Aug 2025 16:21:28 +0200 Subject: [PATCH 4/8] Fixing error in parenthesis --- backend/controllers/committeeController.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/backend/controllers/committeeController.ts b/backend/controllers/committeeController.ts index 91cd0ff7..a5c6ecc5 100644 --- a/backend/controllers/committeeController.ts +++ b/backend/controllers/committeeController.ts @@ -37,16 +37,13 @@ async function acceptAdmissions( (userCommittee.committee === MAIN_BOARD_ID && committee._id !== MAIN_BOARD_ID) || // If user part of election committee, allow toggle of own, main board and the law committee - ( - userCommittee.committee === ELECTION_COMMITTEE_ID && + (userCommittee.committee === ELECTION_COMMITTEE_ID && (committee._id === userCommittee.committee || committee._id === MAIN_BOARD_ID || - committee._id === LAW_COMMITTEE_ID) - )( - // If user is board member of the committee and is not in the main board - userCommittee.committee === committee._id && - committee._id !== MAIN_BOARD_ID, - ), + committee._id === LAW_COMMITTEE_ID)) || + // If user is board member of the committee and is not in the main board + (userCommittee.committee === committee._id && + committee._id !== MAIN_BOARD_ID), ) if (isAuthorized) { // Toggle accepts_admissions for a committee From 7bb37c0c85c538739828f5942ff91d4afc9981f1 Mon Sep 17 00:00:00 2001 From: Daniel Kristiansen Date: Mon, 25 Aug 2025 16:33:19 +0200 Subject: [PATCH 5/8] Prettier fix --- backend/controllers/committeeController.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/controllers/committeeController.ts b/backend/controllers/committeeController.ts index a5c6ecc5..4f7e542d 100644 --- a/backend/controllers/committeeController.ts +++ b/backend/controllers/committeeController.ts @@ -18,7 +18,7 @@ const getCommittees = (_req: Request, res: Response) => { async function acceptAdmissions( req: RequestWithNtnuiNo, res: Response, - next: NextFunction, + next: NextFunction ) { try { const { ntnuiNo } = req @@ -43,7 +43,7 @@ async function acceptAdmissions( committee._id === LAW_COMMITTEE_ID)) || // If user is board member of the committee and is not in the main board (userCommittee.committee === committee._id && - committee._id !== MAIN_BOARD_ID), + committee._id !== MAIN_BOARD_ID) ) if (isAuthorized) { // Toggle accepts_admissions for a committee @@ -54,13 +54,13 @@ async function acceptAdmissions( .then(() => res.status(200).json({ accepts_admissions: committee.accepts_admissions, - }), + }) ) .catch((err) => res.status(500).json({ message: err.message })) } throw new CustomError( 'You are not authorized to change the admission status of this committee', - 403, + 403 ) } catch (error) { return next(error) From d8f6681ab12c9597464d97434f018d0916b2c23f Mon Sep 17 00:00:00 2001 From: Daniel Kristiansen Date: Tue, 26 Aug 2025 19:32:59 +0200 Subject: [PATCH 6/8] Fix admission status to make election committee see law committee and fixtures --- backend/fixtures/development/committees.json | 12 ++++++++++++ frontend/src/pages/AdmissionStatus.tsx | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/fixtures/development/committees.json b/backend/fixtures/development/committees.json index 43efb64d..a8a679c0 100644 --- a/backend/fixtures/development/committees.json +++ b/backend/fixtures/development/committees.json @@ -78,5 +78,17 @@ "deputy_board_member" ], "accepts_admissions": false + }, + { + "_id": 11, + "name": "Lovutvalget", + "slug": "lovutvalget", + "access_roles": [ + "deputy_leader", + "cashier", + "board_member", + "deputy_board_member" + ], + "accepts_admissions": true } ] diff --git a/frontend/src/pages/AdmissionStatus.tsx b/frontend/src/pages/AdmissionStatus.tsx index d476252e..446c77a5 100644 --- a/frontend/src/pages/AdmissionStatus.tsx +++ b/frontend/src/pages/AdmissionStatus.tsx @@ -142,11 +142,11 @@ function AdmissionStatus() { committee.slug !== 'valgkomiteen' && committee.slug !== 'hovedstyret' ) }) - // Election committee can see main board + // Election committee can see main board and the law committee } else if (locationState.isElectionCommittee) { allCommittees = await getAllCommittees() allCommittees = allCommittees.filter((committee: ICommittee) => { - return committee.slug === 'hovedstyret' + return committee.slug === 'hovedstyret' || committee.slug === 'lovutvalget' }) // Include the users other committees const committeesRes = await getUserCommittees() From ad86b82ff2d2cb890a355d8fbb5ff24306815854 Mon Sep 17 00:00:00 2001 From: Daniel Kristiansen Date: Tue, 26 Aug 2025 19:36:57 +0200 Subject: [PATCH 7/8] Prettier --- frontend/src/pages/AdmissionStatus.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/AdmissionStatus.tsx b/frontend/src/pages/AdmissionStatus.tsx index 446c77a5..47fa1944 100644 --- a/frontend/src/pages/AdmissionStatus.tsx +++ b/frontend/src/pages/AdmissionStatus.tsx @@ -146,7 +146,9 @@ function AdmissionStatus() { } else if (locationState.isElectionCommittee) { allCommittees = await getAllCommittees() allCommittees = allCommittees.filter((committee: ICommittee) => { - return committee.slug === 'hovedstyret' || committee.slug === 'lovutvalget' + return ( + committee.slug === 'hovedstyret' || committee.slug === 'lovutvalget' + ) }) // Include the users other committees const committeesRes = await getUserCommittees() From e04cc8b6dcc89101e8e76049880bef774c9da561 Mon Sep 17 00:00:00 2001 From: Daniel Kristiansen Date: Tue, 26 Aug 2025 20:06:08 +0200 Subject: [PATCH 8/8] Updating fixtures in production --- backend/fixtures/production/committees.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/fixtures/production/committees.json b/backend/fixtures/production/committees.json index 5116f00f..3dea2411 100644 --- a/backend/fixtures/production/committees.json +++ b/backend/fixtures/production/committees.json @@ -104,5 +104,12 @@ "slug": "baneutvalget", "access_roles": ["deputy_leader"], "accepts_admissions": true + }, + { + "_id": 72, + "name": "Lovutvalget", + "slug": "lovutvalget", + "access_roles": ["deputy_leader"], + "accepts_admissions": true } ]