diff --git a/big_tests/tests/graphql_muc_light_SUITE.erl b/big_tests/tests/graphql_muc_light_SUITE.erl index 1739730451..3c19c3503c 100644 --- a/big_tests/tests/graphql_muc_light_SUITE.erl +++ b/big_tests/tests/graphql_muc_light_SUITE.erl @@ -713,7 +713,7 @@ admin_delete_room_story(Config, Alice) -> ?assertNotEqual(nomatch, binary:match(get_err_msg(Res2), <<"not found">>)), % Try with a non-existent room Res3 = execute_auth(delete_room_body(make_bare_jid(?UNKNOWN, MUCServer)), Config), - ?assertNotEqual(nomatch, binary:match(get_err_msg(Res3), <<"not found">>)). + ?assertNotEqual(nomatch, binary:match(get_err_msg(Res3), <<"Cannot remove">>)). admin_kick_user(Config) -> escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}], fun admin_kick_user_story/3). diff --git a/big_tests/tests/muc_light_http_api_SUITE.erl b/big_tests/tests/muc_light_http_api_SUITE.erl index 794bb5b98d..114927feb0 100644 --- a/big_tests/tests/muc_light_http_api_SUITE.erl +++ b/big_tests/tests/muc_light_http_api_SUITE.erl @@ -47,13 +47,11 @@ success_response() -> create_identifiable_room, invite_to_room, send_message_to_room, - delete_room_by_owner + delete_room ]. negative_response() -> - [delete_room_by_non_owner, - delete_non_existent_room, - delete_room_without_having_a_membership, + [delete_non_existent_room, create_non_unique_room, create_room_on_non_existing_muc_server ]. @@ -180,7 +178,7 @@ send_message_to_room(Config) -> [ see_message_from_user(U, Alice, Text) || U <- [Bob, Kate] ] end). -delete_room_by_owner(Config) -> +delete_room(Config) -> RoomID = atom_to_binary(?FUNCTION_NAME), RoomName = <<"wonderland">>, escalus:fresh_story(Config, @@ -188,19 +186,7 @@ delete_room_by_owner(Config) -> fun(Alice, Bob, Kate)-> {{<<"204">>, <<"No Content">>}, <<"">>} = check_delete_room(Config, RoomName, RoomID, RoomID, - Alice, [Bob, Kate], Alice) - end). - -delete_room_by_non_owner(Config) -> - RoomID = atom_to_binary(?FUNCTION_NAME), - RoomName = <<"wonderland">>, - escalus:fresh_story(Config, - [{alice, 1}, {bob, 1}, {kate, 1}], - fun(Alice, Bob, Kate)-> - {{<<"403">>, <<"Forbidden">>}, - <<"Given user cannot delete this room">>} = - check_delete_room(Config, RoomName, RoomID, RoomID, - Alice, [Bob, Kate], Bob) + Alice, [Bob, Kate]) end). delete_non_existent_room(Config) -> @@ -212,21 +198,9 @@ delete_non_existent_room(Config) -> {{<<"404">>, _}, <<"Cannot remove not existing room">>} = check_delete_room(Config, RoomName, RoomID, <<"some_non_existent_room">>, - Alice, [Bob, Kate], Alice) + Alice, [Bob, Kate]) end). -delete_room_without_having_a_membership(Config) -> - RoomID = atom_to_binary(?FUNCTION_NAME), - RoomName = <<"wonderland">>, - escalus:fresh_story(Config, - [{alice, 1}, {bob, 1}, {kate, 1}], - fun(Alice, Bob, Kate)-> - {{<<"403">>, _}, <<"Given user does not occupy this room">>} = - check_delete_room(Config, RoomName, RoomID, RoomID, - Alice, [Bob], Kate) - end). - - create_non_unique_room(Config) -> escalus:fresh_story(Config, [{alice, 1}], fun(Alice) -> Path = path([muc_light_domain()]), @@ -293,8 +267,7 @@ member_is_affiliated(Stanza, User) -> Data = exml_query:path(Stanza, [{element, <<"x">>}, {element, <<"user">>}, cdata]), MemberJID == Data. -check_delete_room(_Config, RoomName, RoomIDToCreate, RoomIDToDelete, RoomOwner, - RoomMembers, UserToExecuteDelete) -> +check_delete_room(_Config, RoomName, RoomIDToCreate, RoomIDToDelete, RoomOwner, RoomMembers) -> Members = [{Member, member} || Member <- RoomMembers], escalus:send(RoomOwner, stanza_create_room(RoomIDToCreate, [{<<"roomname">>, RoomName}], @@ -306,8 +279,7 @@ check_delete_room(_Config, RoomName, RoomIDToCreate, RoomIDToDelete, RoomOwner, CreationResult = escalus:wait_for_stanza(RoomOwner), escalus:assert(is_iq_result, CreationResult), muc_light_helper:verify_aff_bcast(Members, Affiliations), - ShortJID = escalus_client:short_jid(UserToExecuteDelete), - Path = path([muc_light_domain(), RoomIDToDelete, ShortJID, "management"]), + Path = path([muc_light_domain(), RoomIDToDelete, "management"]), rest_helper:delete(admin, Path). diff --git a/doc/rest-api/Administration-backend_swagger.yml b/doc/rest-api/Administration-backend_swagger.yml index 4cddd88294..4517d3bc79 100644 --- a/doc/rest-api/Administration-backend_swagger.yml +++ b/doc/rest-api/Administration-backend_swagger.yml @@ -472,10 +472,10 @@ paths: schema: title: roomJID type: string - /muc-lights/{XMPPMUCHost}/{roomName}/participants: + /muc-lights/{XMPPMUCHost}/{roomID}/participants: parameters: - $ref: '#/parameters/MUCServer' - - $ref: '#/parameters/roomName' + - $ref: '#/parameters/roomID' post: tags: - "MUC-light management" @@ -504,10 +504,10 @@ paths: responses: 204: description: An invite was sent out - /muc-lights/{XMPPMUCHost}/{roomName}/messages: + /muc-lights/{XMPPMUCHost}/{roomID}/messages: parameters: - $ref: '#/parameters/MUCServer' - - $ref: '#/parameters/roomName' + - $ref: '#/parameters/roomID' post: tags: - "MUC-light management" @@ -536,16 +536,10 @@ paths: responses: 204: description: Message was sent to the MUC Light room - /muc-lights/{XMPPMUCHost}/{roomName}/{user}/management: + /muc-lights/{XMPPMUCHost}/{roomID}/management: parameters: - $ref: '#/parameters/MUCServer' - - $ref: '#/parameters/roomName' - - name: user - in: path - description: User's JID (f.e. alice@wonderland.lit) - required: true - type: string - format: JID + - $ref: '#/parameters/roomID' delete: tags: - "MUC-light management" @@ -689,6 +683,12 @@ parameters: description: The MUC Light room's **name** (i.e. **not** the room's JID) required: true type: string + roomID: + name: roomID + in: path + description: The MUC Light room's **id** + required: true + type: string definitions: messageList: diff --git a/src/muc_light/mod_muc_light_api.erl b/src/muc_light/mod_muc_light_api.erl index a9218d3d41..89466cbbc1 100644 --- a/src/muc_light/mod_muc_light_api.erl +++ b/src/muc_light/mod_muc_light_api.erl @@ -40,6 +40,7 @@ -define(ROOM_DELETED_SUCC_RESULT, {ok, "Room deleted successfully"}). -define(USER_NOT_ROOM_MEMBER_RESULT, {not_room_member, "Given user does not occupy this room"}). -define(ROOM_NOT_FOUND_RESULT, {room_not_found, "Room not found"}). +-define(DELETE_NOT_EXISTING_ROOM_RESULT, {room_not_found, "Cannot remove not existing room"}). -define(MUC_SERVER_NOT_FOUND_RESULT, {muc_server_not_found, "MUC Light server not found"}). -define(VALIDATION_ERROR_RESULT(Key, Reason), {validation_error, io_lib:format("Validation failed for key: ~p with reason ~p", @@ -162,7 +163,7 @@ delete_room(#jid{lserver = MUCServer} = RoomJID, UserJID) -> {ok, member} -> {not_allowed, "Given user cannot delete this room"}; {error, room_not_found} -> - {room_not_found, "Cannot remove not existing room"} + ?DELETE_NOT_EXISTING_ROOM_RESULT end; {error, not_found}-> ?MUC_SERVER_NOT_FOUND_RESULT @@ -174,7 +175,7 @@ delete_room(RoomJID) -> ok -> ?ROOM_DELETED_SUCC_RESULT; {error, not_exists} -> - ?ROOM_NOT_FOUND_RESULT + ?DELETE_NOT_EXISTING_ROOM_RESULT catch error:{muc_host_to_host_type_failed, _, _} -> ?MUC_SERVER_NOT_FOUND_RESULT diff --git a/src/muc_light/mod_muc_light_commands.erl b/src/muc_light/mod_muc_light_commands.erl index 5e1d7bd5bc..7303e97e48 100644 --- a/src/muc_light/mod_muc_light_commands.erl +++ b/src/muc_light/mod_muc_light_commands.erl @@ -28,10 +28,10 @@ -export([create_identifiable_room/5]). -export([send_message/4]). -export([invite_to_room/4]). --export([delete_room/3]). +-export([delete_room/2]). -export([change_room_config/5]). --ignore_xref([create_identifiable_room/5, create_unique_room/4, delete_room/3, +-ignore_xref([create_identifiable_room/5, create_unique_room/4, delete_room/2, invite_to_room/4, send_message/4, change_room_config/5]). %%-------------------------------------------------------------------- @@ -114,10 +114,10 @@ commands() -> {module, ?MODULE}, {function, invite_to_room}, {action, create}, - {identifiers, [domain, name]}, + {identifiers, [domain, id]}, {args, [{domain, binary}, - {name, binary}, + {id, binary}, {sender, binary}, {recipient, binary} ]}, @@ -130,10 +130,10 @@ commands() -> {module, ?MODULE}, {function, send_message}, {action, create}, - {identifiers, [domain, name]}, + {identifiers, [domain, id]}, {args, [{domain, binary}, - {name, binary}, + {id, binary}, {from, binary}, {body, binary} ]}, @@ -146,11 +146,11 @@ commands() -> {module, ?MODULE}, {function, delete_room}, {action, delete}, - {identifiers, [domain, name, owner]}, + {identifiers, [domain, id]}, {args, [{domain, binary}, - {name, binary}, - {owner, binary}]}, + {id, binary} + ]}, {result, ok}] ]. @@ -203,12 +203,11 @@ send_message(MUCServer, RoomID, Sender, Message) -> Result = mod_muc_light_api:send_message(RoomJID, SenderJID, Message), format_result_no_msg(Result). --spec delete_room(jid:server(), jid:user(), jid:literal_jid()) -> - ok | {error, not_found | denied, iolist()}. -delete_room(MUCServer, RoomID, Owner) -> - OwnerJID = jid:from_binary(Owner), +-spec delete_room(jid:server(), jid:user()) -> + ok | {error, not_found, iolist()}. +delete_room(MUCServer, RoomID) -> RoomJID = jid:make_bare(RoomID, MUCServer), - Result = mod_muc_light_api:delete_room(RoomJID, OwnerJID), + Result = mod_muc_light_api:delete_room(RoomJID), format_result_no_msg(Result). format_result_no_msg({ok, _}) -> ok;