Skip to content

Commit 676ea3c

Browse files
author
Jan Rochel
authored
Merge pull request #652 from ilankri/sessions-disconnect-all
2 parents 54c40a5 + 8fd8b1c commit 676ea3c

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
===== 6.1.0 (2022-03-08) =====
2+
* Adjust the server-side interface of Os_session.disconnect_all
3+
14
===== 4.0.0 (2021-01-13) =====
25
* BREAKING CHANGE Os_tips: change the type of 'onclose'
36

opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
opam-version: "2.0"
22
name: "ocsigen-start"
3-
version: "6.0.1"
3+
version: "6.1.0"
44
55
maintainer: "[email protected]"
66
synopsis: "An Eliom application skeleton ready to use to build your own application with users, (pre)registration, notifications, etc"
@@ -23,7 +23,7 @@ depends: [
2323
"pgocaml_ppx" {>= "4.0"}
2424
"safepass" {>= "3.0"}
2525
"ocsigen-i18n" {>= "4.0.0"}
26-
"eliom" {>= "9.3.0" & < "10.0.0"}
26+
"eliom" {>= "10.0.0" & < "11.0.0"}
2727
"ocsigen-toolkit" {>= "2.7.0"}
2828
"ocsigen-ppx-rpc"
2929
"ocsigen-i18n" {>= "3.7.0"}

src/os_session.eliom

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ let set_warn_connection_change, warn_connection_changed =
120120
let r = ref (fun _ -> ()) in
121121
(fun f -> r := f), fun state -> !r state; Lwt.return_unit
122122

123-
let disconnect_all ?userid ?(user_indep = true) () =
123+
let disconnect_all ?sitedata ?userid ?(user_indep = true) ?(with_restart = true)
124+
()
125+
=
124126
let close_my_sessions = userid = None in
125127
let%lwt () =
126128
if close_my_sessions then pre_close_session_action () else Lwt.return_unit
@@ -163,7 +165,7 @@ let disconnect_all ?userid ?(user_indep = true) () =
163165
let%lwt acc = acc in
164166
Lwt.return (s :: acc))
165167
Lwt.return_nil
166-
(Eliom_state.Ext.fold_volatile_sub_states
168+
(Eliom_state.Ext.fold_volatile_sub_states ?sitedata
167169
~state:
168170
(Eliom_state.Ext.volatile_data_group_state
169171
~scope:Eliom_common.default_group_scope group_name)
@@ -174,8 +176,8 @@ let disconnect_all ?userid ?(user_indep = true) () =
174176
let%lwt () =
175177
Lwt_list.iter_s
176178
(fun state ->
177-
Eliom_state.Ext.iter_sub_states ~state @@ fun state ->
178-
Eliom_state.Ext.discard_state ~state)
179+
Eliom_state.Ext.iter_sub_states ?sitedata ~state @@ fun state ->
180+
Eliom_state.Ext.discard_state ?sitedata ~state ())
179181
states
180182
in
181183
let%lwt () =
@@ -187,19 +189,22 @@ let disconnect_all ?userid ?(user_indep = true) () =
187189
let%lwt () =
188190
Lwt_list.iter_s
189191
(fun state ->
190-
Eliom_state.Ext.iter_sub_states ~state warn_connection_changed)
192+
Eliom_state.Ext.iter_sub_states ?sitedata ~state
193+
warn_connection_changed)
191194
ui_states
192195
in
193196
(* Closing user_indep states, if requested: *)
194197
let%lwt () =
195198
if user_indep
196199
then
197200
Lwt_list.iter_s
198-
(fun state -> Eliom_state.Ext.discard_state ~state)
201+
(fun state -> Eliom_state.Ext.discard_state ?sitedata ~state ())
199202
ui_states
200203
else Lwt.return_unit
201204
in
202-
let _ = [%client (Os_handlers.restart () : unit)] in
205+
let () =
206+
if with_restart then ignore [%client (Os_handlers.restart () : unit)]
207+
in
203208
Lwt.return_unit
204209

205210
let check_allow_deny userid allow deny =

src/os_session.eliomi

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,25 @@ val connect : ?expire:bool -> Os_types.User.id -> unit Lwt.t
8686
*)
8787

8888
val disconnect_all
89-
: ?userid:Os_types.User.id
89+
: ?sitedata:Eliom_common.sitedata
90+
-> ?userid:Os_types.User.id
9091
-> ?user_indep:bool
92+
-> ?with_restart:bool
9193
-> unit
9294
-> unit Lwt.t
9395
(** Close all sessions of current user (or [userid] if present).
9496
If [?user_indep] is [true]
9597
(default), will also affect [user_indep_session_scope].
98+
If [?with_restart] is [true]
99+
(default), will also restart the client.
100+
If you do not call the function during
101+
a request or during the initialisation phase of the Eliom module:
102+
103+
- [?userid] must not be [None]
104+
- [?with_restart] must be [false]
105+
- you must provide the extra parameter [?sitedata],
106+
that you can get by calling [Eliom_request_info.get_sitedata]
107+
during the initialisation phase of the Eliom module.
96108
*)
97109

98110
[%%client.start]

template.distillery/PROJECT_NAME.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: "0.1"
44
synopsis: "Pseudo package for defining project dependencies"
55

66
depends: [
7-
"eliom" {>= "9.3.0" & < "10.0.0"}
7+
"eliom" {>= "10.0.0" & < "11.0.0"}
88
"ocsipersist-pgsql" {>= "1.0" & < "2.0"}
99
"ocsigen-start"
1010
]

0 commit comments

Comments
 (0)