Skip to content

Commit

Permalink
[sessions] Adjust server-side interface of Os_session.disconnect_all
Browse files Browse the repository at this point in the history
So that it is possible to call `Os_session.disconnect_all` outside
a request or the initialization phase of the Eliom module (see
https://ocsigen.org/eliom/dev/api/server/Eliom_state.Ext#VALfold_volatile_sub_states).
  • Loading branch information
ilankri committed Mar 21, 2022
1 parent e577488 commit a5b5c2e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion opam
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ depends: [
"pgocaml_ppx" {>= "4.0"}
"safepass" {>= "3.0"}
"ocsigen-i18n" {>= "4.0.0"}
"eliom" {>= "9.3.0" & < "10.0.0"}
"eliom" {>= "10.0.0" & < "11.0.0"}
"ocsigen-toolkit" {>= "2.7.0"}
"ocsigen-ppx-rpc"
"ocsigen-i18n" {>= "3.7.0"}
Expand Down
15 changes: 9 additions & 6 deletions src/os_session.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ let set_warn_connection_change, warn_connection_changed =
let r = ref (fun _ -> ()) in
(fun f -> r := f), fun state -> !r state; Lwt.return_unit

let disconnect_all ?userid ?(user_indep = true) ?(with_restart = true) () =
let disconnect_all ?sitedata ?userid ?(user_indep = true) ?(with_restart = true)
()
=
let close_my_sessions = userid = None in
let%lwt () =
if close_my_sessions then pre_close_session_action () else Lwt.return_unit
Expand Down Expand Up @@ -163,7 +165,7 @@ let disconnect_all ?userid ?(user_indep = true) ?(with_restart = true) () =
let%lwt acc = acc in
Lwt.return (s :: acc))
Lwt.return_nil
(Eliom_state.Ext.fold_volatile_sub_states
(Eliom_state.Ext.fold_volatile_sub_states ?sitedata
~state:
(Eliom_state.Ext.volatile_data_group_state
~scope:Eliom_common.default_group_scope group_name)
Expand All @@ -174,8 +176,8 @@ let disconnect_all ?userid ?(user_indep = true) ?(with_restart = true) () =
let%lwt () =
Lwt_list.iter_s
(fun state ->
Eliom_state.Ext.iter_sub_states ~state @@ fun state ->
Eliom_state.Ext.discard_state ~state)
Eliom_state.Ext.iter_sub_states ?sitedata ~state @@ fun state ->
Eliom_state.Ext.discard_state ?sitedata ~state ())
states
in
let%lwt () =
Expand All @@ -187,15 +189,16 @@ let disconnect_all ?userid ?(user_indep = true) ?(with_restart = true) () =
let%lwt () =
Lwt_list.iter_s
(fun state ->
Eliom_state.Ext.iter_sub_states ~state warn_connection_changed)
Eliom_state.Ext.iter_sub_states ?sitedata ~state
warn_connection_changed)
ui_states
in
(* Closing user_indep states, if requested: *)
let%lwt () =
if user_indep
then
Lwt_list.iter_s
(fun state -> Eliom_state.Ext.discard_state ~state)
(fun state -> Eliom_state.Ext.discard_state ?sitedata ~state ())
ui_states
else Lwt.return_unit
in
Expand Down
11 changes: 10 additions & 1 deletion src/os_session.eliomi
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ val connect : ?expire:bool -> Os_types.User.id -> unit Lwt.t
*)

val disconnect_all
: ?userid:Os_types.User.id
: ?sitedata:Eliom_common.sitedata
-> ?userid:Os_types.User.id
-> ?user_indep:bool
-> ?with_restart:bool
-> unit
Expand All @@ -96,6 +97,14 @@ val disconnect_all
(default), will also affect [user_indep_session_scope].
If [?with_restart] is [true]
(default), will also restart the client.
If you do not call the function during
a request or during the initialisation phase of the Eliom module:
- [?userid] must not be [None]
- [?with_restart] must be [false]
- you must provide the extra parameter [?sitedata],
that you can get by calling [Eliom_request_info.get_sitedata]
during the initialisation phase of the Eliom module.
*)

[%%client.start]
Expand Down
2 changes: 1 addition & 1 deletion template.distillery/PROJECT_NAME.opam
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: "0.1"
synopsis: "Pseudo package for defining project dependencies"

depends: [
"eliom" {>= "9.3.0" & < "10.0.0"}
"eliom" {>= "10.0.0" & < "11.0.0"}
"ocsipersist-pgsql" {>= "1.0" & < "2.0"}
"ocsigen-start"
]

0 comments on commit a5b5c2e

Please sign in to comment.