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

Merge election_setup_index into admin

parent c1cf2b22
......@@ -38,8 +38,7 @@ let new_election_post = post_service ~fallback:new_election ~post_params:(file "
let tool = preapply (static_dir ()) ["static"; "belenios-tool.html"]
let election_setup_index = service ~path:["setup"; ""] ~get_params:unit ()
let election_setup_new = post_coservice ~csrf_safe:true ~fallback:election_setup_index ~post_params:unit ()
let election_setup_new = post_coservice ~csrf_safe:true ~fallback:admin ~post_params:unit ()
let election_setup = service ~path:["setup"; "election"] ~get_params:(uuid "uuid") ()
let election_setup_group = post_coservice ~fallback:election_setup ~post_params:(string "group") ()
let election_setup_metadata = post_coservice ~fallback:election_setup ~post_params:(string "metadata") ()
......
......@@ -238,8 +238,9 @@ let () = Html5.register ~service:admin
(fun () () ->
let cont () () = Redirection.send admin in
Eliom_reference.set Web_services.cont cont >>
lwt site_user = Web_site_auth.get_user () in
lwt elections =
match_lwt Web_site_auth.get_user () with
match site_user with
| None -> return []
| Some u ->
SMap.fold (fun _ w accu ->
......@@ -251,7 +252,17 @@ let () = Html5.register ~service:admin
)
) !election_table [] |> List.rev |> return
in
T.admin ~elections (module Web_site_auth : AUTH_SERVICES) ()
lwt setup_elections =
match site_user with
| None -> return []
| Some u ->
Ocsipersist.fold_step (fun k v accu ->
if v.se_owner = u
then return (uuid_of_string k :: accu)
else return accu
) election_stable []
in
T.admin ~elections ~setup_elections (module Web_site_auth) ()
)
let () = File.register
......@@ -316,20 +327,6 @@ let () = Any.register ~service:new_election_post
let generate_uuid = Uuidm.v4_gen (Random.State.make_self_init ())
let () = Html5.register ~service:election_setup_index
(fun () () ->
match_lwt Web_site_auth.get_user () with
| Some u ->
lwt uuids =
Ocsipersist.fold_step (fun k v accu ->
if v.se_owner = u
then return (uuid_of_string k :: accu)
else return accu
) election_stable []
in T.election_setup_index uuids (module Web_site_auth : AUTH_SERVICES) ()
| None -> forbidden ()
)
let () = Redirection.register ~service:election_setup_new
(fun () () ->
match_lwt Web_site_auth.get_user () with
......
......@@ -151,17 +151,26 @@ let home ~featured () =
let login_box = pcdata "" in
base ~title:site_title ~login_box ~content ()
let admin ~elections auth () =
let admin ~elections ~setup_elections auth () =
let title = site_title ^ " — Administration" in
let elections =
match elections with
| [] -> p [pcdata "You cannot administer any elections!"]
| [] -> p [pcdata "You own no such elections!"]
| _ -> ul @@ List.map (format_election `Admin) elections
in
let setup_elections =
match setup_elections with
| [] -> p [pcdata "You own no such elections!"]
| _ -> ul @@
List.map (fun k ->
li [a ~service:election_setup [pcdata (Uuidm.to_string k)] k]
) setup_elections
in
let content = [
div [
div [a ~service:new_election [pcdata "Create a new election"] ()];
div [a ~service:election_setup_index [pcdata "Elections being prepared"] ()];
h2 [pcdata "Elections being prepared"];
setup_elections;
h2 [pcdata "Elections you can administer"];
elections;
];
......@@ -242,25 +251,6 @@ let new_election_failure reason auth () =
lwt login_box = site_login_box auth () in
base ~title ~login_box ~content ()
let election_setup_index uuids auth () =
let service = election_setup in
let title = "Elections being prepared" in
let uuids =
List.map (fun k ->
li [a ~service [pcdata (Uuidm.to_string k)] k]
) uuids
in
let list =
match uuids with
| [] -> div [pcdata "You own no such elections."]
| us -> ul us
in
let content = [
div [list];
] in
lwt login_box = site_login_box auth () in
base ~title ~login_box ~content ()
let generic_page ~title message () =
let content = [
p [pcdata message];
......
......@@ -22,14 +22,13 @@
open Web_signatures
val home : featured:(module WEB_ELECTION) list -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val admin : elections:(module WEB_ELECTION) list -> (module AUTH_SERVICES) -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val admin : elections:(module WEB_ELECTION) list -> setup_elections:(Uuidm.t list) -> (module AUTH_SERVICES) -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val new_election : (module AUTH_SERVICES) -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val new_election_failure : [ `Exists | `Exception of exn ] -> (module AUTH_SERVICES) -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val generic_page : title:string -> string -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_setup_index : Uuidm.t list -> (module AUTH_SERVICES) -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_setup : Uuidm.t -> Web_common.setup_election -> (module AUTH_SERVICES) -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_setup_questions : Uuidm.t -> Web_common.setup_election -> (module AUTH_SERVICES) -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val election_setup_credentials : string -> string -> Web_common.setup_election -> unit -> [> `Html ] Eliom_content.Html5.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