disallow room creation if archive not empty and
clear_archive_on_room_destroy is false
This commit is contained in:
parent
f987db5a39
commit
5e7f234ac8
|
@ -41,7 +41,7 @@
|
||||||
delete_old_messages/2, get_commands_spec/0, msg_to_el/4,
|
delete_old_messages/2, get_commands_spec/0, msg_to_el/4,
|
||||||
get_room_config/4, set_room_option/3, offline_message/1, export/1,
|
get_room_config/4, set_room_option/3, offline_message/1, export/1,
|
||||||
mod_options/1, remove_mam_for_user_with_peer/3, remove_mam_for_user/2,
|
mod_options/1, remove_mam_for_user_with_peer/3, remove_mam_for_user/2,
|
||||||
is_empty_for_user/2, is_empty_for_room/3]).
|
is_empty_for_user/2, is_empty_for_room/3, check_create_room/4]).
|
||||||
|
|
||||||
-include("xmpp.hrl").
|
-include("xmpp.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
@ -132,7 +132,8 @@ start(Host, Opts) ->
|
||||||
ejabberd_hooks:add(remove_room, Host, ?MODULE,
|
ejabberd_hooks:add(remove_room, Host, ?MODULE,
|
||||||
remove_room, 50);
|
remove_room, 50);
|
||||||
false ->
|
false ->
|
||||||
ok
|
ejabberd_hooks:add(check_create_room, Host, ?MODULE,
|
||||||
|
check_create_room, 50)
|
||||||
end,
|
end,
|
||||||
ejabberd_commands:register_commands(get_commands_spec());
|
ejabberd_commands:register_commands(get_commands_spec());
|
||||||
Err ->
|
Err ->
|
||||||
|
@ -207,7 +208,8 @@ stop(Host) ->
|
||||||
ejabberd_hooks:delete(remove_room, Host, ?MODULE,
|
ejabberd_hooks:delete(remove_room, Host, ?MODULE,
|
||||||
remove_room, 50);
|
remove_room, 50);
|
||||||
false ->
|
false ->
|
||||||
ok
|
ejabberd_hooks:delete(check_create_room, Host, ?MODULE,
|
||||||
|
check_create_room, 50)
|
||||||
end,
|
end,
|
||||||
case gen_mod:is_loaded_elsewhere(Host, ?MODULE) of
|
case gen_mod:is_loaded_elsewhere(Host, ?MODULE) of
|
||||||
false ->
|
false ->
|
||||||
|
@ -589,6 +591,10 @@ is_empty_for_room(LServer, Name, Host) ->
|
||||||
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
||||||
Mod:is_empty_for_room(LServer, LName, LHost).
|
Mod:is_empty_for_room(LServer, LName, LHost).
|
||||||
|
|
||||||
|
-spec check_create_room(boolean(), binary(), binary(), binary()) -> boolean().
|
||||||
|
check_create_room(Acc, ServerHost, RoomID, Host) ->
|
||||||
|
Acc and is_empty_for_room(ServerHost, RoomID, Host).
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
|
@ -65,7 +65,8 @@
|
||||||
iq_set_register_info/5,
|
iq_set_register_info/5,
|
||||||
count_online_rooms_by_user/3,
|
count_online_rooms_by_user/3,
|
||||||
get_online_rooms_by_user/3,
|
get_online_rooms_by_user/3,
|
||||||
can_use_nick/4]).
|
can_use_nick/4,
|
||||||
|
check_create_room/4]).
|
||||||
|
|
||||||
-export([init/1, handle_call/3, handle_cast/2,
|
-export([init/1, handle_call/3, handle_cast/2,
|
||||||
handle_info/2, terminate/2, code_change/3,
|
handle_info/2, terminate/2, code_change/3,
|
||||||
|
@ -112,10 +113,14 @@
|
||||||
%% API
|
%% API
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
start(Host, Opts) ->
|
start(Host, Opts) ->
|
||||||
|
ejabberd_hooks:add(check_create_room, Host, ?MODULE,
|
||||||
|
check_create_room, 50),
|
||||||
gen_mod:start_child(?MODULE, Host, Opts).
|
gen_mod:start_child(?MODULE, Host, Opts).
|
||||||
|
|
||||||
stop(Host) ->
|
stop(Host) ->
|
||||||
Rooms = shutdown_rooms(Host),
|
Rooms = shutdown_rooms(Host),
|
||||||
|
ejabberd_hooks:delete(check_create_room, Host, ?MODULE,
|
||||||
|
check_create_room, 50),
|
||||||
gen_mod:stop_child(?MODULE, Host),
|
gen_mod:stop_child(?MODULE, Host),
|
||||||
{wait, Rooms}.
|
{wait, Rooms}.
|
||||||
|
|
||||||
|
@ -442,7 +447,9 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
|
||||||
true ->
|
true ->
|
||||||
case check_user_can_create_room(
|
case check_user_can_create_room(
|
||||||
ServerHost, AccessCreate, From, Room) and
|
ServerHost, AccessCreate, From, Room) and
|
||||||
check_create_roomid(ServerHost, Room) of
|
ejabberd_hooks:run_fold(check_create_room,
|
||||||
|
ServerHost, true,
|
||||||
|
[ServerHost, Room, Host]) of
|
||||||
true ->
|
true ->
|
||||||
{ok, Pid} = start_new_room(
|
{ok, Pid} = start_new_room(
|
||||||
Host, ServerHost, Access,
|
Host, ServerHost, Access,
|
||||||
|
@ -611,9 +618,10 @@ check_user_can_create_room(ServerHost, AccessCreate,
|
||||||
_ -> false
|
_ -> false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
check_create_roomid(ServerHost, RoomID) ->
|
check_create_room(Acc, ServerHost, RoomID, _Host) ->
|
||||||
Max = gen_mod:get_module_opt(ServerHost, ?MODULE, max_room_id),
|
Max = gen_mod:get_module_opt(ServerHost, ?MODULE, max_room_id),
|
||||||
Regexp = gen_mod:get_module_opt(ServerHost, ?MODULE, regexp_room_id),
|
Regexp = gen_mod:get_module_opt(ServerHost, ?MODULE, regexp_room_id),
|
||||||
|
Acc and
|
||||||
(byte_size(RoomID) =< Max) and
|
(byte_size(RoomID) =< Max) and
|
||||||
(re:run(RoomID, Regexp, [unicode, {capture, none}]) == match).
|
(re:run(RoomID, Regexp, [unicode, {capture, none}]) == match).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue