Commit cd7a876d authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Prettier URLs for election pseudo-files

parent c182704b
......@@ -539,26 +539,28 @@ let f_records uuid election user () =
return (s, "text/plain")
) else forbidden ()
let () =
let handle_pseudo_file u f =
let open Eliom_registration in
let open Services in
File.register
~service:election_raw
~content_type:"application/json"
(if_eligible can_read f_raw);
File.register
~service:election_public_keys
~content_type:"application/json"
(if_eligible can_read f_keys);
Streamlist.register
~service:election_public_creds
(if_eligible can_read f_creds);
Streamlist.register
~service:election_ballots
(if_eligible can_read f_ballots);
Streamlist.register
~service:election_records
(if_eligible can_read f_records)
let file f =
if_eligible can_read f u () >>=
File.send ~content_type:"application/json"
and stream f =
if_eligible can_read f u () >>=
Streamlist.send >>=
(fun x -> return (cast_unknown_content_kind x))
in
match f with
| ESRaw -> file f_raw
| ESKeys -> file f_keys
| ESCreds -> stream f_creds
| ESBallots -> stream f_ballots
| ESRecords -> stream f_records
let () =
Eliom_registration.Any.register
~service:Services.election_dir
(fun (uuid, f) () -> handle_pseudo_file uuid f)
let get_randomness =
let prng = Lazy.lazy_from_fun (Lwt_preemptive.detach (fun () ->
......
......@@ -60,28 +60,43 @@ let uuid = Eliom_parameter.user_type
Uuidm.to_string
"uuid"
(* TODO: put uuid in url instead of GET parameter *)
type election_file =
| ESRaw
| ESKeys
| ESCreds
| ESBallots
| ESRecords
let election_file_of_string = function
| "election.json" -> ESRaw
| "public_keys.jsons" -> ESKeys
| "public_creds.txt" -> ESCreds
| "ballots.jsons" -> ESBallots
| "records" -> ESRecords
| x -> invalid_arg ("election_dir_item: " ^ x)
let string_of_election_file = function
| ESRaw -> "election.json"
| ESKeys -> "public_keys.jsons"
| ESCreds -> "public_creds.txt"
| ESBallots -> "ballots.jsons"
| ESRecords -> "records"
let election_file = Eliom_parameter.user_type
election_file_of_string
string_of_election_file
"file"
let election_dir = service
~path:["elections"]
~get_params:(suffix (uuid ** election_file))
()
let election_index = service
~path:["election"; ""]
~get_params:uuid
()
let election_raw = service
~path:["election"; "election.json"]
~get_params:uuid
()
let election_public_keys = service
~path:["election"; "public_keys.jsons"]
~get_params:uuid
()
let election_public_creds = service
~path:["election"; "public_creds.txt"]
~get_params:uuid
()
let election_vote = service
~path:["election"; "vote"]
~get_params:uuid
......@@ -92,16 +107,6 @@ let election_cast = service
~get_params:uuid
()
let election_ballots = service
~path:["election"; "ballots.jsons"]
~get_params:uuid
()
let election_records = service
~path:["election"; "records"]
~get_params:uuid
()
let election_cast_post = post_service
~fallback:election_cast
~post_params:(opt (string "encrypted_vote") ** opt (file "encrypted_vote_file"))
......@@ -135,13 +140,14 @@ let election_booth = static_dir_with_params
()
let make_booth uuid =
let service = Eliom_service.preapply election_raw uuid in
let service = Eliom_service.preapply election_dir (uuid, ESRaw) in
Eliom_service.preapply election_booth (
["booth"; "vote.html"],
Eliom_uri.make_string_uri ~absolute_path:true ~service ()
)
let preapply_uuid s e = Eliom_service.preapply s e.e_uuid
let election_file e f = Eliom_service.preapply election_dir (e.e_uuid, f)
type savable_service =
| Home
......
......@@ -216,7 +216,7 @@ let make_button ~service contents =
let election_view ~auth_systems ~election ~user =
let open Web_common in
let params = election.election.e_params in
let service = Services.(preapply_uuid election_raw params) in
let service = Services.(election_file params ESRaw) in
lwt permissions =
match election.election_web.can_vote with
| Any ->
......@@ -261,15 +261,15 @@ let election_view ~auth_systems ~election ~user =
pcdata "Election data: ";
a ~service [ pcdata "parameters" ] ();
pcdata ", ";
a ~service:Services.(preapply_uuid election_public_creds params) [
a ~service:Services.(election_file params ESCreds) [
pcdata "public credentials"
] ();
pcdata ", ";
a ~service:Services.(preapply_uuid election_public_keys params) [
a ~service:Services.(election_file params ESKeys) [
pcdata "trustee public keys"
] ();
pcdata ", ";
a ~service:Services.(preapply_uuid election_ballots params) [
a ~service:Services.(election_file params ESBallots) [
pcdata "ballots";
] ();
pcdata ".";
......
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