Skip to content
New issue

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

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

Already on GitHub? # to your account

Always increment check-in numbers, even after undo #158

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
3 changes: 1 addition & 2 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,11 @@ function buildApi(context: AppContext) {
voterId: string;
identificationMethod: VoterIdentificationMethod;
}): Promise<void> {
const { voter, count } = store.recordVoterCheckIn(input);
const { voter } = store.recordVoterCheckIn(input);
debug('Checked in voter %s', voter.voterId);

const receipt = React.createElement(CheckInReceipt, {
voter,
count,
machineId,
});
debug('Printing check-in receipt for voter %s', voter.voterId);
Expand Down
4 changes: 1 addition & 3 deletions backend/src/receipts/check_in_receipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import {

export function CheckInReceipt({
voter,
count,
machineId,
}: {
voter: Voter;
count: number;
machineId: string;
}): JSX.Element {
const { checkIn } = voter;
Expand All @@ -33,7 +31,7 @@ export function CheckInReceipt({
>
<div>
<div>
<strong>Check-In Number: {count}</strong>
<strong>Check-In #{checkIn.checkInNumber}</strong>
</div>
{checkIn.isAbsentee && <div>Absentee</div>}
<div>
Expand Down
4 changes: 2 additions & 2 deletions backend/src/receipts/undo_check_in_receipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function UndoCheckInReceipt({
>
<div>
<div>
<strong>Undo Check-In</strong>
<strong>Undo Check-In #{checkIn.checkInNumber}</strong>
</div>
<div>{format.localeNumericDateAndTime(new Date())}</div>
<div>Pollbook: {machineId}</div>
Expand All @@ -57,7 +57,7 @@ export function UndoCheckInReceipt({
<br />

<div>
<strong>Check-In Details</strong>
<strong>Check-In #{checkIn.checkInNumber} Details</strong>
</div>
<div>{format.localeNumericDateAndTime(new Date(checkIn.timestamp))}</div>
<div>Pollbook: {checkIn.machineId}</div>
Expand Down
22 changes: 20 additions & 2 deletions backend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,19 +507,37 @@ export class Store {
return this.currentClock.now();
}

private nextCheckInNumber(): number {
// Count all of the check-in events that have occurred and add one. This
// ensures that when we undo a check-in, the next check-in will have a
// unique number. Note that we don't have any cross-machine locking, so it's
// still possible for two machines to generate the same check-in number if
// they have a different set of events.
const { checkInCount } = this.client.one(
`
SELECT COUNT(*) as checkInCount
FROM event_log
WHERE event_type = ?
`,
EventType.VoterCheckIn
) as { checkInCount: number };
return checkInCount + 1;
}

recordVoterCheckIn({
voterId,
identificationMethod,
}: {
voterId: string;
identificationMethod: VoterIdentificationMethod;
}): { voter: Voter; count: number } {
}): { voter: Voter } {
debug('Recording check-in for voter %s', voterId);
const voters = this.getVoters();
assert(voters);
const voter = voters[voterId];
const isoTimestamp = new Date().toISOString();
voter.checkIn = {
checkInNumber: this.nextCheckInNumber(),
identificationMethod,
isAbsentee: this.getIsAbsenteeMode(),
machineId: this.machineId,
Expand All @@ -540,7 +558,7 @@ export class Store {
})
);
});
return { voter, count: this.getCheckInCount() };
return { voter };
}

recordUndoVoterCheckIn(voterId: string): Voter {
Expand Down
1 change: 1 addition & 0 deletions backend/src/test_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function createVoterCheckInEvent(
timestamp: hlcTimestamp,
voterId,
checkInData: {
checkInNumber: localEventId,
timestamp,
identificationMethod: {
type: 'photoId',
Expand Down
2 changes: 2 additions & 0 deletions backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ export type VoterIdentificationMethod =
};

export interface VoterCheckIn {
checkInNumber: number;
identificationMethod: VoterIdentificationMethod;
isAbsentee: boolean;
timestamp: string;
machineId: string;
}

export const VoterCheckInSchema: z.ZodSchema<VoterCheckIn> = z.object({
checkInNumber: z.number(),
identificationMethod: z.union([
z.object({
type: z.literal('photoId'),
Expand Down
4 changes: 2 additions & 2 deletions libs/ui/src/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ import {
faPrint,
faRotate,
faEnvelope,
faCircleXmark,
} from '@fortawesome/free-solid-svg-icons';
import {
faXmarkCircle,
faPauseCircle,
faSquare,
faCircle,
Expand Down Expand Up @@ -263,7 +263,7 @@ export const Icons = {
},

Delete(props) {
return <FaIcon {...props} type={faXmarkCircle} />;
return <FaIcon {...props} type={faCircleXmark} />;
},

Disabled(props) {
Expand Down