Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TECH-2970] Add ballot reference param to request access code #288

Merged
merged 2 commits into from
Jan 31, 2024
Merged
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
6 changes: 4 additions & 2 deletions lib/av_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,19 @@ export class AVClient implements IAVClient {
*
* @param opaqueVoterId Voter ID that preserves voter anonymity.
* @param email where the voter expects to receive otp code.
* @param ballotReference The ballot which which voter voter intends to vote on
* @returns Returns undefined or throws an error.
* @throws VoterRecordNotFound if no voter was found
* @throws {@link NetworkError | NetworkError } if any request failed to get a response
*/
public async requestAccessCode(opaqueVoterId: string, email: string): Promise<void> {
public async requestAccessCode(opaqueVoterId: string, email: string, ballotReference?: string): Promise<void> {
const coordinatorURL = this.getLatestConfig().items.voterAuthorizerConfig.content.voterAuthorizer.url;
const voterAuthorizerContextUuid = this.getLatestConfig().items.voterAuthorizerConfig.content.voterAuthorizer.contextUuid;
const coordinator = new VoterAuthorizationCoordinator(coordinatorURL, voterAuthorizerContextUuid);

return coordinator.createSession(opaqueVoterId, email)
return coordinator.createSession(opaqueVoterId, email, ballotReference)
.then(({ data: { sessionId } }) => {
// In the US voters are allowed to chose their ballot
return sessionId as string
})
.then(async sessionId => {
Expand Down
9 changes: 6 additions & 3 deletions lib/av_client/connectors/voter_authorization_coordinator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios, { AxiosInstance, AxiosResponse } from 'axios'
import { IdentityConfirmationToken } from "./otp_provider";
import { EmailDoesNotMatchVoterRecordError, NetworkError, UnsupportedServerReplyError, VoterRecordNotFoundError, DBBError } from "../errors";
import { EmailDoesNotMatchVoterRecordError, NetworkError, UnsupportedServerReplyError, VoterRecordNotFoundError, DBBError, BallotReferenceNotOnVoterRecord } from "../errors";
import { ProofOfElectionCodes } from "../crypto/proof_of_election_codes";
import { BallotBoxReceipt } from '../types';

Expand All @@ -18,11 +18,12 @@ export default class VoterAuthorizationCoordinator {
* @param opaqueVoterId Gets
* @returns
*/
createSession(opaqueVoterId: string, email: string): Promise<AxiosResponse> {
createSession(opaqueVoterId: string, email: string, ballotReference?: string): Promise<AxiosResponse> {
return this.backend.post('create_session', {
electionContextUuid: this.electionContextUuid,
opaqueVoterId: opaqueVoterId,
email
ballotReference: ballotReference,
email,
}).catch(error => {
const response = error.response;

Expand All @@ -34,6 +35,8 @@ export default class VoterAuthorizationCoordinator {
const errorCode = response.data.error_code;
const errorMessage = response.data.error_message;
switch(errorCode) {
case 'BALLOT_REFERERENCE_NOT_ON_VOTER_RECORD':
throw new BallotReferenceNotOnVoterRecord(errorMessage);
case 'EMAIL_DOES_NOT_MATCH_VOTER_RECORD':
throw new EmailDoesNotMatchVoterRecordError(errorMessage);
case 'COULD_NOT_CONNECT_TO_OTP_PROVIDER':
Expand Down
9 changes: 9 additions & 0 deletions lib/av_client/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ export class EmailDoesNotMatchVoterRecordError extends AvClientError {
}
}

export class BallotReferenceNotOnVoterRecord extends AvClientError {
readonly name = "BallotReferenceNotOnVoterRecord";

constructor(message: string) {
super(message);
Object.setPrototypeOf(this, BallotReferenceNotOnVoterRecord.prototype);
}
}

export class DBBError extends AvClientError {
readonly name = "DBB_ERROR";

Expand Down
Loading