From 9e91eb6dbd7b3d4ba220eefa1f179517a53560c3 Mon Sep 17 00:00:00 2001 From: eznarf <41272412+eznarf@users.noreply.github.com> Date: Thu, 11 Jul 2024 22:27:05 -0700 Subject: [PATCH 1/4] Updating backend to accept quick poll voter ids --- packages/backend/src/Controllers/voterRollUtils.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/Controllers/voterRollUtils.ts b/packages/backend/src/Controllers/voterRollUtils.ts index 8a467ee9..ad5e6bf4 100644 --- a/packages/backend/src/Controllers/voterRollUtils.ts +++ b/packages/backend/src/Controllers/voterRollUtils.ts @@ -17,7 +17,14 @@ export async function getOrCreateElectionRoll(req: IRequest, election: Election, // Get data that is used for voter authentication const require_ip_hash = election.settings.voter_authentication.ip_address ? ip_hash : null const email = election.settings.voter_authentication.email ? req.user?.email : null - let voter_id = election.settings.voter_authentication.voter_id ? req.cookies?.voter_id : null + + // Get voter ID if required and available, otherwise set to null + let voter_id = null + if (election.settings.voter_authentication.voter_id && election.settings.voter_access == 'closed') { + voter_id = req.cookies?.voter_id + } else if (election.settings.voter_authentication.voter_id && election.settings.voter_access == 'open') { + voter_id = req.user?.sub + } // Get all election roll entries that match any of the voter authentication fields // This is an odd way of going about this, rather than getting a roll that matches all three we get all that match any of the fields and @@ -99,9 +106,12 @@ export async function getOrCreateElectionRoll(req: IRequest, election: Election, export function checkForMissingAuthenticationData(req: IRequest, election: Election, ctx: ILoggingContext): string | null { // Checks that user has provided all data needed for authentication Logger.info(req, `checkForMissingAuthenticationData`) - if (election.settings.voter_authentication.voter_id && !(req.cookies?.voter_id)) { + if ((election.settings.voter_authentication.voter_id && election.settings.voter_access == 'closed') && !(req.cookies?.voter_id)) { return 'Voter ID Required' } + if ((election.settings.voter_authentication.voter_id && election.settings.voter_access == 'open') && !(req.user)) { + return 'User ID Required' + } if (election.settings.voter_authentication.email && !(req.user?.email)) { return 'Email Validation Required' } From 4b58b0fd929a012596153c11daa50f9c7d6873dd Mon Sep 17 00:00:00 2001 From: eznarf <41272412+eznarf@users.noreply.github.com> Date: Thu, 11 Jul 2024 22:27:48 -0700 Subject: [PATCH 2/4] Updating Quick Poll default authentication to voter_id --- packages/frontend/src/components/ElectionForm/QuickPoll.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend/src/components/ElectionForm/QuickPoll.tsx b/packages/frontend/src/components/ElectionForm/QuickPoll.tsx index 105a2933..aa93e358 100644 --- a/packages/frontend/src/components/ElectionForm/QuickPoll.tsx +++ b/packages/frontend/src/components/ElectionForm/QuickPoll.tsx @@ -55,7 +55,7 @@ const QuickPoll = ({ authSession, methodName, grow }) => { settings: { voter_access: 'open', voter_authentication: { - ip_address: true, + voter_id: true, }, ballot_updates: false, public_results: true, From 982804d1a19bd5a89b021ba7380b1b13d5027e03 Mon Sep 17 00:00:00 2001 From: eznarf <41272412+eznarf@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:29:26 -0700 Subject: [PATCH 3/4] Fixing bug that was overwriting device id --- packages/backend/src/Controllers/voterRollUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/Controllers/voterRollUtils.ts b/packages/backend/src/Controllers/voterRollUtils.ts index ad5e6bf4..17c144b9 100644 --- a/packages/backend/src/Controllers/voterRollUtils.ts +++ b/packages/backend/src/Controllers/voterRollUtils.ts @@ -25,7 +25,7 @@ export async function getOrCreateElectionRoll(req: IRequest, election: Election, } else if (election.settings.voter_authentication.voter_id && election.settings.voter_access == 'open') { voter_id = req.user?.sub } - + // Get all election roll entries that match any of the voter authentication fields // This is an odd way of going about this, rather than getting a roll that matches all three we get all that match any of the fields and // check the output for a number of edge cases. @@ -44,7 +44,7 @@ export async function getOrCreateElectionRoll(req: IRequest, election: Election, return null } Logger.info(req, "Creating new roll"); - const new_voter_id = randomUUID() + const new_voter_id = election.settings.voter_authentication.voter_id ? voter_id : randomUUID() const history = [{ action_type: ElectionRollState.approved, actor: new_voter_id, From f89d2b11a2f35f62af4765e17cf1916e357ce9b2 Mon Sep 17 00:00:00 2001 From: eznarf <41272412+eznarf@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:31:47 -0700 Subject: [PATCH 4/4] Removing voter id textbox if voter access is open --- packages/frontend/src/components/Election/VoterAuth.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend/src/components/Election/VoterAuth.tsx b/packages/frontend/src/components/Election/VoterAuth.tsx index 52bb2d80..7863bda2 100644 --- a/packages/frontend/src/components/Election/VoterAuth.tsx +++ b/packages/frontend/src/components/Election/VoterAuth.tsx @@ -35,7 +35,7 @@ const VoterAuth = () => { const isOpen = election.state === "open" - const voterIdRequired = election.settings?.voter_authentication?.voter_id + const voterIdRequired = election.settings?.voter_authentication?.voter_id && election.settings.voter_access === 'closed' const emailRequired = election.settings?.voter_authentication?.email const isAuthorized = voterAuth?.authorized_voter