Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL MUC Light - Allow rest admin to delete each room #3576

Merged
merged 4 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion big_tests/tests/graphql_muc_light_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
42 changes: 7 additions & 35 deletions big_tests/tests/muc_light_http_api_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
].
Expand Down Expand Up @@ -180,27 +178,15 @@ 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,
[{alice, 1}, {bob, 1}, {kate, 1}],
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) ->
Expand All @@ -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()]),
Expand Down Expand Up @@ -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}],
Expand All @@ -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).


Expand Down
24 changes: 12 additions & 12 deletions doc/rest-api/Administration-backend_swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions src/muc_light/mod_muc_light_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
27 changes: 13 additions & 14 deletions src/muc_light/mod_muc_light_commands.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).

%%--------------------------------------------------------------------
Expand Down Expand Up @@ -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}
]},
Expand All @@ -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}
]},
Expand All @@ -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}]
].

Expand Down Expand Up @@ -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;
Expand Down