Commit 72de861f authored by Stephane Glondu's avatar Stephane Glondu

Changes in ballot management functions of Web_persist

parent e4d96c2d
......@@ -20,7 +20,6 @@
(**************************************************************************)
open Lwt
open Platform
open Serializable_j
open Signatures
open Common
......@@ -90,9 +89,8 @@ module Make (E : ELECTION with type 'a m = 'a Lwt.t) : WEB_BALLOT_BOX = struct
(* first vote *)
let%lwt b = Lwt_preemptive.detach E.check_ballot ballot in
if b then (
let hash = sha256_b64 rawballot in
let%lwt hash = Web_persist.add_ballot uuid rawballot in
Web_persist.add_credential_mapping uuid credential (Some hash) >>
Web_persist.add_ballot uuid hash rawballot >>
Web_persist.add_extended_record uuid user (date, credential) >>
send_confirmation_email false login email hash >>
return hash
......@@ -104,10 +102,8 @@ module Make (E : ELECTION with type 'a m = 'a Lwt.t) : WEB_BALLOT_BOX = struct
if credential = old_credential then (
let%lwt b = Lwt_preemptive.detach E.check_ballot ballot in
if b then (
Web_persist.remove_ballot uuid h >>
let hash = sha256_b64 rawballot in
let%lwt hash = Web_persist.replace_ballot uuid h rawballot in
Web_persist.add_credential_mapping uuid credential (Some hash) >>
Web_persist.add_ballot uuid hash rawballot >>
Web_persist.add_extended_record uuid user (date, credential) >>
send_confirmation_email true login email hash >>
return hash
......
......@@ -241,16 +241,22 @@ let dump_ballots uuid =
let%lwt ballots = load_ballots uuid in
write_file ~uuid "ballots.jsons" ballots
let add_ballot uuid hash ballot =
let add_ballot uuid ballot =
let hash = sha256_b64 ballot in
let ballots_dir = !spool_dir / raw_string_of_uuid uuid / "ballots" in
let%lwt () = try%lwt Lwt_unix.mkdir ballots_dir 0o755 with _ -> return_unit in
write_file (ballots_dir / urlize hash) [ballot] >>
dump_ballots uuid
dump_ballots uuid >>
return hash
let remove_ballot uuid hash =
let ballots_dir = !spool_dir / raw_string_of_uuid uuid / "ballots" in
try%lwt Lwt_unix.unlink (ballots_dir / urlize hash) with _ -> return_unit
let replace_ballot uuid hash ballot =
remove_ballot uuid hash >>
add_ballot uuid ballot
let compute_encrypted_tally uuid =
let%lwt election = get_raw_election uuid in
match election with
......
......@@ -64,8 +64,8 @@ val get_threshold : uuid -> string option Lwt.t
val get_ballot_hashes : uuid -> string list Lwt.t
val get_ballot_by_hash : uuid -> string -> string option Lwt.t
val add_ballot : uuid -> string -> string -> unit Lwt.t
val remove_ballot : uuid -> string -> unit Lwt.t
val add_ballot : uuid -> string -> string Lwt.t
val replace_ballot : uuid -> string -> string -> string Lwt.t
val compute_encrypted_tally : uuid -> (int * string * string) Lwt.t
val find_extended_record : uuid -> string -> (datetime * string) option Lwt.t
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment