Skip to content

Commit

Permalink
Prevent admin from fetching votes for ongoing election
Browse files Browse the repository at this point in the history
  • Loading branch information
ApsiV11 committed Nov 22, 2024
1 parent 065f5f9 commit c5a487b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"title": "Auditing",
"ballot_id": "Ballot ID",
"ballot": "Ballot",
"election_not_ongoing_or_finished": "There is no finished election",
"election_not_ongoing_or_finished_description": "You can only audit the election whose results have just been published. If you think this is an error, please contact the chairperson or secretary.",
"no_finished_election": "There is no finished election",
"no_finished_election_description": "You can only audit the election whose results have just been published. If you think this is an error, please contact the chairperson or secretary.",
"empty_ballot": "Empty ballot"
},
"info": {
Expand Down
4 changes: 2 additions & 2 deletions public/locales/fi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"title": "Auditointi",
"ballot_id": "Äänestyslipun tunniste",
"ballot": "Äänestyslippu",
"election_not_ongoing_or_finished": "Ei päättynyttä vaalia",
"election_not_ongoing_or_finished_description": "Voit tarkastella vain juuri päättynyttä vaalia. Jos tämä on mielestäsi virhe, ota yhteyttä puheenjohtajaan tai sihteeriin.",
"no_finished_election": "Ei päättynyttä vaalia",
"no_finished_election_description": "Voit tarkastella vain juuri päättynyttä vaalia. Jos tämä on mielestäsi virhe, ota yhteyttä puheenjohtajaan tai sihteeriin.",
"empty_ballot": "Tyhjä äänestyslippu"
},
"info": {
Expand Down
15 changes: 12 additions & 3 deletions src/backend/handlers/admin/votes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response, Router } from 'express'

import { getVotes } from '../../routes/admin/votes'
import { getCompletedElectionWithVotes } from '../../routes/elections'
import { validateUuid } from '../../validation/validation'

export const handleFetchVotesForElection = async (
Expand All @@ -9,8 +9,17 @@ export const handleFetchVotesForElection = async (
) => {
const { electionId } = req.params
try {
const votes = await getVotes(electionId)
res.status(200).json(votes)
const election = await getCompletedElectionWithVotes(electionId)
if (!election) {
res.status(404).json({ key: 'election_not_found' })
return
}

if (election.status !== 'FINISHED' && election.status !== 'CLOSED') {
res.status(400).json({ key: 'election_not_completed' })
return
}
res.status(200).json(election.ballots)
} catch (err) {
if (err instanceof Error) {
res.status(500).json({ message: err.message })
Expand Down
10 changes: 0 additions & 10 deletions src/backend/routes/admin/votes.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/frontend/components/audit/Audit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ export const Audit = () => {
<Card.Header as="h2">{t('title')}</Card.Header>
<Card.Body>
<Alert className="d-flex flex-column text-center" variant="info">
<Alert.Heading>
{t('election_not_ongoing_or_finished')}
</Alert.Heading>
<p>{t('election_not_ongoing_or_finished_description')}</p>
<Alert.Heading>{t('no_finished_election')}</Alert.Heading>
<p>{t('no_finished_election_description')}</p>
</Alert>
</Card.Body>
</Card>
Expand Down

0 comments on commit c5a487b

Please sign in to comment.