Commit 725ac65d authored by Stephane Glondu's avatar Stephane Glondu Committed by Stéphane Glondu

Rework presentation of links in election_draft_trustees

parent 50bb1722
Pipeline #105558 passed with stages
in 27 minutes and 20 seconds
......@@ -347,13 +347,16 @@ let with_site_user f =
| Some u -> f u
| None -> forbidden ()
let without_site_user f =
let without_site_user ?fallback f =
match%lwt Eliom_reference.get Web_state.site_user with
| None -> f ()
| Some _ ->
T.generic_page ~title:"Error"
"This page is not accessible to authenticated administrators, because it is meant to be used by third parties."
() >>= Html.send
| Some u ->
match fallback with
| Some g -> g u
| None ->
T.generic_page ~title:"Error"
"This page is not accessible to authenticated administrators, because it is meant to be used by third parties."
() >>= Html.send
let () =
Redirection.register ~service:privacy_notice_accept
......@@ -1027,7 +1030,16 @@ let () =
let () =
Any.register ~service:election_draft_trustee
(fun (uuid, token) () ->
without_site_user (fun () ->
without_site_user
~fallback:(fun u ->
match%lwt Web_persist.get_draft_election uuid with
| None -> fail_http 404
| Some se ->
if se.se_owner = u then (
T.election_draft_trustees ~token uuid se () >>= Html.send
) else forbidden ()
)
(fun () ->
match%lwt Web_persist.get_draft_election uuid with
| None -> fail_http 404
| Some se -> T.election_draft_trustee token uuid se () >>= Html.send
......
......@@ -637,7 +637,7 @@ Thank you for your help,
-- \nThe election administrator."
let election_draft_trustees uuid se () =
let election_draft_trustees ?token uuid se () =
let title = "Trustees for election " ^ se.se_questions.t_name in
let form_trustees_add =
post_form
......@@ -662,45 +662,78 @@ let election_draft_trustees uuid se () =
let trustees = match se.se_public_keys with
| [] -> pcdata ""
| ts ->
table (
tr [
th [pcdata "Trustee"];
th [pcdata "Mail"];
th [pcdata "Link"];
th [pcdata "Done?"];
th [pcdata "Remove"];
] ::
List.mapi (fun i t ->
tr [
td [
pcdata t.st_id;
];
td [
if t.st_token <> "" then (
let uri = rewrite_prefix @@ Eliom_uri.make_string_uri
~absolute:true ~service:election_draft_trustee (uuid, t.st_token)
in
let body = Printf.sprintf mail_trustee_generation uri in
let subject = "Link to generate the decryption key" in
a_mailto ~dest:t.st_id ~subject ~body "Mail"
) else (
pcdata "(server)"
)
];
td [
if t.st_token <> "" then (
a ~service:election_draft_trustee [pcdata "Link"] (uuid, t.st_token);
) else (
pcdata "(server)"
)
];
td [
pcdata (if t.st_public_key = "" then "No" else "Yes");
];
td [if t.st_id = "server" then pcdata "(cannot be removed)" else mk_form_trustee_del i];
]
let ts =
List.mapi
(fun i t ->
let this_line =
match token with
| Some x when x = t.st_token -> true
| _ -> false
in
let first_line =
tr [
td [
pcdata t.st_id;
];
td [
if t.st_token <> "" then (
let uri = rewrite_prefix @@ Eliom_uri.make_string_uri
~absolute:true ~service:election_draft_trustee (uuid, t.st_token)
in
let body = Printf.sprintf mail_trustee_generation uri in
let subject = "Link to generate the decryption key" in
a_mailto ~dest:t.st_id ~subject ~body "Mail"
) else (
pcdata "(server)"
)
];
td [
if t.st_token <> "" then (
if this_line then
a ~service:election_draft_trustees [pcdata "Hide link"] uuid
else
a ~service:election_draft_trustee [pcdata "Link"] (uuid, t.st_token);
) else (
pcdata "(server)"
)
];
td [
pcdata (if t.st_public_key = "" then "No" else "Yes");
];
td [if t.st_id = "server" then pcdata "(cannot be removed)" else mk_form_trustee_del i];
]
in
let second_line =
if this_line then
[
tr
[
td ~a:[a_colspan 5]
[
pcdata "The link that must be sent to trustee ";
pcdata t.st_id;
pcdata " is:";
br ();
Eliom_uri.make_string_uri ~absolute:true
~service:election_draft_trustee (uuid, t.st_token)
|> rewrite_prefix |> pcdata
]
]
]
else []
in
first_line :: second_line
) ts
)
in
table (
tr [
th [pcdata "Trustee"];
th [pcdata "Mail"];
th [pcdata "Link"];
th [pcdata "Done?"];
th [pcdata "Remove"];
] :: (List.flatten ts)
)
in
let import_link = div [
a ~service:Web_services.election_draft_import_trustees
......
......@@ -43,7 +43,7 @@ val election_draft_voters : uuid -> draft_election -> int -> unit -> [> `Html ]
val election_draft_questions : uuid -> draft_election -> unit -> [> `Html ] Eliom_content.Html.F.elt Lwt.t
val election_draft_credential_authority : uuid -> draft_election -> unit -> [> `Html ] Eliom_content.Html.F.elt Lwt.t
val election_draft_credentials : string -> uuid -> draft_election -> unit -> [> `Html ] Eliom_content.Html.F.elt Lwt.t
val election_draft_trustees : uuid -> draft_election -> unit -> [> `Html ] Eliom_content.Html.F.elt Lwt.t
val election_draft_trustees : ?token:string -> uuid -> draft_election -> unit -> [> `Html ] Eliom_content.Html.F.elt Lwt.t
val election_draft_threshold_trustees : uuid -> draft_election -> unit -> [> `Html ] Eliom_content.Html.F.elt Lwt.t
val election_draft_trustee : string -> uuid -> draft_election -> unit -> [> `Html ] Eliom_content.Html.F.elt Lwt.t
val election_draft_threshold_trustee : string -> uuid -> draft_election -> unit -> [> `Html ] Eliom_content.Html.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