25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

Minor improvements to support mod_tombstones

New check_register_user hook in ejabberd_auth.erl
to allow blocking account registration when a tombstone exists.

Modified room_destroyed hook in mod_muc_room.erl
Until now the hook passed as arguments: LServer, Room, Host.
Now it passes: LServer, Room, Host, Persistent
That new Persistent argument passes the room persistent option,
required by mod_tombstones because only persistent rooms should generate
a tombstone, temporary ones should not.
And the persistent option should not be completely overwritten, as we must
still known its real value even when room is being destroyed.

mod_tombstones is available in experimental mode in ejabberd-contrib git.

Initial feature request: #2546
This commit is contained in:
Badlop 2024-10-14 13:34:42 +02:00
parent 8be0f8a0b0
commit 71ad7c368d
4 changed files with 17 additions and 8 deletions

View File

@ -44,7 +44,7 @@
allow_visitor_nickchange = true :: boolean(),
public = true :: boolean(),
public_list = true :: boolean(),
persistent = false :: boolean(),
persistent = false :: boolean() | {destroying, boolean()},
moderated = true :: boolean(),
captcha_protected = false :: boolean(),
members_by_default = true :: boolean(),

View File

@ -293,6 +293,8 @@ try_register(User, Server, Password) ->
false ->
case ejabberd_router:is_my_host(LServer) of
true ->
case ejabberd_hooks:run_fold(check_register_user, LServer, true, [User, Server, Password]) of
true ->
case lists:foldl(
fun(_, ok) ->
ok;
@ -307,6 +309,9 @@ try_register(User, Server, Password) ->
{error, _} = Err ->
Err
end;
false ->
{error, not_allowed}
end;
false ->
{error, not_allowed}
end

View File

@ -1726,7 +1726,7 @@ make_command_raw_value(Name, Request, BaseArguments) ->
raw_value |
raw_and_value} |
{input_name_append, [binary()]} |
{force_execution, boolean()} |
{force_execution, boolean() | undefined} |
{table_options, {PageSize :: integer(), RemainingPath :: [binary()]}} |
{result_named, boolean()} |
{result_links,
@ -1737,7 +1737,7 @@ make_command_raw_value(Name, Request, BaseArguments) ->
{style, normal | danger}.
make_command2(Name, Request, BaseArguments, Options) ->
Only = proplists:get_value(only, Options, all),
ForceExecution = proplists:get_value(force_execution, Options, false),
ForceExecution = proplists:get_value(force_execution, Options, undefined),
InputNameAppend = proplists:get_value(input_name_append, Options, []),
Resultnamed = proplists:get_value(result_named, Options, false),
ResultLinks = proplists:get_value(result_links, Options, []),
@ -1791,6 +1791,8 @@ make_command2(Name,
case {ForceExecution, ResultFormatApi} of
{true, _} ->
auto;
{false, _} ->
manual;
{_, {_, rescode}} ->
manual;
{_, {_, restuple}} ->

View File

@ -540,7 +540,7 @@ normal_state({route, <<"">>,
case NewStateData of
stop ->
Conf = StateData#state.config,
{stop, normal, StateData#state{config = Conf#config{persistent = false}}};
{stop, normal, StateData#state{config = Conf#config{persistent = {destroying, Conf#config.persistent}}}};
_ when NewStateData#state.just_created ->
close_room_if_temporary_and_empty(NewStateData);
_ ->
@ -736,7 +736,7 @@ handle_event({destroy, Reason}, _StateName,
[jid:encode(StateData#state.jid), Reason]),
add_to_log(room_existence, destroyed, StateData),
Conf = StateData#state.config,
{stop, shutdown, StateData#state{config = Conf#config{persistent = false}}};
{stop, shutdown, StateData#state{config = Conf#config{persistent = {destroying, Conf#config.persistent}}}};
handle_event(destroy, StateName, StateData) ->
?INFO_MSG("Destroyed MUC room ~ts",
[jid:encode(StateData#state.jid)]),
@ -856,7 +856,7 @@ handle_sync_event({muc_unsubscribe, From}, _From, StateName,
from = From, sub_els = [#muc_unsubscribe{}]},
case process_iq_mucsub(From, IQ, StateData) of
{result, _, stop} ->
{stop, normal, StateData#state{config = Conf#config{persistent = false}}};
{stop, normal, StateData#state{config = Conf#config{persistent = {destroying, Conf#config.persistent}}}};
{result, _, NewState} ->
{reply, ok, StateName, NewState};
{ignore, NewState} ->
@ -1015,8 +1015,10 @@ terminate(Reason, _StateName,
_ ->
add_to_log(room_existence, stopped, StateData),
case (StateData#state.config)#config.persistent of
false ->
ejabberd_hooks:run(room_destroyed, LServer, [LServer, Room, Host]);
false ->
ejabberd_hooks:run(room_destroyed, LServer, [LServer, Room, Host, false]);
{destroying, Persistent} ->
ejabberd_hooks:run(room_destroyed, LServer, [LServer, Room, Host, Persistent]);
_ ->
ok
end