diff --git a/big_tests/tests/graphql_muc_light_SUITE.erl b/big_tests/tests/graphql_muc_light_SUITE.erl index 231e413ceb..8882059280 100644 --- a/big_tests/tests/graphql_muc_light_SUITE.erl +++ b/big_tests/tests/graphql_muc_light_SUITE.erl @@ -69,6 +69,7 @@ admin_muc_light_tests() -> admin_create_room_with_custom_fields, admin_create_identified_room, admin_change_room_config, + admin_change_room_config_with_custom_fields, admin_change_room_config_errors, admin_invite_user, admin_invite_user_errors, @@ -204,6 +205,24 @@ user_change_room_config_story(Config, Alice) -> Res = user_change_room_configuration(Alice, jid:to_binary(RoomJID), Name2, Subject2, Config), ?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2}, get_ok_value(?CHANGE_CONFIG_PATH, Res)). +user_change_room_config_with_custom_fields(Config) -> + escalus:fresh_story_with_config(Config, [{alice, 1}], fun user_change_room_config_with_custom_fields_story/2). + +user_change_room_config_with_custom_fields_story(Config, Alice) -> + AliceBin = escalus_client:short_jid(Alice), + MUCServer = ?config(muc_light_host, Config), + % Create a new room + {ok, #{jid := RoomJID}} = create_room(MUCServer, <<"ornithology">>, <<"birds">>, AliceBin), + % Try to change the room configuration + Name2 = <<"changed room">>, + Subject2 = <<"not testing">>, + Opts2 = #{<<"music">> => <<"sad">>}, + Res = user_change_room_configuration_with_custom_fields(Alice, jid:to_binary(RoomJID), Name2, Subject2, Config, Opts2), + Opts3 = [#{<<"key">> => <<"music">>, <<"value">> => <<"sad">>}, + #{<<"key">> => <<"roomname">>, <<"value">> => Name2}, + #{<<"key">> => <<"subject">>, <<"value">> => Subject2}], + ?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2, <<"options">> := Opts3}, get_ok_value(?CHANGE_CONFIG_PATH, Res)). + user_change_room_config_errors(Config) -> escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}], fun user_change_room_config_errors_story/3). @@ -626,6 +645,31 @@ admin_change_room_config_story(Config, Alice) -> ?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2}, get_ok_value(?CHANGE_CONFIG_PATH, Res)). +admin_change_room_config_with_custom_fields(Config) -> + escalus:fresh_story_with_config(Config, [{alice, 1}], fun admin_change_room_config_with_custom_fields_story/2). + +admin_change_room_config_with_custom_fields_story(Config, Alice) -> + AliceBin = escalus_client:short_jid(Alice), + MUCServer = ?config(muc_light_host, Config), + Name = <<"first room">>, + Subject = <<"testing">>, + Opts = #{<<"background">> => <<"red">>}, + % Create a new room + Res = create_room_with_custom_fields(MUCServer, Name, AliceBin, Subject, null, Config, Opts), + #{<<"jid">> := RoomJID} = get_ok_value(?CREATE_ROOM_PATH, Res), + % Try to change the room configuration + Name2 = <<"changed room">>, + Subject2 = <<"not testing">>, + Opts2 = #{<<"music">> => <<"sad">>}, + Res2 = change_room_configuration_with_custom_fields(jid:to_binary(RoomJID), AliceBin, Name2, Subject2, Config, Opts2), + %% It overwrites old config for all fields + Opts3 = [% #{<<"key">> => <<"background">>, <<"value">> => <<"red">>}, + #{<<"key">> => <<"music">>, <<"value">> => <<"sad">>}, + #{<<"key">> => <<"roomname">>, <<"value">> => Name2}, + #{<<"key">> => <<"subject">>, <<"value">> => Subject2}], + ?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2, <<"options">> := Opts3}, + get_ok_value(?CHANGE_CONFIG_PATH, Res2)). + admin_change_room_config_errors(Config) -> escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}], fun admin_change_room_config_errors_story/3). @@ -927,6 +971,11 @@ change_room_configuration(RoomJID, OwnerJID, Name, Subject, Config) -> <<"subject">> => Subject}, execute_command(<<"muc_light">>, <<"changeRoomConfiguration">>, Vars, Config). +change_room_configuration_with_custom_fields(RoomJID, OwnerJID, Name, Subject, Config, Opts) -> + Vars = #{<<"room">> => RoomJID, <<"name">> => Name, <<"owner">> => OwnerJID, + <<"subject">> => Subject, <<"options">> => format_options(Opts)}, + execute_command(<<"muc_light">>, <<"changeRoomConfiguration">>, Vars, Config). + invite_user(RoomJID, Sender, Recipient, Config) -> Vars = #{<<"room">> => RoomJID, <<"sender">> => Sender, <<"recipient">> => Recipient}, execute_command(<<"muc_light">>, <<"inviteUser">>, Vars, Config). @@ -981,6 +1030,11 @@ user_change_room_configuration(User, RoomJID, Name, Subject, Config) -> Vars = #{<<"room">> => RoomJID, <<"name">> => Name, <<"subject">> => Subject}, execute_user_command(<<"muc_light">>, <<"changeRoomConfiguration">>, User, Vars, Config). +user_change_room_configuration_with_custom_fields(User, RoomJID, Name, Subject, Config, Options) -> + Vars = #{<<"room">> => RoomJID, <<"name">> => Name, <<"subject">> => Subject, + <<"options">> => format_options(Options)}, + execute_user_command(<<"muc_light">>, <<"changeRoomConfiguration">>, User, Vars, Config). + format_options(Map) -> [#{<<"key">> => K, <<"value">> => V} || {K, V} <- maps:to_list(Map)]. diff --git a/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl b/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl index 52f665c8e4..abe77a394a 100644 --- a/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl +++ b/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl @@ -40,8 +40,10 @@ create_room(#{<<"id">> := RoomID, <<"mucDomain">> := MUCDomain, <<"name">> := Ro -spec change_room_config(map()) -> {ok, map()} | {error, resolver_error()}. change_room_config(#{<<"room">> := RoomJID, <<"name">> := RoomName, - <<"owner">> := OwnerJID, <<"subject">> := Subject}) -> - Config = #{<<"roomname">> => RoomName, <<"subject">> => Subject}, + <<"owner">> := OwnerJID, <<"subject">> := Subject, + <<"options">> := Options}) -> + OptMap = options_to_map(Options), + Config = OptMap#{<<"roomname">> => RoomName, <<"subject">> => Subject}, case mod_muc_light_api:change_room_config(RoomJID, OwnerJID, Config) of {ok, Room} -> {ok, make_room(Room)}; diff --git a/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl b/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl index bd4dbfcd7f..571f67252c 100644 --- a/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl +++ b/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl @@ -40,8 +40,9 @@ create_room(#{user := UserJID}, #{<<"id">> := RoomID, <<"mucDomain">> := MUCDoma -spec change_room_config(map(), map()) -> {ok, map()} | {error, resolver_error()}. change_room_config(#{user := UserJID}, #{<<"room">> := RoomJID, <<"name">> := RoomName, - <<"subject">> := Subject}) -> - Config = #{<<"roomname">> => RoomName, <<"subject">> => Subject}, + <<"subject">> := Subject, <<"options">> := Options}) -> + OptMap = options_to_map(Options), + Config = OptMap#{<<"roomname">> => RoomName, <<"subject">> => Subject}, case mod_muc_light_api:change_room_config(RoomJID, UserJID, Config) of {ok, Room} -> {ok, make_room(Room)};