Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
belenios
belenios
Commits
c182704b
Commit
c182704b
authored
Feb 12, 2014
by
Stephane Glondu
Browse files
Refactor handling of election pseudo-files
parent
acaaccb1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/web/registration.ml
View file @
c182704b
...
...
@@ -496,75 +496,69 @@ let () = Eliom_registration.File.register
return
f
)
let
()
=
Eliom_registration
.
File
.
register
~
service
:
Services
.
election_raw
~
content_type
:
"application/json"
(
if_eligible
can_read
(
fun
uuid
election
user
()
->
return
Web_common
.(
election
.
election_web
.
params_fname
)
)
)
let
f_raw
uuid
election
user
()
=
return
Web_common
.(
election
.
election_web
.
params_fname
)
let
()
=
Eliom_registration
.
File
.
register
~
service
:
Services
.
election_public_keys
~
content_type
:
"application/json"
(
if_eligible
can_read
(
fun
uuid
election
user
()
->
return
Web_common
.(
election
.
election_web
.
public_keys_fname
)
)
)
let
f_keys
uuid
election
user
()
=
return
Web_common
.(
election
.
election_web
.
public_keys_fname
)
let
()
=
Eliom_registration
.
Streamlist
.
register
~
service
:
Services
.
election_public_creds
(
if_eligible
can_read
(
fun
uuid
election
user
()
->
let
open
Web_common
in
let
module
X
=
(
val
election
.
modules
:
WEB_BALLOT_BOX_BUNDLE
with
type
elt
=
Z
.
t
)
in
lwt
creds
=
X
.
B
.
extract_creds
()
in
let
s
=
Web_common
.
SSet
.
fold
(
fun
x
accu
->
(
fun
()
->
return
(
Ocsigen_stream
.
of_string
(
x
^
"
\n
"
)))
::
accu
)
creds
[]
in
return
(
List
.
rev
s
,
"text/plain"
)
)
)
let
f_creds
uuid
election
user
()
=
let
open
Web_common
in
let
module
X
=
(
val
election
.
modules
:
WEB_BALLOT_BOX_BUNDLE
with
type
elt
=
Z
.
t
)
in
lwt
creds
=
X
.
B
.
extract_creds
()
in
let
s
=
Web_common
.
SSet
.
fold
(
fun
x
accu
->
(
fun
()
->
return
(
Ocsigen_stream
.
of_string
(
x
^
"
\n
"
)))
::
accu
)
creds
[]
in
return
(
List
.
rev
s
,
"text/plain"
)
let
()
=
Eliom_registration
.
Streamlist
.
register
~
service
:
Services
.
election_ballots
(
if_eligible
can_read
(
fun
uuid
election
user
()
->
let
open
Web_common
in
let
module
X
=
(
val
election
.
modules
:
WEB_BALLOT_BOX_BUNDLE
with
type
elt
=
Z
.
t
)
in
(* TODO: streaming *)
lwt
ballots
=
X
.
B
.
fold_ballots
(
fun
x
xs
->
return
((
x
^
"
\n
"
)
::
xs
)
)
[]
in
let
s
=
List
.
map
(
fun
b
()
->
return
(
Ocsigen_stream
.
of_string
b
)
)
ballots
in
return
(
s
,
"application/json"
)
)
)
let
f_ballots
uuid
election
user
()
=
let
open
Web_common
in
let
module
X
=
(
val
election
.
modules
:
WEB_BALLOT_BOX_BUNDLE
with
type
elt
=
Z
.
t
)
in
(* TODO: streaming *)
lwt
ballots
=
X
.
B
.
fold_ballots
(
fun
x
xs
->
return
((
x
^
"
\n
"
)
::
xs
)
)
[]
in
let
s
=
List
.
map
(
fun
b
()
->
return
(
Ocsigen_stream
.
of_string
b
)
)
ballots
in
return
(
s
,
"application/json"
)
let
f_records
uuid
election
user
()
=
if
Web_common
.
is_admin
user
then
(
let
open
Web_common
in
let
module
X
=
(
val
election
.
modules
:
WEB_BALLOT_BOX_BUNDLE
with
type
elt
=
Z
.
t
)
in
(* TODO: streaming *)
lwt
ballots
=
X
.
B
.
fold_records
(
fun
(
u
,
d
)
xs
->
let
x
=
Printf
.
sprintf
"%s %S
\n
"
(
Serializable_builtin_j
.
string_of_datetime
d
)
u
in
return
(
x
::
xs
)
)
[]
in
let
s
=
List
.
map
(
fun
b
()
->
return
(
Ocsigen_stream
.
of_string
b
)
)
ballots
in
return
(
s
,
"text/plain"
)
)
else
forbidden
()
let
()
=
Eliom_registration
.
Streamlist
.
register
~
service
:
Services
.
election_records
(
if_eligible
can_read
(
fun
uuid
election
user
()
->
if
Web_common
.
is_admin
user
then
(
let
open
Web_common
in
let
module
X
=
(
val
election
.
modules
:
WEB_BALLOT_BOX_BUNDLE
with
type
elt
=
Z
.
t
)
in
(* TODO: streaming *)
lwt
ballots
=
X
.
B
.
fold_records
(
fun
(
u
,
d
)
xs
->
let
x
=
Printf
.
sprintf
"%s %S
\
n
"
(
Serializable_builtin_j
.
string_of_datetime
d
)
u
in
return
(
x
::
xs
)
)
[]
in
let
s
=
List
.
map
(
fun
b
()
->
return
(
Ocsigen_
stre
am
.
of_string
b
)
)
ballots
in
return
(
s
,
"text/plain"
)
)
else
forbidden
()
)
)
let
()
=
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/jso
n"
(
if_eligible
can_read
f_keys
);
Streamlist
.
register
~
service
:
election_public_creds
(
if_eligible
can_read
f_creds
);
Streamli
st
.
re
gister
~
service
:
election_
ballots
(
if_eligible
can_read
f_ballots
);
Streamlist
.
register
~
service
:
election_records
(
if_eligible
can_read
f_records
)
let
get_randomness
=
let
prng
=
Lazy
.
lazy_from_fun
(
Lwt_preemptive
.
detach
(
fun
()
->
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment