From bcada18cd5ba2e086efdb5a039af41b0df7837ca Mon Sep 17 00:00:00 2001 From: Matt Grogan Date: Tue, 17 Dec 2024 16:24:18 +0200 Subject: [PATCH] Remove bot thread permissions (#7071) --- backend/canisters/community/CHANGELOG.md | 4 ++++ backend/canisters/community/impl/src/lib.rs | 9 --------- .../community/impl/src/updates/c2c_handle_bot_action.rs | 2 +- backend/canisters/group/CHANGELOG.md | 4 ++++ backend/canisters/group/impl/src/lib.rs | 9 --------- .../group/impl/src/updates/c2c_handle_bot_action.rs | 2 +- backend/canisters/local_user_index/CHANGELOG.md | 4 ++++ backend/canisters/user_index/CHANGELOG.md | 4 ++++ backend/integration_tests/src/bot_tests.rs | 1 - backend/libraries/types/can.did | 1 - backend/libraries/types/src/bot_actions.rs | 8 ++------ backend/libraries/types/src/bots.rs | 1 - backend/libraries/utils/src/bots.rs | 5 ----- 13 files changed, 20 insertions(+), 34 deletions(-) diff --git a/backend/canisters/community/CHANGELOG.md b/backend/canisters/community/CHANGELOG.md index f4dd820b80..d3120fb93b 100644 --- a/backend/canisters/community/CHANGELOG.md +++ b/backend/canisters/community/CHANGELOG.md @@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Log error if end video call job fails ([#7066](https://github.com/open-chat-labs/open-chat/pull/7066)) - 2-stage bot messages + bot context in messages ([#7060](https://github.com/open-chat-labs/open-chat/pull/7060)) +### Removed + +- Remove bot thread permissions ([#7071](https://github.com/open-chat-labs/open-chat/pull/7071)) + ### Fixed - Fix `RoleChanged` events which were serialized under the wrong name (part 2) ([#7059](https://github.com/open-chat-labs/open-chat/pull/7059)) diff --git a/backend/canisters/community/impl/src/lib.rs b/backend/canisters/community/impl/src/lib.rs index fff3a10145..4e6f5bb235 100644 --- a/backend/canisters/community/impl/src/lib.rs +++ b/backend/canisters/community/impl/src/lib.rs @@ -885,20 +885,11 @@ impl Data { let message_permissions = channel_member .role() .message_permissions(&channel.chat.permissions.message_permissions); - let thread_permissions = channel - .chat - .permissions - .thread_permissions - .as_ref() - .map_or(message_permissions.clone(), |thread_permissions| { - channel_member.role().message_permissions(thread_permissions) - }); Some(SlashCommandPermissions { community: community_permissions, chat: channel_permissions, message: message_permissions, - thread: thread_permissions, }) } } diff --git a/backend/canisters/community/impl/src/updates/c2c_handle_bot_action.rs b/backend/canisters/community/impl/src/updates/c2c_handle_bot_action.rs index de21574886..11ea8f7841 100644 --- a/backend/canisters/community/impl/src/updates/c2c_handle_bot_action.rs +++ b/backend/canisters/community/impl/src/updates/c2c_handle_bot_action.rs @@ -90,7 +90,7 @@ fn is_bot_permitted_to_execute_command(args: &Args, state: &RuntimeState) -> boo }; // Get the permissions required to execute the given action - let permissions_required = args.action.permissions_required(args.thread_root_message_index.is_some()); + let permissions_required = args.action.permissions_required(); can_execute_bot_command(&permissions_required, granted_to_bot, &granted_to_user) } diff --git a/backend/canisters/group/CHANGELOG.md b/backend/canisters/group/CHANGELOG.md index 93e0e4626f..b036918fa2 100644 --- a/backend/canisters/group/CHANGELOG.md +++ b/backend/canisters/group/CHANGELOG.md @@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Log error if end video call job fails ([#7066](https://github.com/open-chat-labs/open-chat/pull/7066)) - 2-stage bot messages + bot context in messages ([#7060](https://github.com/open-chat-labs/open-chat/pull/7060)) +### Removed + +- Remove bot thread permissions ([#7071](https://github.com/open-chat-labs/open-chat/pull/7071)) + ### Fixed - Fix any long-running video calls that failed to be marked as ended ([#7068](https://github.com/open-chat-labs/open-chat/pull/7068)) diff --git a/backend/canisters/group/impl/src/lib.rs b/backend/canisters/group/impl/src/lib.rs index 0a0c46b02e..2c389f9495 100644 --- a/backend/canisters/group/impl/src/lib.rs +++ b/backend/canisters/group/impl/src/lib.rs @@ -735,20 +735,11 @@ impl Data { let group_permissions = member.role().permissions(&self.chat.permissions); let message_permissions = member.role().message_permissions(&self.chat.permissions.message_permissions); - let thread_permissions = self - .chat - .permissions - .thread_permissions - .as_ref() - .map_or(message_permissions.clone(), |thread_permissions| { - member.role().message_permissions(thread_permissions) - }); Some(SlashCommandPermissions { community: HashSet::new(), chat: group_permissions, message: message_permissions, - thread: thread_permissions, }) } } diff --git a/backend/canisters/group/impl/src/updates/c2c_handle_bot_action.rs b/backend/canisters/group/impl/src/updates/c2c_handle_bot_action.rs index 7aa48a8c81..4ed696244b 100644 --- a/backend/canisters/group/impl/src/updates/c2c_handle_bot_action.rs +++ b/backend/canisters/group/impl/src/updates/c2c_handle_bot_action.rs @@ -82,7 +82,7 @@ fn is_bot_permitted_to_execute_command(args: &Args, state: &RuntimeState) -> boo }; // Get the permissions required to execute the given action - let permissions_required = args.action.permissions_required(args.thread_root_message_index.is_some()); + let permissions_required = args.action.permissions_required(); can_execute_bot_command(&permissions_required, granted_to_bot, &granted_to_user) } diff --git a/backend/canisters/local_user_index/CHANGELOG.md b/backend/canisters/local_user_index/CHANGELOG.md index 99e91ccb2c..6ec0dc6587 100644 --- a/backend/canisters/local_user_index/CHANGELOG.md +++ b/backend/canisters/local_user_index/CHANGELOG.md @@ -14,6 +14,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Rename fields in access token & c2c_handle_bot_action::Args ([#7060](https://github.com/open-chat-labs/open-chat/pull/7060)) +### Removed + +- Remove bot thread permissions ([#7071](https://github.com/open-chat-labs/open-chat/pull/7071)) + ## [[2.0.1513](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1513-local_user_index)] - 2024-12-13 ### Added diff --git a/backend/canisters/user_index/CHANGELOG.md b/backend/canisters/user_index/CHANGELOG.md index 827c4474d5..e396db708a 100644 --- a/backend/canisters/user_index/CHANGELOG.md +++ b/backend/canisters/user_index/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Add new LocalUserIndexes to the CyclesDispenser's allow list ([#7070](https://github.com/open-chat-labs/open-chat/pull/7070)) +### Removed + +- Remove bot thread permissions ([#7071](https://github.com/open-chat-labs/open-chat/pull/7071)) + ## [[2.0.1508](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1508-user_index)] - 2024-12-13 ### Added diff --git a/backend/integration_tests/src/bot_tests.rs b/backend/integration_tests/src/bot_tests.rs index cdb20207b8..94ec3d963c 100644 --- a/backend/integration_tests/src/bot_tests.rs +++ b/backend/integration_tests/src/bot_tests.rs @@ -44,7 +44,6 @@ fn bot_smoke_test() { community: HashSet::new(), chat: HashSet::new(), message: HashSet::from_iter([MessagePermission::Text]), - thread: HashSet::new(), }, }], ); diff --git a/backend/libraries/types/can.did b/backend/libraries/types/can.did index 8c4069a743..5d1a7090f2 100644 --- a/backend/libraries/types/can.did +++ b/backend/libraries/types/can.did @@ -2131,7 +2131,6 @@ type SlashCommandPermissions = record { community: vec CommunityPermission; chat: vec GroupPermission; message: vec MessagePermission; - thread: vec MessagePermission; }; type CommunityPermission = variant { diff --git a/backend/libraries/types/src/bot_actions.rs b/backend/libraries/types/src/bot_actions.rs index 43eaa4e8d1..163b6ab97f 100644 --- a/backend/libraries/types/src/bot_actions.rs +++ b/backend/libraries/types/src/bot_actions.rs @@ -28,7 +28,7 @@ pub enum MessageContent { } impl BotAction { - pub fn permissions_required(&self, in_thread: bool) -> SlashCommandPermissions { + pub fn permissions_required(&self) -> SlashCommandPermissions { let mut permissions_required = SlashCommandPermissions::default(); match self { @@ -43,11 +43,7 @@ impl BotAction { MessageContent::Giphy(_) => MessagePermission::Giphy, }; - if in_thread { - permissions_required.thread.insert(permission); - } else { - permissions_required.message.insert(permission); - } + permissions_required.message.insert(permission); } }; diff --git a/backend/libraries/types/src/bots.rs b/backend/libraries/types/src/bots.rs index 8140f78918..f2af00cddd 100644 --- a/backend/libraries/types/src/bots.rs +++ b/backend/libraries/types/src/bots.rs @@ -63,7 +63,6 @@ pub struct SlashCommandPermissions { pub community: HashSet, pub chat: HashSet, pub message: HashSet, - pub thread: HashSet, } #[ts_export] diff --git a/backend/libraries/utils/src/bots.rs b/backend/libraries/utils/src/bots.rs index b5bdbe67ce..3ff32ba5d9 100644 --- a/backend/libraries/utils/src/bots.rs +++ b/backend/libraries/utils/src/bots.rs @@ -17,7 +17,6 @@ pub fn can_execute_bot_command( community: intersect(&p1.community, &p2.community), chat: intersect(&p1.chat, &p2.chat), message: intersect(&p1.message, &p2.message), - thread: intersect(&p1.thread, &p2.thread), } } @@ -26,7 +25,6 @@ pub fn can_execute_bot_command( required.community.is_subset(&granted.community) && required.chat.is_subset(&granted.chat) && required.message.is_subset(&granted.message) - && required.thread.is_subset(&granted.thread) } #[cfg(test)] @@ -64,7 +62,6 @@ mod tests { community: HashSet::from_iter([CommunityPermission::RemoveMembers]), chat: HashSet::new(), message: HashSet::from_iter([MessagePermission::Text]), - thread: HashSet::new(), }; let mut bot_community_permissions = HashSet::from_iter([CommunityPermission::InviteUsers]); @@ -75,7 +72,6 @@ mod tests { community: bot_community_permissions, chat: HashSet::from_iter([GroupPermission::RemoveMembers]), message: HashSet::from_iter([MessagePermission::Text, MessagePermission::Image]), - thread: HashSet::from_iter([MessagePermission::Text, MessagePermission::Image]), }; let mut user_community_permissions = HashSet::from_iter([CommunityPermission::ManageUserGroups]); @@ -86,7 +82,6 @@ mod tests { community: user_community_permissions, chat: HashSet::from_iter([GroupPermission::RemoveMembers, GroupPermission::DeleteMessages]), message: HashSet::from_iter([MessagePermission::Text, MessagePermission::Image, MessagePermission::Audio]), - thread: HashSet::new(), }; (required, granted_to_bot, granted_to_user)