Commit 41433bd2 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Remove one layer of nesting

parent 7d274e7a
......@@ -156,16 +156,3 @@ type 'a result = {
partial_decryptions : 'a partial_decryption list <ocaml repr="array">;
result : raw_result;
}
type 'a election_public_data = {
public_keys : 'a trustee_public_key list <ocaml repr="array">;
?election_result : 'a result option;
admin : user;
private_p : bool;
featured_p : bool;
state : election_state;
}
type 'a election_private_data = {
private_keys : 'a private_key list <ocaml repr="array">;
}
......@@ -6,7 +6,12 @@ type election_data = {
raw : string;
fingerprint : string;
election : Z.t election;
public_data : Z.t election_public_data;
public_keys : Z.t trustee_public_key array;
election_result : Z.t result option;
admin : user;
private_p : bool;
featured_p : bool;
state : election_state;
}
let enforce_single_element s =
......@@ -77,14 +82,6 @@ let load_elections_and_votes dirname =
in return (Some { encrypted_tally; partial_decryptions; result }, `Finished)
| None -> return (None, `Started)
in
let public_data = {
public_keys;
election_result;
admin = { user_name = "admin"; user_type = "dummy" };
private_p = false;
featured_p = true;
state;
} in
let fingerprint = hashB raw in
let ballots =
let file = data "ballots.json" in
......@@ -97,7 +94,17 @@ let load_elections_and_votes dirname =
)
) else Lwt_stream.from_direct (fun () -> None)
in
let election_data = { raw; fingerprint; election; public_data } in
let election_data = {
raw;
fingerprint;
election;
public_keys;
election_result;
admin = { user_name = "admin"; user_type = "dummy" };
private_p = false;
featured_p = true;
state;
} in
Lwt.return (Some (election_data, ballots))
| None -> assert false
) else Lwt.return None
......
......@@ -4,7 +4,12 @@ type election_data = {
raw : string;
fingerprint : string;
election : Z.t election;
public_data : Z.t election_public_data;
public_keys : Z.t trustee_public_key array;
election_result : Z.t result option;
admin : user;
private_p : bool;
featured_p : bool;
state : election_state;
}
val hashB : string -> string
......
......@@ -49,7 +49,7 @@ let get_election_by_uuid x =
let get_featured_elections () =
(* FIXME: doesn't scale when there are a lot of unfeatured elections *)
Ocsipersist.fold_step (fun uuid e res ->
let res = if e.Common.public_data.featured_p then e::res else res in
let res = if e.Common.featured_p then e::res else res in
return res
) elections_table []
......@@ -63,7 +63,7 @@ let if_eligible f uuid x =
lwt election = get_election_by_uuid uuid in
lwt user = Eliom_reference.get Services.user in
lwt () =
if election.Common.public_data.private_p then (
if election.Common.private_p then (
match user with
| Some user ->
lwt eligible = Services.is_eligible uuid user in
......@@ -108,19 +108,6 @@ let () = Eliom_registration.String.register
)
)
let () = Eliom_registration.String.register
~service:Services.election_public_data
(if_eligible
(fun uuid election user () ->
return (
Serializable_compat_j.string_of_election_public_data
Serializable_builtin_j.write_number
election.Common.public_data,
"application/json"
)
)
)
let () = Eliom_registration.String.register
~service:Services.election_ballots
(if_eligible
......@@ -184,7 +171,7 @@ let () = Eliom_registration.Html5.register
module G = (val Election.finite_field ~p ~q ~g : Signatures.GROUP with type t = Z.t)
let public_keys = Array.map (fun x ->
x.trustee_public_key.y
) election.Common.public_data.public_keys
) election.Common.public_keys
let params = Serializable_compat.election election.Common.election
let fingerprint = assert false
end in
......
......@@ -85,11 +85,6 @@ let election_ballots = service
~get_params:uuid
()
let election_public_data = service
~path:["election"; "public-data"]
~get_params:uuid
()
let election_cast_post = post_service
~fallback:election_cast
~post_params:(string "encrypted_vote")
......
......@@ -150,7 +150,7 @@ let format_one_featured_election e =
~a:[a_style "font-size: 1.4em;"]
[pcdata e.Common.election.e_name] ();
pcdata " by ";
] @ format_user e.Common.public_data.admin 15 @ [
] @ format_user e.Common.admin 15 @ [
br ();
pcdata e.Common.election.e_description;
]);
......@@ -228,7 +228,7 @@ let election_view ~election ~user =
let service = Services.(preapply_uuid election_raw election) in
let booth = Services.make_booth election.Common.election.e_uuid in
lwt eligibility =
if not election.Common.public_data.private_p && election.Common.election.e_openreg then (
if not election.Common.private_p && election.Common.election.e_openreg then (
Lwt.return [
pcdata "Anyone can vote in this election.";
]
......@@ -275,10 +275,6 @@ let election_view ~election ~user =
pcdata "Ballot Tracking Center";
] ();
pcdata " | ";
a ~service:Services.(preapply_uuid election_public_data election) [
pcdata "Election data";
] ();
pcdata " | ";
a ~service:booth [
pcdata "Voting booth";
] ();
......@@ -290,14 +286,14 @@ let election_view ~election ~user =
h2 ~a:[a_class ["title"]] [pcdata election.Common.election.e_name];
p ~a:[a_style "padding-top:0px; margin-top:0px"] [
em [
pcdata (if election.Common.public_data.private_p then "private" else "public")
pcdata (if election.Common.private_p then "private" else "public")
];
pcdata " election created by ";
u [ b (format_user election.Common.public_data.admin 15) ];
u [ b (format_user election.Common.admin 15) ];
pcdata " with ";
pcdata (string_of_int (Array.length election.Common.election.e_questions));
pcdata " question(s) and ";
pcdata (string_of_int (Array.length election.Common.public_data.public_keys));
pcdata (string_of_int (Array.length election.Common.public_keys));
pcdata " trustee(s)";
];
];
......@@ -307,7 +303,7 @@ let election_view ~election ~user =
div ~a:[a_style "margin-bottom: 25px;margin-left: 15px; border-left: 1px solid #aaa; padding-left: 5px; font-size:1.3em;"] [pcdata election.Common.election.e_description];
(* NOTE: administration things removed from here! *)
br ();
] @ (match election.Common.public_data.state, election.Common.public_data.election_result with
] @ (match election.Common.state, election.Common.election_result with
| `Finished, Some r ->
let result = format_election_result election.Common.election r in
[
......
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