diff --git a/big_tests/tests/muc_SUITE.erl b/big_tests/tests/muc_SUITE.erl index c55855c037..80b39324fd 100644 --- a/big_tests/tests/muc_SUITE.erl +++ b/big_tests/tests/muc_SUITE.erl @@ -403,7 +403,7 @@ init_per_group(_GroupName, Config) -> required_modules(http_auth) -> MucHostPattern = ct:get_config({hosts, mim, muc_service_pattern}), - DefRoomOpts = rpc(mim(), mod_muc, default_room_opts, []), + DefRoomOpts = config_parser_helper:default_room_opts(), Opts = #{host => subhost_pattern(MucHostPattern), access => muc, access_create => muc_create, diff --git a/big_tests/tests/muc_helper.erl b/big_tests/tests/muc_helper.erl index d94538bd91..1dab729cfb 100644 --- a/big_tests/tests/muc_helper.erl +++ b/big_tests/tests/muc_helper.erl @@ -18,12 +18,10 @@ %% Extend default opts with new ExtraOpts make_opts(ExtraOpts) -> - Opts = rpc(mim(), mod_muc, default_opts, []), - maps:merge(Opts, ExtraOpts). + config_parser_helper:mod_config(mod_muc, ExtraOpts). make_log_opts(ExtraOpts) -> - Opts = rpc(mim(), mod_muc_log, default_opts, []), - maps:merge(Opts, ExtraOpts). + config_parser_helper:mod_config(mod_muc_log, ExtraOpts). -spec foreach_occupant( Users :: [escalus:client()], Stanza :: #xmlel{}, VerifyFun :: verify_fun()) -> ok. diff --git a/src/config/mongoose_config_utils.erl b/src/config/mongoose_config_utils.erl index 7adeb991a0..3d278fae14 100644 --- a/src/config/mongoose_config_utils.erl +++ b/src/config/mongoose_config_utils.erl @@ -4,7 +4,6 @@ -module(mongoose_config_utils). -export([exit_or_halt/1]). -export([section_to_defaults/1]). --export([keys_are_binaries/1]). -ignore_xref([section_to_defaults/1]). -include("mongoose_config_spec.hrl"). @@ -22,6 +21,3 @@ exit_or_halt(ExitText) -> section_to_defaults(#section{defaults = Defaults}) -> Defaults. - -keys_are_binaries(KV) -> - maps:from_list([{atom_to_binary(K, latin1), V} || {K, V} <- maps:to_list(KV)]). diff --git a/src/inbox/mod_inbox.erl b/src/inbox/mod_inbox.erl index c3a4ecd02f..d0f7fba456 100644 --- a/src/inbox/mod_inbox.erl +++ b/src/inbox/mod_inbox.erl @@ -86,7 +86,7 @@ process_entry(#{remote_jid := RemJID, -spec deps(jid:lserver(), list()) -> gen_mod_deps:deps(). deps(_Host, Opts) -> Groupchats = gen_mod:get_opt(groupchat, Opts), - muclight_dep(Groupchats) ++ muc_dep(Groupchats). + muclight_dep(Groupchats). -spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok. start(HostType, #{iqdisc := IQDisc, groupchat := MucTypes} = Opts) -> @@ -553,12 +553,6 @@ muclight_dep(List) -> false -> [] end. -muc_dep(List) -> - case lists:member(muc, List) of - true -> [{mod_muc, mod_muc:default_opts(), hard}]; - false -> [] - end. - -spec muclight_enabled(HostType :: mongooseim:host_type()) -> boolean(). muclight_enabled(HostType) -> Groupchats = get_groupchat_types(HostType), diff --git a/src/mod_muc.erl b/src/mod_muc.erl index c41e9f05ee..e4ee45364e 100644 --- a/src/mod_muc.erl +++ b/src/mod_muc.erl @@ -72,15 +72,11 @@ -export([hibernated_rooms_number/0]). -export([config_metrics/1]). --export([default_opts/0]). --export([default_room_opts/0]). -ignore_xref([ can_access_identity/4, can_access_room/4, acc_room_affiliations/2, create_instant_room/6, disco_local_items/1, hibernated_rooms_number/0, is_muc_room_owner/4, remove_domain/3, - online_rooms_number/0, register_room/4, restore_room/3, start_link/2, - default_room_opts/0 -]). + online_rooms_number/0, register_room/4, restore_room/3, start_link/2]). -include("mongoose.hrl"). -include("jlib.hrl"). @@ -251,36 +247,37 @@ config_spec() -> validate = non_negative}, <<"default_room">> => default_room_config_spec() }, - defaults = mongoose_config_utils:keys_are_binaries(default_opts()) + defaults = defaults() }. -default_opts() -> - #{ - backend => mnesia, - host => default_host(), - access => all, - access_create => all, - access_admin => none, - access_persistent => all, - history_size => 20, - room_shaper => none, - max_room_id => infinity, - max_room_name => infinity, - max_room_desc => infinity, - min_message_interval => 0, - min_presence_interval => 0, - max_users => ?MAX_USERS_DEFAULT, - max_users_admin_threshold => 5, - user_message_shaper => none, - user_presence_shaper => none, - max_user_conferences => 10, - http_auth_pool => none, - load_permanent_rooms_at_startup => false, - hibernate_timeout => timer:seconds(90), - hibernated_room_check_interval => infinity, - hibernated_room_timeout => infinity, - default_room => default_room_opts() - }. +defaults() -> + #{<<"backend">> => mnesia, + <<"host">> => default_host(), + <<"access">> => all, + <<"access_create">> => all, + <<"access_admin">> => none, + <<"access_persistent">> => all, + <<"history_size">> => 20, + <<"room_shaper">> => none, + <<"max_room_id">> => infinity, + <<"max_room_name">> => infinity, + <<"max_room_desc">> => infinity, + <<"min_message_interval">> => 0, + <<"min_presence_interval">> => 0, + <<"max_users">> => ?MAX_USERS_DEFAULT, + <<"max_users_admin_threshold">> => 5, + <<"user_message_shaper">> => none, + <<"user_presence_shaper">> => none, + <<"max_user_conferences">> => 10, + <<"http_auth_pool">> => none, + <<"load_permanent_rooms_at_startup">> => false, + <<"hibernate_timeout">> => timer:seconds(90), + <<"hibernated_room_check_interval">> => infinity, + <<"hibernated_room_timeout">> => infinity, + <<"default_room">> => keys_as_atoms(default_room_opts())}. + +keys_as_atoms(Map) -> + maps:from_list([{binary_to_atom(K), V} || {K, V} <- maps:to_list(Map)]). default_room_config_spec() -> #section{ @@ -312,37 +309,35 @@ default_room_config_spec() -> <<"subject">> => #option{type = binary}, <<"subject_author">> => #option{type = binary} }, - defaults = mongoose_config_utils:keys_are_binaries(default_room_opts()) + defaults = default_room_opts() }. default_room_opts() -> X = #config{}, - #{ - title => X#config.title, - description => X#config.description, - allow_change_subj => X#config.allow_change_subj, - allow_query_users => X#config.allow_query_users, - allow_private_messages => X#config.allow_private_messages, - allow_visitor_status => X#config.allow_visitor_status, - allow_visitor_nickchange => X#config.allow_visitor_nickchange, - public => X#config.public, - public_list => X#config.public_list, - persistent => X#config.persistent, - moderated => X#config.moderated, - members_by_default => X#config.members_by_default, - members_only => X#config.members_only, - allow_user_invites => X#config.allow_user_invites, - allow_multiple_sessions => X#config.allow_multiple_sessions, - password_protected => X#config.password_protected, - password => X#config.password, - anonymous => X#config.anonymous, - max_users => X#config.max_users, - logging => X#config.logging, - maygetmemberlist => X#config.maygetmemberlist, - affiliations => [], - subject => <<>>, - subject_author => <<>> - }. + #{<<"title">> => X#config.title, + <<"description">> => X#config.description, + <<"allow_change_subj">> => X#config.allow_change_subj, + <<"allow_query_users">> => X#config.allow_query_users, + <<"allow_private_messages">> => X#config.allow_private_messages, + <<"allow_visitor_status">> => X#config.allow_visitor_status, + <<"allow_visitor_nickchange">> => X#config.allow_visitor_nickchange, + <<"public">> => X#config.public, + <<"public_list">> => X#config.public_list, + <<"persistent">> => X#config.persistent, + <<"moderated">> => X#config.moderated, + <<"members_by_default">> => X#config.members_by_default, + <<"members_only">> => X#config.members_only, + <<"allow_user_invites">> => X#config.allow_user_invites, + <<"allow_multiple_sessions">> => X#config.allow_multiple_sessions, + <<"password_protected">> => X#config.password_protected, + <<"password">> => X#config.password, + <<"anonymous">> => X#config.anonymous, + <<"max_users">> => X#config.max_users, + <<"logging">> => X#config.logging, + <<"maygetmemberlist">> => X#config.maygetmemberlist, + <<"affiliations">> => [], + <<"subject">> => <<>>, + <<"subject_author">> => <<>>}. default_room_affiliations_spec() -> #section{ diff --git a/src/mod_muc_log.erl b/src/mod_muc_log.erl index 372edfaab7..b64a94aeb8 100644 --- a/src/mod_muc_log.erl +++ b/src/mod_muc_log.erl @@ -43,14 +43,11 @@ -export([config_spec/0, process_top_link/1]). --export([default_opts/0]). - %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -ignore_xref([start_link/2]). --ignore_xref([default_opts/0]). -include("mongoose.hrl"). -include("jlib.hrl"). @@ -150,21 +147,19 @@ config_spec() -> <<"top_link">> => top_link_config_spec(), <<"spam_prevention">> => #option{type = boolean} }, - defaults = mongoose_config_utils:keys_are_binaries(default_opts()) + defaults = defaults() }. -default_opts() -> - #{ - outdir => "www/muc", - access_log => muc_admin, - dirtype => subdirs, - dirname => room_jid, - file_format => html, - css_file => false, - timezone => local, - top_link => {"/", "Home"}, - spam_prevention => true - }. +defaults() -> + #{<<"outdir">> => "www/muc", + <<"access_log">> => muc_admin, + <<"dirtype">> => subdirs, + <<"dirname">> => room_jid, + <<"file_format">> => html, + <<"css_file">> => false, + <<"timezone">> => local, + <<"top_link">> => {"/", "Home"}, + <<"spam_prevention">> => true}. top_link_config_spec() -> #section{ diff --git a/test/common/config_parser_helper.erl b/test/common/config_parser_helper.erl index 8c80c40f33..efb38b7d3d 100644 --- a/test/common/config_parser_helper.erl +++ b/test/common/config_parser_helper.erl @@ -532,11 +532,11 @@ all_modules() -> #{host => <<"192.168.0.1">>, type => turn}]}, mod_csi => [{buffer_max, 40}], mod_muc_log => - (mod_muc_log:default_opts()) - #{access_log => muc, - css_file => <<"path/to/css/file">>, - outdir => "www/muc", - top_link => {"/", "Home"}}, + mod_config(mod_muc_log, + #{access_log => muc, + css_file => <<"path/to/css/file">>, + outdir => "www/muc", + top_link => {"/", "Home"}}), mod_http_upload => [{backend, s3}, {expiration_time, 120}, @@ -627,17 +627,16 @@ all_modules() -> #{backend => mnesia, inactivity => 20, max_wait => infinity, server_acks => true, max_pause => 120}, mod_muc => - (mod_muc:default_opts()) - #{access => muc, - access_create => muc_create, - default_room => - (mod_muc:default_room_opts()) - #{affiliations => - [{{<<"alice">>, <<"localhost">>, <<"resource1">>}, member}, - {{<<"bob">>, <<"localhost">>, <<"resource2">>}, owner}], - password_protected => true}, - host => {fqdn, <<"muc.example.com">>}, - http_auth_pool => my_auth_pool}, + mod_config(mod_muc, + #{access => muc, + access_create => muc_create, + default_room => (default_room_opts()) + #{affiliations => + [{{<<"alice">>, <<"localhost">>, <<"resource1">>}, member}, + {{<<"bob">>, <<"localhost">>, <<"resource2">>}, owner}], + password_protected => true}, + host => {fqdn, <<"muc.example.com">>}, + http_auth_pool => my_auth_pool}), mod_vcard => mod_config(mod_vcard, #{host => {fqdn, <<"directory.example.com">>}, @@ -893,7 +892,68 @@ default_mod_config(mod_mam_rdbms_arch) -> default_mod_config(mod_mam_muc_rdbms_arch) -> #{no_writer => false, db_message_format => mam_message_compressed_eterm, - db_jid_format => mam_jid_rfc}. + db_jid_format => mam_jid_rfc}; +default_mod_config(mod_muc) -> + #{backend => mnesia, + host => {prefix,<<"conference.">>}, + access => all, + access_create => all, + access_admin => none, + access_persistent => all, + history_size => 20, + room_shaper => none, + max_room_id => infinity, + max_room_name => infinity, + max_room_desc => infinity, + min_message_interval => 0, + min_presence_interval => 0, + max_users => 200, + max_users_admin_threshold => 5, + user_message_shaper => none, + user_presence_shaper => none, + max_user_conferences => 10, + http_auth_pool => none, + load_permanent_rooms_at_startup => false, + hibernate_timeout => timer:seconds(90), + hibernated_room_check_interval => infinity, + hibernated_room_timeout => infinity, + default_room => default_room_opts()}; +default_mod_config(mod_muc_log) -> + #{outdir => "www/muc", + access_log => muc_admin, + dirtype => subdirs, + dirname => room_jid, + file_format => html, + css_file => false, + timezone => local, + top_link => {"/", "Home"}, + spam_prevention => true}. + +default_room_opts() -> + #{title => <<>>, + description => <<>>, + allow_change_subj => true, + allow_query_users => true, + allow_private_messages => true, + allow_visitor_status => true, + allow_visitor_nickchange => true, + public => true, + public_list => true, + persistent => false, + moderated => true, + members_by_default => true, + members_only => false, + allow_user_invites => false, + allow_multiple_sessions => false, + password_protected => false, + password => <<>>, + anonymous => true, + max_users => 200, + logging => false, + maygetmemberlist => [], + affiliations => [], + subject => <<>>, + subject_author => <<>>}. default_config([modules, M]) -> default_mod_config(M); diff --git a/test/config_parser_SUITE.erl b/test/config_parser_SUITE.erl index 33fa27914a..d5abf135df 100644 --- a/test/config_parser_SUITE.erl +++ b/test/config_parser_SUITE.erl @@ -2266,177 +2266,144 @@ test_async_writer(ParentT, ParentP) -> ?errh(T(#{<<"enabled">> => <<"wrong">>})). mod_muc(_Config) -> - DefOpts = mod_muc:default_opts(), - T = fun(Opts) -> #{<<"modules">> => #{<<"mod_muc">> => Opts}} end, - M = fun(Cfg) -> modopts(mod_muc, maps:merge(DefOpts, Cfg)) end, - ?cfgh(M(#{host => {prefix, <<"conference.">>}}), - T(#{<<"host">> => <<"conference.@HOST@">>})), - ?cfgh(M(#{host => {fqdn, <<"conference.test">>}}), - T(#{<<"host">> => <<"conference.test">>})), - ?cfgh(M(#{backend => mnesia}), - T(#{<<"backend">> => <<"mnesia">>})), - ?cfgh(M(#{access => all}), - T(#{<<"access">> => <<"all">>})), - ?cfgh(M(#{access_create => admin}), - T(#{<<"access_create">> => <<"admin">>})), - ?cfgh(M(#{access_admin => none}), - T(#{<<"access_admin">> => <<"none">>})), - ?cfgh(M(#{access_persistent => all}), - T(#{<<"access_persistent">> => <<"all">>})), - ?cfgh(M(#{history_size => 20}), - T(#{<<"history_size">> => 20})), - ?cfgh(M(#{room_shaper => muc_room_shaper}), - T(#{<<"room_shaper">> => <<"muc_room_shaper">>})), - ?cfgh(M(#{max_room_id => infinity}), - T(#{<<"max_room_id">> => <<"infinity">>})), - ?cfgh(M(#{max_room_name => 30}), - T(#{<<"max_room_name">> => 30})), - ?cfgh(M(#{max_room_desc => 0}), - T(#{<<"max_room_desc">> => 0})), - ?cfgh(M(#{min_message_interval => 10}), - T(#{<<"min_message_interval">> => 10})), - ?cfgh(M(#{min_presence_interval => 0}), - T(#{<<"min_presence_interval">> => 0})), - ?cfgh(M(#{max_users => 30}), - T(#{<<"max_users">> => 30})), - ?cfgh(M(#{max_users_admin_threshold => 2}), - T(#{<<"max_users_admin_threshold">> => 2})), - ?cfgh(M(#{user_message_shaper => muc_msg_shaper}), - T(#{<<"user_message_shaper">> => <<"muc_msg_shaper">>})), - ?cfgh(M(#{user_presence_shaper => muc_pres_shaper}), - T(#{<<"user_presence_shaper">> => <<"muc_pres_shaper">>})), - ?cfgh(M(#{max_user_conferences => 10}), - T(#{<<"max_user_conferences">> => 10})), - ?cfgh(M(#{http_auth_pool => external_auth}), - T(#{<<"http_auth_pool">> => <<"external_auth">>})), - ?cfgh(M(#{load_permanent_rooms_at_startup => true}), - T(#{<<"load_permanent_rooms_at_startup">> => true})), - ?cfgh(M(#{hibernate_timeout => infinity}), - T(#{<<"hibernate_timeout">> => <<"infinity">>})), - ?cfgh(M(#{hibernated_room_check_interval => 5000}), - T(#{<<"hibernated_room_check_interval">> => 5000})), - ?cfgh(M(#{hibernated_room_timeout => 0}), - T(#{<<"hibernated_room_timeout">> => 0})), - ?errh(T(#{<<"host">> => <<>>})), - ?errh(T(#{<<"host">> => <<"is this a host? no.">>})), - ?errh(T(#{<<"host">> => [<<"invalid.sub@HOST@">>]})), - ?errh(T(#{<<"host">> => [<<"invalid.sub.@HOST@.as.well">>]})), - ?errh(T(#{<<"backend">> => <<"amnesia">>})), - ?errh(T(#{<<"access">> => <<>>})), - ?errh(T(#{<<"access_create">> => 1})), - ?errh(T(#{<<"access_admin">> => []})), - ?errh(T(#{<<"access_persistent">> => true})), - ?errh(T(#{<<"history_size">> => <<"20">>})), - ?errh(T(#{<<"room_shaper">> => <<>>})), - ?errh(T(#{<<"max_room_id">> => #{}})), - ?errh(T(#{<<"max_room_name">> => <<"infinite!">>})), - ?errh(T(#{<<"max_room_desc">> => -1})), - ?errh(T(#{<<"min_message_interval">> => -10})), - ?errh(T(#{<<"min_presence_interval">> => <<"infinity">>})), - ?errh(T(#{<<"max_users">> => 0})), - ?errh(T(#{<<"max_users_admin_threshold">> => 0})), - ?errh(T(#{<<"user_message_shaper">> => []})), - ?errh(T(#{<<"user_presence_shaper">> => <<>>})), - ?errh(T(#{<<"max_user_conferences">> => -1})), - ?errh(T(#{<<"http_auth_pool">> => <<>>})), - ?errh(T(#{<<"load_permanent_rooms_at_startup">> => <<"true">>})), - ?errh(T(#{<<"hibernate_timeout">> => <<"really big">>})), - ?errh(T(#{<<"hibernated_room_check_interval">> => -1})), - ?errh(T(#{<<"hibernated_room_timeout">> => false})). + check_module_defaults(mod_muc), + P = [modules, mod_muc], + T = fun(K, V) -> #{<<"modules">> => #{<<"mod_muc">> => #{K => V}}} end, + ?cfgh(P ++ [host], {prefix, <<"conference.">>}, + T(<<"host">>, <<"conference.@HOST@">>)), + ?cfgh(P ++ [host], {fqdn, <<"conference.test">>}, + T(<<"host">>, <<"conference.test">>)), + ?cfgh(P ++ [backend], mnesia, T(<<"backend">>, <<"mnesia">>)), + ?cfgh(P ++ [access], all, T(<<"access">>, <<"all">>)), + ?cfgh(P ++ [access_create], admin, T(<<"access_create">>, <<"admin">>)), + ?cfgh(P ++ [access_admin], none, T(<<"access_admin">>, <<"none">>)), + ?cfgh(P ++ [access_persistent], all, T(<<"access_persistent">>, <<"all">>)), + ?cfgh(P ++ [history_size], 20, T(<<"history_size">>, 20)), + ?cfgh(P ++ [room_shaper], muc_room_shaper, + T(<<"room_shaper">>, <<"muc_room_shaper">>)), + ?cfgh(P ++ [max_room_id], infinity, T(<<"max_room_id">>, <<"infinity">>)), + ?cfgh(P ++ [max_room_name], 30, T(<<"max_room_name">>, 30)), + ?cfgh(P ++ [max_room_desc], 0, T(<<"max_room_desc">>, 0)), + ?cfgh(P ++ [min_message_interval], 10, T(<<"min_message_interval">>, 10)), + ?cfgh(P ++ [min_presence_interval], 0, T(<<"min_presence_interval">>, 0)), + ?cfgh(P ++ [max_users], 30, T(<<"max_users">>, 30)), + ?cfgh(P ++ [max_users_admin_threshold], 2, + T(<<"max_users_admin_threshold">>, 2)), + ?cfgh(P ++ [user_message_shaper], muc_msg_shaper, + T(<<"user_message_shaper">>, <<"muc_msg_shaper">>)), + ?cfgh(P ++ [user_presence_shaper], muc_pres_shaper, + T(<<"user_presence_shaper">>, <<"muc_pres_shaper">>)), + ?cfgh(P ++ [max_user_conferences], 10, T(<<"max_user_conferences">>, 10)), + ?cfgh(P ++ [http_auth_pool], external_auth, + T(<<"http_auth_pool">>, <<"external_auth">>)), + ?cfgh(P ++ [load_permanent_rooms_at_startup], true, + T(<<"load_permanent_rooms_at_startup">>, true)), + ?cfgh(P ++ [hibernate_timeout], infinity, + T(<<"hibernate_timeout">>, <<"infinity">>)), + ?cfgh(P ++ [hibernated_room_check_interval], 5000, + T(<<"hibernated_room_check_interval">>, 5000)), + ?cfgh(P ++ [hibernated_room_timeout], 0, + T(<<"hibernated_room_timeout">>, 0)), + ?errh(T(<<"host">>, <<>>)), + ?errh(T(<<"host">>, <<"is this a host? no.">>)), + ?errh(T(<<"host">>, [<<"invalid.sub@HOST@">>])), + ?errh(T(<<"host">>, [<<"invalid.sub.@HOST@.as.well">>])), + ?errh(T(<<"backend">>, <<"amnesia">>)), + ?errh(T(<<"access">>, <<>>)), + ?errh(T(<<"access_create">>, 1)), + ?errh(T(<<"access_admin">>, [])), + ?errh(T(<<"access_persistent">>, true)), + ?errh(T(<<"history_size">>, <<"20">>)), + ?errh(T(<<"room_shaper">>, <<>>)), + ?errh(T(<<"max_room_id">>, #{})), + ?errh(T(<<"max_room_name">>, <<"infinite!">>)), + ?errh(T(<<"max_room_desc">>, -1)), + ?errh(T(<<"min_message_interval">>, -10)), + ?errh(T(<<"min_presence_interval">>, <<"infinity">>)), + ?errh(T(<<"max_users">>, 0)), + ?errh(T(<<"max_users_admin_threshold">>, 0)), + ?errh(T(<<"user_message_shaper">>, [])), + ?errh(T(<<"user_presence_shaper">>, <<>>)), + ?errh(T(<<"max_user_conferences">>, -1)), + ?errh(T(<<"http_auth_pool">>, <<>>)), + ?errh(T(<<"load_permanent_rooms_at_startup">>, <<"true">>)), + ?errh(T(<<"hibernate_timeout">>, <<"really big">>)), + ?errh(T(<<"hibernated_room_check_interval">>, -1)), + ?errh(T(<<"hibernated_room_timeout">>, false)). mod_muc_default_room(_Config) -> - DefOpts = mod_muc:default_opts(), - DefRoomOpts = mod_muc:default_room_opts(), - T = fun(Opts) -> #{<<"modules">> => - #{<<"mod_muc">> => #{<<"default_room">> => Opts}}} end, - M = fun(Cfg) -> modopts(mod_muc, DefOpts#{default_room => maps:merge(DefRoomOpts, Cfg)}) end, - ?cfgh(M(#{}), T(#{})), - ?cfgh(M(#{title => <<"living room">>}), - T(#{<<"title">> => <<"living room">>})), - ?cfgh(M(#{description => <<"a room that is alive">>}), - T(#{<<"description">> => <<"a room that is alive">>})), - ?cfgh(M(#{allow_change_subj => true}), - T(#{<<"allow_change_subj">> => true})), - ?cfgh(M(#{allow_query_users => false}), - T(#{<<"allow_query_users">> => false})), - ?cfgh(M(#{allow_private_messages => true}), - T(#{<<"allow_private_messages">> => true})), - ?cfgh(M(#{allow_visitor_status => false}), - T(#{<<"allow_visitor_status">> => false})), - ?cfgh(M(#{allow_visitor_nickchange => true}), - T(#{<<"allow_visitor_nickchange">> => true})), - ?cfgh(M(#{public => false}), - T(#{<<"public">> => false})), - ?cfgh(M(#{public_list => true}), - T(#{<<"public_list">> => true})), - ?cfgh(M(#{persistent => true}), - T(#{<<"persistent">> => true})), - ?cfgh(M(#{moderated => false}), - T(#{<<"moderated">> => false})), - ?cfgh(M(#{members_by_default => true}), - T(#{<<"members_by_default">> => true})), - ?cfgh(M(#{members_only => false}), - T(#{<<"members_only">> => false})), - ?cfgh(M(#{allow_user_invites => true}), - T(#{<<"allow_user_invites">> => true})), - ?cfgh(M(#{allow_multiple_sessions => false}), - T(#{<<"allow_multiple_sessions">> => false})), - ?cfgh(M(#{password_protected => true}), - T(#{<<"password_protected">> => true})), - ?cfgh(M(#{password => <<"secret">>}), - T(#{<<"password">> => <<"secret">>})), - ?cfgh(M(#{anonymous => true}), - T(#{<<"anonymous">> => true})), - ?cfgh(M(#{max_users => 100}), - T(#{<<"max_users">> => 100})), - ?cfgh(M(#{logging => false}), - T(#{<<"logging">> => false})), - ?cfgh(M(#{maygetmemberlist => [moderator]}), - T(#{<<"maygetmemberlist">> => [<<"moderator">>]})), - ?cfgh(M(#{subject => <<"Lambda days">>}), - T(#{<<"subject">> => <<"Lambda days">>})), - ?cfgh(M(#{subject_author => <<"Alice">>}), - T(#{<<"subject_author">> => <<"Alice">>})), - ?errh(T(<<"bad value">>)), - ?errh(T(#{<<"title">> => true})), - ?errh(T(#{<<"description">> => 1})), - ?errh(T(#{<<"allow_change_subj">> => <<"true">>})), - ?errh(T(#{<<"allow_query_users">> => <<>>})), - ?errh(T(#{<<"allow_private_messages">> => 1})), - ?errh(T(#{<<"allow_visitor_status">> => []})), - ?errh(T(#{<<"allow_visitor_nickchange">> => #{}})), - ?errh(T(#{<<"public">> => 0})), - ?errh(T(#{<<"public_list">> => [false]})), - ?errh(T(#{<<"persistent">> => 1})), - ?errh(T(#{<<"moderated">> => <<"yes">>})), - ?errh(T(#{<<"members_by_default">> => 0})), - ?errh(T(#{<<"members_only">> => [true]})), - ?errh(T(#{<<"allow_user_invites">> => <<>>})), - ?errh(T(#{<<"allow_multiple_sessions">> => []})), - ?errh(T(#{<<"password_protected">> => #{}})), - ?errh(T(#{<<"password">> => false})), - ?errh(T(#{<<"anonymous">> => <<"maybe">>})), - ?errh(T(#{<<"max_users">> => 0})), - ?errh(T(#{<<"logging">> => [true, false]})), - ?errh(T(#{<<"maygetmemberlist">> => <<"moderator">>})), - ?errh(T(#{<<"maygetmemberlist">> => [<<>>]})), - ?errh(T(#{<<"subject">> => [<<"subjective">>]})), - ?errh(T(#{<<"subject_author">> => 1})). + P = [modules, mod_muc, default_room], + T = fun(K, V) -> + M = #{<<"mod_muc">> => #{<<"default_room">> => #{K => V}}}, + #{<<"modules">> => M} + end, + ?cfgh(P ++ [title], <<"living room">>, T(<<"title">>, <<"living room">>)), + ?cfgh(P ++ [description], <<"a room that is alive">>, + T(<<"description">>, <<"a room that is alive">>)), + ?cfgh(P ++ [allow_change_subj], true, T(<<"allow_change_subj">>, true)), + ?cfgh(P ++ [allow_query_users], false, T(<<"allow_query_users">>, false)), + ?cfgh(P ++ [allow_private_messages], true, + T(<<"allow_private_messages">>, true)), + ?cfgh(P ++ [allow_visitor_status], false, + T(<<"allow_visitor_status">>, false)), + ?cfgh(P ++ [allow_visitor_nickchange], true, + T(<<"allow_visitor_nickchange">>, true)), + ?cfgh(P ++ [public], false, T(<<"public">>, false)), + ?cfgh(P ++ [public_list], true, T(<<"public_list">>, true)), + ?cfgh(P ++ [persistent], true, T(<<"persistent">>, true)), + ?cfgh(P ++ [moderated], false, T(<<"moderated">>, false)), + ?cfgh(P ++ [members_by_default], true, T(<<"members_by_default">>, true)), + ?cfgh(P ++ [members_only], false, T(<<"members_only">>, false)), + ?cfgh(P ++ [allow_user_invites], true, T(<<"allow_user_invites">>, true)), + ?cfgh(P ++ [allow_multiple_sessions], false, + T(<<"allow_multiple_sessions">>, false)), + ?cfgh(P ++ [password_protected], true, T(<<"password_protected">>, true)), + ?cfgh(P ++ [password], <<"secret">>, T(<<"password">>, <<"secret">>)), + ?cfgh(P ++ [anonymous], true, T(<<"anonymous">>, true)), + ?cfgh(P ++ [max_users], 100, T(<<"max_users">>, 100)), + ?cfgh(P ++ [logging], false, T(<<"logging">>, false)), + ?cfgh(P ++ [maygetmemberlist], [moderator], + T(<<"maygetmemberlist">>, [<<"moderator">>])), + ?cfgh(P ++ [subject], <<"Lambda days">>, T(<<"subject">>, <<"Lambda days">>)), + ?cfgh(P ++ [subject_author], <<"Alice">>, T(<<"subject_author">>, <<"Alice">>)), + ?errh(T(<<"title">>, true)), + ?errh(T(<<"description">>, 1)), + ?errh(T(<<"allow_change_subj">>, <<"true">>)), + ?errh(T(<<"allow_query_users">>, <<>>)), + ?errh(T(<<"allow_private_messages">>, 1)), + ?errh(T(<<"allow_visitor_status">>, [])), + ?errh(T(<<"allow_visitor_nickchange">>, #{})), + ?errh(T(<<"public">>, 0)), + ?errh(T(<<"public_list">>, [false])), + ?errh(T(<<"persistent">>, 1)), + ?errh(T(<<"moderated">>, <<"yes">>)), + ?errh(T(<<"members_by_default">>, 0)), + ?errh(T(<<"members_only">>, [true])), + ?errh(T(<<"allow_user_invites">>, <<>>)), + ?errh(T(<<"allow_multiple_sessions">>, [])), + ?errh(T(<<"password_protected">>, #{})), + ?errh(T(<<"password">>, false)), + ?errh(T(<<"anonymous">>, <<"maybe">>)), + ?errh(T(<<"max_users">>, 0)), + ?errh(T(<<"logging">>, [true, false])), + ?errh(T(<<"maygetmemberlist">>, <<"moderator">>)), + ?errh(T(<<"maygetmemberlist">>, [<<>>])), + ?errh(T(<<"subject">>, [<<"subjective">>])), + ?errh(T(<<"subject_author">>, 1)). mod_muc_default_room_affiliations(_Config) -> - DefOpts = mod_muc:default_opts(), - DefRoomOpts = mod_muc:default_room_opts(), - T = fun(Opts) -> #{<<"modules">> => - #{<<"mod_muc">> => - #{<<"default_room">> => #{<<"affiliations">> => Opts}}}} end, - M = fun(Cfg) -> modopts(mod_muc, DefOpts#{default_room => maps:merge(DefRoomOpts, #{affiliations => Cfg})}) end, + P = [modules, mod_muc, default_room, affiliations], + T = fun(V) -> + M = #{<<"mod_muc">> => #{<<"default_room">> => #{<<"affiliations">> => V}}}, + #{<<"modules">> => M} + end, RequiredOpts = #{<<"user">> => <<"alice">>, <<"server">> => <<"localhost">>, <<"resource">> => <<"phone">>, <<"affiliation">> => <<"moderator">>}, ExpectedCfg = {{<<"alice">>, <<"localhost">>, <<"phone">>}, moderator}, - ?cfgh(M([]), T([])), - ?cfgh(M([ExpectedCfg]), T([RequiredOpts])), + ?cfgh(P, [], T([])), + ?cfgh(P, [ExpectedCfg], T([RequiredOpts])), [?errh(T([maps:remove(Key, RequiredOpts)])) || Key <- maps:keys(RequiredOpts)], ?errh(T([RequiredOpts#{<<"user">> := <<>>}])), ?errh(T([RequiredOpts#{<<"server">> := <<"domain? not really!">>}])), @@ -2444,42 +2411,37 @@ mod_muc_default_room_affiliations(_Config) -> ?errh(T([RequiredOpts#{<<"affiliation">> := <<>>}])). mod_muc_log(_Config) -> - DefOpts = mod_muc_log:default_opts(), - T = fun(Opts) -> #{<<"modules">> => #{<<"mod_muc_log">> => Opts}} end, - M = fun(Cfg) -> modopts(mod_muc_log, maps:merge(DefOpts, Cfg)) end, - ?cfgh(M(#{outdir => "www/muc"}), - T(#{<<"outdir">> => <<"www/muc">>})), - ?cfgh(M(#{access_log => muc_admin}), - T(#{<<"access_log">> => <<"muc_admin">>})), - ?cfgh(M(#{dirtype => subdirs}), - T(#{<<"dirtype">> => <<"subdirs">>})), - ?cfgh(M(#{dirname => room_name}), - T(#{<<"dirname">> => <<"room_name">>})), - ?cfgh(M(#{file_format => html}), - T(#{<<"file_format">> => <<"html">>})), - ?cfgh(M(#{css_file => <<"path/to/css_file">>}), - T(#{<<"css_file">> => <<"path/to/css_file">>})), - ?cfgh(M(#{timezone => local}), - T(#{<<"timezone">> => <<"local">>})), - ?cfgh(M(#{spam_prevention => false}), - T(#{<<"spam_prevention">> => false})), - ?errh(T(#{<<"outdir">> => <<"does/not/exist">>})), - ?errh(T(#{<<"access_log">> => 1})), - ?errh(T(#{<<"dirtype">> => <<"imaginary">>})), - ?errh(T(#{<<"dirname">> => <<"dyrektory">>})), - ?errh(T(#{<<"file_format">> => <<"none">>})), - ?errh(T(#{<<"css_file">> => <<>>})), - ?errh(T(#{<<"timezone">> => <<"yes">>})), - ?errh(T(#{<<"spam_prevention">> => <<"spam and eggs and spam">>})). + check_module_defaults(mod_muc_log), + P = [modules, mod_muc_log], + T = fun(K, V) -> #{<<"modules">> => #{<<"mod_muc_log">> => #{K => V}}} end, + ?cfgh(P ++ [outdir], "www/muc", T(<<"outdir">>, <<"www/muc">>)), + ?cfgh(P ++ [access_log], muc_admin, T(<<"access_log">>, <<"muc_admin">>)), + ?cfgh(P ++ [dirtype], subdirs, T(<<"dirtype">>, <<"subdirs">>)), + ?cfgh(P ++ [dirname], room_name, T(<<"dirname">>, <<"room_name">>)), + ?cfgh(P ++ [file_format], html, T(<<"file_format">>, <<"html">>)), + ?cfgh(P ++ [css_file], <<"path/to/css_file">>, + T(<<"css_file">>, <<"path/to/css_file">>)), + ?cfgh(P ++ [timezone], local, T(<<"timezone">>, <<"local">>)), + ?cfgh(P ++ [spam_prevention], false, T(<<"spam_prevention">>, false)), + ?errh(T(<<"outdir">>, <<"does/not/exist">>)), + ?errh(T(<<"access_log">>, 1)), + ?errh(T(<<"dirtype">>, <<"imaginary">>)), + ?errh(T(<<"dirname">>, <<"dyrektory">>)), + ?errh(T(<<"file_format">>, <<"none">>)), + ?errh(T(<<"css_file">>, <<>>)), + ?errh(T(<<"timezone">>, <<"yes">>)), + ?errh(T(<<"spam_prevention">>, <<"spam and eggs and spam">>)). mod_muc_log_top_link(_Config) -> - DefOpts = mod_muc_log:default_opts(), - T = fun(Opts) -> #{<<"modules">> => #{<<"mod_muc_log">> => #{<<"top_link">> => Opts}}} end, - M = fun(Cfg) -> modopts(mod_muc_log, DefOpts#{top_link => Cfg}) end, + P = [modules, mod_muc_log, top_link], + T = fun(V) -> + M = #{<<"mod_muc_log">> => #{<<"top_link">> => V}}, + #{<<"modules">> => M} + end, RequiredOpts = #{<<"target">> => <<"https://esl.github.io/MongooseDocs/">>, <<"text">> => <<"Docs">>}, ExpectedCfg = {"https://esl.github.io/MongooseDocs/", "Docs"}, - ?cfgh(M(ExpectedCfg), T(RequiredOpts)), + ?cfgh(P, ExpectedCfg, T(RequiredOpts)), [?errh(T(maps:remove(K, RequiredOpts))) || K <- maps:keys(RequiredOpts)], ?errh(T(RequiredOpts#{<<"target">> => true})), ?errh(T(RequiredOpts#{<<"text">> => <<"">>})).