Skip to content

Commit

Permalink
Removing the storage of a voter email for checking if they have voted
Browse files Browse the repository at this point in the history
  • Loading branch information
COMTOP1 committed Apr 7, 2024
1 parent f84c954 commit 807313f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 90 deletions.
5 changes: 4 additions & 1 deletion controllers/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func (r *VoteRepo) AddVote(c echo.Context) error {
return fmt.Errorf("url not found")
}

if u1.Voted {
return fmt.Errorf("this url has expired")
}

err = c.Request().ParseForm()
if err != nil {
return err
Expand All @@ -134,7 +138,6 @@ func (r *VoteRepo) AddVote(c echo.Context) error {

ballot := &storage.Ballot{
Election: u1.GetElection(),
Voter: u1.GetVoter(),
Choice: m,
}

Expand Down
135 changes: 63 additions & 72 deletions storage/storage.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion storage/storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ message STV {
message Ballot {
string id = 1;
string election = 2;
string voter = 3;
map<uint64, string> choice = 4; // map[order, candidate id]
}

Expand Down
21 changes: 5 additions & 16 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ func (store *Store) AddBallot(ballot *storage.Ballot) (*storage.Ballot, error) {
return nil, err
}

for _, e := range stv.GetBallots() {
if e.GetElection() == ballot.GetElection() && e.GetVoter() == ballot.GetVoter() {
return nil, fmt.Errorf("ballot already exists for AddBallot")
}
}

beforeUUID:
ballot.Id = uuid.NewString()

Expand All @@ -59,18 +53,13 @@ beforeUUID:

for _, election := range stv.GetElections() {
if election.GetId() == ballot.GetElection() {
for _, voter := range stv.GetVoters() {
if voter.GetEmail() == ballot.GetVoter() {
stv.Ballots = append(stv.GetBallots(), ballot)

if err = store.backend.Write(stv); err != nil {
return nil, err
}
stv.Ballots = append(stv.GetBallots(), ballot)

return ballot, nil
}
if err = store.backend.Write(stv); err != nil {
return nil, err
}
return nil, fmt.Errorf("unable to find voter for AddBallot")

return ballot, nil
}
}

Expand Down

0 comments on commit 807313f

Please sign in to comment.