Commit e8fdeb64 authored by Stephane Glondu's avatar Stephane Glondu

Add voters.txt pseudo-file

parent 31847b88
user10@example.com
user11@example.com
user12@example.com
user13@example.com
user14@example.com
user15@example.com
user16@example.com
user17@example.com
user18@example.com
user19@example.com
user20@example.com
......@@ -164,6 +164,7 @@ type election_file =
| ESKeys
| ESCreds
| ESBallots
| ESVoters
| ESRecords
| ESETally
| ESResult
......@@ -174,6 +175,7 @@ let election_file_of_string = function
| "public_creds.txt" -> ESCreds
| "ballots.jsons" -> ESBallots
| "records" -> ESRecords
| "voters.txt" -> ESVoters
| "encrypted_tally.json" -> ESETally
| "result.json" -> ESResult
| x -> invalid_arg ("election_dir_item: " ^ x)
......@@ -184,6 +186,7 @@ let string_of_election_file = function
| ESCreds -> "public_creds.txt"
| ESBallots -> "ballots.jsons"
| ESRecords -> "records"
| ESVoters -> "voters.txt"
| ESETally -> "encrypted_tally.json"
| ESResult -> "result.json"
......
......@@ -73,6 +73,7 @@ type election_file =
| ESKeys
| ESCreds
| ESBallots
| ESVoters
| ESRecords
| ESETally
| ESResult
......
......@@ -95,6 +95,7 @@ let read_election_dir dir =
f_metadata = path/"metadata.json";
f_public_keys = path/"public_keys.jsons";
f_public_creds = path/"public_creds.txt";
f_voters = path/"voters.txt";
}, item.datadir_featured)
)
......
......@@ -97,6 +97,7 @@ type election_files = {
f_metadata : string;
f_public_keys : string;
f_public_creds : string;
f_voters : string;
}
module type REGISTRABLE_ELECTION = sig
......
......@@ -54,6 +54,8 @@ let delete_shallow_directory dir =
in
Lwt_unix.rmdir dir
let concat = String.concat
open Eliom_service
open Eliom_registration
......@@ -139,6 +141,7 @@ let import_election f =
let module G = P.G in
let module KG = Election.MakeSimpleDistKeyGen (G) (LwtRandom) in
let public_keys = Lwt_io.lines_of_file f.f_public_keys in
let voters = Lwt_io.lines_of_file f.f_voters in
lwt pks = Lwt_stream.(
clone public_keys |>
map (trustee_public_key_of_string G.read) |>
......@@ -170,6 +173,9 @@ let import_election f =
Lwt_io.(with_file Output (dir/"public_keys.jsons") (fun oc ->
write_lines oc public_keys
)) >>
Lwt_io.(with_file Output (dir/"voters.txt") (fun oc ->
write_lines oc voters
)) >>
let election = do_register () in
let module W = (val election : WEB_ELECTION) in
lwt () =
......@@ -641,6 +647,7 @@ let () =
f_metadata = !spool_dir / uuid_s ^ ".metadata.json";
f_public_keys = !spool_dir / uuid_s ^ ".public_keys.jsons";
f_public_creds = !spool_dir / uuid_s ^ ".public_creds.txt";
f_voters = !spool_dir / uuid_s ^ ".voters.txt";
} in
lwt _ =
try_lwt Lwt_unix.stat files.f_public_creds
......@@ -655,6 +662,7 @@ let () =
in
create_file files.f_election (string_of_params G.write_wrapped_pubkey params) >>
create_file files.f_metadata (string_of_metadata se.se_metadata) >>
create_file files.f_voters (concat "\n" se.se_voters) >>
Lwt_io.with_file
~flags:(Unix.([O_WRONLY; O_NONBLOCK; O_CREAT; O_TRUNC]))
~perm:0o600
......@@ -688,6 +696,7 @@ let () =
Lwt_unix.unlink files.f_metadata >>
Lwt_unix.unlink files.f_public_keys >>
Lwt_unix.unlink files.f_public_creds >>
Lwt_unix.unlink files.f_voters >>
(* clean up tokens *)
Ocsipersist.remove election_credtokens se.se_public_creds >>
Lwt_list.iter_s
......@@ -1052,12 +1061,17 @@ let () =
let content_type_of_file = function
| ESRaw | ESKeys | ESBallots | ESETally | ESResult -> "application/json"
| ESCreds | ESRecords -> "text/plain"
| ESCreds | ESRecords | ESVoters -> "text/plain"
let handle_pseudo_file w u f site_user =
let module W = (val w : WEB_ELECTION) in
let confidential =
match f with
| ESRaw | ESKeys | ESBallots | ESETally | ESResult | ESCreds -> false
| ESRecords | ESVoters -> true
in
lwt () =
if f = ESRecords then (
if confidential then (
match site_user with
| Some u when W.metadata.e_owner = Some u -> return ()
| _ -> forbidden ()
......
......@@ -789,6 +789,9 @@ let election_admin w ~is_featured state () =
div [
a ~service:election_update_credential [pcdata "Update a credential"] (uuid, ());
];
div [
a ~service:election_dir [pcdata "Voter list"] (uuid, ESVoters);
];
div [
a ~service:election_dir [pcdata "Voting records"] (uuid, ESRecords);
];
......
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