Commit 84d53590 authored by Stephane Glondu's avatar Stephane Glondu

Do no longer rely on Ocsipersist for election states

parent 72de861f
......@@ -34,22 +34,19 @@ let get_election_result uuid =
| Some [x] -> return (Some (result_of_string Yojson.Safe.read_json x))
| _ -> return_none
type election_state =
[ `Open
| `Closed
| `EncryptedTally of int * int * string
| `Tallied of plaintext
| `Archived
]
let election_states = Ocsipersist.open_table "election_states"
let get_election_state uuid =
match%lwt read_file ~uuid "state.json" with
| Some [x] -> return @@ election_state_of_string x
| _ -> return `Archived
let get_election_state x =
try%lwt Ocsipersist.find election_states (raw_string_of_uuid x)
with Not_found -> return `Archived
let set_election_state x s =
Ocsipersist.add election_states (raw_string_of_uuid x) s
let set_election_state uuid s =
match s with
| `Archived ->
(
try%lwt Lwt_unix.unlink (!spool_dir / raw_string_of_uuid uuid / "state.json")
with _ -> return_unit
)
| _ -> write_file ~uuid "state.json" [string_of_election_state s]
type election_date =
[ `Creation
......
......@@ -23,13 +23,6 @@ open Serializable_t
open Common
open Web_serializable_t
type election_state =
[ `Open
| `Closed
| `EncryptedTally of int * int * string
| `Tallied of plaintext
| `Archived
]
val get_election_state : uuid -> election_state Lwt.t
val set_election_state : uuid -> election_state -> unit Lwt.t
......
......@@ -74,6 +74,14 @@ type credential_mapping = {
?ballot : string option;
} <ocaml field_prefix="c_">
type election_state =
[ Open
| Closed
| EncryptedTally of (int * int * string)
| Tallied
| Archived
]
(** {1 Types related to elections being prepared} *)
type draft_voter = {
......
......@@ -251,7 +251,7 @@ let cleanup_file f =
let delete_sensitive_data uuid =
let uuid_s = raw_string_of_uuid uuid in
let%lwt () = cleanup_table ~uuid_s "election_states" in
let%lwt () = cleanup_file (!spool_dir / uuid_s / "state.json") in
let%lwt () = cleanup_table ~uuid_s "site_tokens_decrypt" in
let%lwt () = cleanup_table ~uuid_s "election_pds" in
let%lwt () = cleanup_file (!spool_dir / uuid_s / "extended_records.jsons") in
......@@ -384,7 +384,7 @@ let get_validated_elections_by_owner u =
in
let elections, tallied, archived = accu in
match state with
| `Tallied _ -> return (elections, (date, w) :: tallied, archived)
| `Tallied -> return (elections, (date, w) :: tallied, archived)
| `Archived -> return (elections, tallied, (date, w) :: archived)
| _ -> return ((date, w) :: elections, tallied, archived)
) ([], [], [])
......@@ -1719,7 +1719,7 @@ let handle_election_tally_release (uuid, ()) () =
let result = string_of_result W.G.write result in
write_file ~uuid (string_of_election_file ESResult) [result]
in
let%lwt () = Web_persist.set_election_state uuid (`Tallied result.result) in
let%lwt () = Web_persist.set_election_state uuid `Tallied in
let%lwt () = Web_persist.set_election_date `Tally uuid (now ()) in
let%lwt () = Ocsipersist.remove election_tokens_decrypt uuid_s in
redir_preapply election_home (uuid, ()) ()
......@@ -2037,7 +2037,7 @@ let extract_automatic_data_validated uuid_s =
let t = Option.get t default_validation_date in
let next_t = datetime_add t (day days_to_delete) in
return @@ Some (`Delete, uuid, next_t, name, contact)
| `Tallied _ ->
| `Tallied ->
let%lwt t = Web_persist.get_election_date `Tally uuid in
let t = Option.get t default_tally_date in
let next_t = datetime_add t (day days_to_archive) in
......
......@@ -1611,7 +1611,7 @@ let election_home election state () =
b [pcdata hash];
pcdata ".";
]
| `Tallied _ ->
| `Tallied ->
[
pcdata " ";
b [pcdata L.election_has_been_tallied];
......@@ -1887,7 +1887,7 @@ let election_admin election metadata state get_tokens_decrypt () =
];
release_form;
]
| `Tallied _ ->
| `Tallied ->
return @@ div [
pcdata "This election has been tallied.";
]
......@@ -1900,7 +1900,7 @@ let election_admin election metadata state get_tokens_decrypt () =
]
in
let%lwt archive_date = match state with
| `Tallied _ ->
| `Tallied ->
let%lwt t = Web_persist.get_election_date `Tally uuid in
let t = datetime_add (Option.get t default_tally_date) (day days_to_archive) in
return @@
......@@ -1930,7 +1930,7 @@ let election_admin election metadata state get_tokens_decrypt () =
let%lwt t = Web_persist.get_election_date `Validation uuid in
let dt = day days_to_delete in
return @@ datetime_add (Option.get t default_validation_date) dt
| `Tallied _ ->
| `Tallied ->
let%lwt t = Web_persist.get_election_date `Tally uuid in
let dt = day (days_to_archive + days_to_delete) in
return @@ datetime_add (Option.get t default_tally_date) dt
......
......@@ -51,8 +51,8 @@ val election_draft_import : uuid -> draft_election -> 'a election list * 'a elec
val election_draft_import_trustees : uuid -> draft_election -> 'a election list * 'a election list * 'a election list -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_draft_confirm : uuid -> draft_election -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_home : 'a election -> Web_persist.election_state -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_admin : 'a election -> Web_serializable_j.metadata -> Web_persist.election_state -> (unit -> string list Lwt.t) -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_home : 'a election -> election_state -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_admin : 'a election -> Web_serializable_j.metadata -> election_state -> (unit -> string list Lwt.t) -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val update_credential : 'a election -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val regenpwd : uuid -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val cast_raw : 'a election -> unit -> [> `Html ] Eliom_content.Html5.F.elt 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