Skip to content

Commit

Permalink
Merge pull request #652 from ilankri/sessions-disconnect-all
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Rochel authored Mar 25, 2022
2 parents 54c40a5 + 8fd8b1c commit 676ea3c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
===== 6.1.0 (2022-03-08) =====
* Adjust the server-side interface of Os_session.disconnect_all

===== 4.0.0 (2021-01-13) =====
* BREAKING CHANGE Os_tips: change the type of 'onclose'

Expand Down
4 changes: 2 additions & 2 deletions opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "2.0"
name: "ocsigen-start"
version: "6.0.1"
version: "6.1.0"
authors: "[email protected]"
maintainer: "[email protected]"
synopsis: "An Eliom application skeleton ready to use to build your own application with users, (pre)registration, notifications, etc"
Expand All @@ -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
19 changes: 12 additions & 7 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) () =
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) () =
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) () =
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,19 +189,22 @@ let disconnect_all ?userid ?(user_indep = 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
let _ = [%client (Os_handlers.restart () : unit)] in
let () =
if with_restart then ignore [%client (Os_handlers.restart () : unit)]
in
Lwt.return_unit

let check_allow_deny userid allow deny =
Expand Down
14 changes: 13 additions & 1 deletion src/os_session.eliomi
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,25 @@ 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
-> unit Lwt.t
(** Close all sessions of current user (or [userid] if present).
If [?user_indep] is [true]
(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 676ea3c

Please sign in to comment.