-
Notifications
You must be signed in to change notification settings - Fork 426
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 - Implement MUC Light rooms API for admin #3538
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e0ce44c
Add MUC Light GraphQL schema
Premwoik cdca4be
Extract common commands to API module
Premwoik 3bec1eb
Implement resolvers for MUC Light admin queries
Premwoik 2a53e48
Add tests for MUC Light GraphQL admin API
Premwoik 04a5863
Use Domain instead of MUCLightServer in requests
Premwoik e260108
Make MUC Light API to use room JID
Premwoik e84b9c3
Add affiliance enum and format JIDs in errors
Premwoik e14f8f6
Adapt tests and doc to the Rest API changes
Premwoik 28f484f
Apply review
Premwoik 198cc90
Fix indentation
Premwoik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Allow admin to manage Multi-User Chat Light rooms. | ||
""" | ||
type MUCLightAdminMutation @protected{ | ||
"Create a MUC light room under the given XMPP hostname" | ||
createRoom(mucDomain: String!, name: String!, owner: JID!, subject: String!, id: String): Room | ||
"Change configuration of a MUC Light room" | ||
changeRoomConfiguration(room: JID!, owner: JID!, name: String!, subject: String!): Room | ||
"Invite a user to a MUC Light room" | ||
inviteUser(room: JID!, sender: JID!, recipient: JID!): String | ||
"Remove a MUC Light room" | ||
deleteRoom(room: JID!): String | ||
"Kick a user from a MUC Light room" | ||
kickUser(room: JID!, user: JID!): String | ||
"Send a message to a MUC Light room" | ||
sendMessageToRoom(room: JID!, from: JID!, body: String!): String | ||
} | ||
|
||
""" | ||
Allow admin to get information about Multi-User Chat Light rooms. | ||
""" | ||
type MUCLightAdminQuery @protected{ | ||
"Get the MUC Light room archived messages" | ||
getRoomMessages(room: JID!, pageSize: Int!, before: DateTime): StanzasPayload | ||
"Get configuration of the MUC Light room" | ||
getRoomConfig(room: JID!): Room | ||
"Get users list of given MUC Light room" | ||
listRoomUsers(room: JID!): [RoomUser!] | ||
"Get the list of MUC Light rooms that the user participates in" | ||
listUserRooms(user: JID!): [JID!] | ||
} | ||
|
||
type Room{ | ||
jid: JID! | ||
name: String! | ||
subject: String! | ||
participants: [RoomUser!]! | ||
} | ||
|
||
type RoomUser{ | ||
jid: JID! | ||
affiliation: Affiliation! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enum Affiliation{ | ||
OWNER | ||
MEMBER | ||
NONE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
-module(mongoose_graphql_muc_light_admin_mutation). | ||
|
||
-export([execute/4]). | ||
|
||
-ignore_xref([execute/4]). | ||
|
||
-include("../mongoose_graphql_types.hrl"). | ||
|
||
-import(mongoose_graphql_helper, [make_error/2, format_result/2]). | ||
-import(mongoose_graphql_muc_light_helper, [make_room/1, make_ok_user/1]). | ||
|
||
execute(_Ctx, _Obj, <<"createRoom">>, Args) -> | ||
create_room(Args); | ||
execute(_Ctx, _Obj, <<"changeRoomConfiguration">>, Args) -> | ||
change_room_config(Args); | ||
execute(_Ctx, _Obj, <<"inviteUser">>, Args) -> | ||
invite_user(Args); | ||
execute(_Ctx, _Obj, <<"deleteRoom">>, Args) -> | ||
delete_room(Args); | ||
execute(_Ctx, _Obj, <<"kickUser">>, Args) -> | ||
kick_user(Args); | ||
execute(_Ctx, _Obj, <<"sendMessageToRoom">>, Args) -> | ||
send_msg_to_room(Args). | ||
|
||
-spec create_room(map()) -> {ok, map()} | {error, resolver_error()}. | ||
create_room(#{<<"id">> := null} = Args) -> | ||
create_room(Args#{<<"id">> => <<>>}); | ||
create_room(#{<<"id">> := RoomID, <<"mucDomain">> := MUCDomain, <<"name">> := RoomName, | ||
<<"owner">> := CreatorJID, <<"subject">> := Subject}) -> | ||
case mod_muc_light_api:create_room(MUCDomain, RoomID, RoomName, CreatorJID, Subject) of | ||
{ok, Room} -> | ||
{ok, make_room(Room)}; | ||
Err -> | ||
make_error(Err, #{mucDomain => MUCDomain, id => RoomID, creator => CreatorJID}) | ||
end. | ||
|
||
-spec change_room_config(map()) -> {ok, map()} | {error, resolver_error()}. | ||
change_room_config(#{<<"room">> := RoomJID, <<"name">> := RoomName, | ||
<<"owner">> := OwnerJID, <<"subject">> := Subject}) -> | ||
case mod_muc_light_api:change_room_config(RoomJID, OwnerJID, RoomName, Subject) of | ||
{ok, Room} -> | ||
{ok, make_room(Room)}; | ||
Err -> | ||
make_error(Err, #{room => jid:to_binary(RoomJID), owner => jid:to_binary(OwnerJID)}) | ||
end. | ||
|
||
-spec delete_room(map()) -> {ok, binary()} | {error, resolver_error()}. | ||
delete_room(#{<<"room">> := RoomJID}) -> | ||
Result = mod_muc_light_api:delete_room(RoomJID), | ||
format_result(Result, #{room => jid:to_binary(RoomJID)}). | ||
|
||
-spec invite_user(map()) -> {ok, binary()} | {error, resolver_error()}. | ||
invite_user(#{<<"room">> := RoomJID, <<"sender">> := SenderJID, | ||
<<"recipient">> := RecipientJID}) -> | ||
Result = mod_muc_light_api:invite_to_room(RoomJID, SenderJID, RecipientJID), | ||
format_result(Result, #{room => jid:to_binary(RoomJID), sender => jid:to_binary(SenderJID), | ||
recipient => jid:to_binary(RecipientJID)}). | ||
|
||
-spec kick_user(map()) -> {ok, binary()} | {error, resolver_error()}. | ||
kick_user(#{<<"room">> := RoomJID, <<"user">> := UserJID}) -> | ||
Result = mod_muc_light_api:remove_user_from_room(RoomJID, UserJID, UserJID), | ||
format_result(Result, #{user => UserJID}). | ||
|
||
-spec send_msg_to_room(map()) -> {ok, binary()} | {error, resolver_error()}. | ||
send_msg_to_room(#{<<"room">> := RoomJID, <<"from">> := FromJID, <<"body">> := Message}) -> | ||
Result = mod_muc_light_api:send_message(RoomJID, FromJID, Message), | ||
format_result(Result, #{room => jid:to_binary(RoomJID), from => jid:to_binary(FromJID)}). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to accept empty binary in the GraphQL query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An empty string, in this case, means that
id
is not present and should be generated. It was done this way in the old commands module. I can return an error whenid
is empty to eliminate the situation that someone passes an empty string by the accident. Should I do it this way?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the point - the logic for "" is a side-effect of the way it is coded. I think it can stay as it is for now. I think that the policy for empty binaries should be similar as e.g. for empty binary for user name, jid etc.