Commit 431bcca9 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Add voters_list to metadata

parent 132e8742
......@@ -94,4 +94,5 @@ type randomness = {
type metadata = {
voting_starts_at : datetime;
voting_ends_at : datetime;
?voters_list : string list option;
} <ocaml field_prefix="e_">
......@@ -7,6 +7,7 @@ open Lwt
let () = Ocsigen_config.set_maxrequestbodysizeinmemory 128000
module EMap = Map.Make(Uuidm)
module SSet = Set.Make(String)
let ( / ) = Filename.concat
......@@ -60,6 +61,28 @@ lwt election_table =
Serializable_j.read_ff_pubkey raw
in
let fingerprint = sha256_b64 raw in
lwt metadata =
let fn = path/"metadata.json" in
lwt b = file_exists fn in
if b then (
Lwt_io.chars_of_file fn |>
Lwt_stream.to_string >>=
wrap1 Serializable_j.metadata_of_string >>=
(fun x -> return (Some x))
) else return None
in
let can_vote = match metadata with
| None -> Web_common.Any
| Some m -> match m.e_voters_list with
| None -> Web_common.Any
| Some voters ->
let set = List.fold_left (fun accu u ->
SSet.add u accu
) SSet.empty voters in
Web_common.Restricted (fun u ->
return (SSet.mem (Web_common.string_of_user u) set)
)
in
let election_data = Web_common.({
fn_election;
fingerprint;
......@@ -67,23 +90,13 @@ lwt election_table =
fn_public_keys;
featured_p = true;
can_read = Any;
can_vote = Any;
can_vote;
}) in
let {g; p; q; y} = election.e_public_key in
let module G = (val
Election.finite_field ~p ~q ~g :
Signatures.GROUP with type t = Z.t
) in
lwt metadata =
let fn = path/"metadata.json" in
lwt b = file_exists fn in
if b then (
Lwt_io.chars_of_file fn |>
Lwt_stream.to_string >>=
wrap1 Serializable_j.metadata_of_string >>=
(fun x -> return (Some x))
) else return None
in
let module P = struct
module G = G
let public_keys = lazy (assert false)
......
{"voting_starts_at":"2013-06-22 09:18:04.836200","voting_ends_at":"2013-06-29 09:18:04.836200"}
\ No newline at end of file
{"voting_starts_at":"2013-06-22 09:18:04.836200","voting_ends_at":"2013-06-29 09:18:04.836200","voters_list":["dummy:tata","dummy:titi","dummy:toto","dummy:tutu"]}
\ No newline at end of file
......@@ -73,6 +73,7 @@ let metadata =
{
e_voting_starts_at = add now Period.(day 1), None;
e_voting_ends_at = add now Period.(day 8), None;
e_voters_list = None;
}
;;
......
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