Skip to content

Commit

Permalink
Remove bot thread permissions (#7071)
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan authored Dec 17, 2024
1 parent 02e8b33 commit bcada18
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 34 deletions.
4 changes: 4 additions & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 0 additions & 9 deletions backend/canisters/community/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions backend/canisters/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 0 additions & 9 deletions backend/canisters/group/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions backend/canisters/local_user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion backend/integration_tests/src/bot_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fn bot_smoke_test() {
community: HashSet::new(),
chat: HashSet::new(),
message: HashSet::from_iter([MessagePermission::Text]),
thread: HashSet::new(),
},
}],
);
Expand Down
1 change: 0 additions & 1 deletion backend/libraries/types/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,6 @@ type SlashCommandPermissions = record {
community: vec CommunityPermission;
chat: vec GroupPermission;
message: vec MessagePermission;
thread: vec MessagePermission;
};

type CommunityPermission = variant {
Expand Down
8 changes: 2 additions & 6 deletions backend/libraries/types/src/bot_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
};

Expand Down
1 change: 0 additions & 1 deletion backend/libraries/types/src/bots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub struct SlashCommandPermissions {
pub community: HashSet<CommunityPermission>,
pub chat: HashSet<GroupPermission>,
pub message: HashSet<MessagePermission>,
pub thread: HashSet<MessagePermission>,
}

#[ts_export]
Expand Down
5 changes: 0 additions & 5 deletions backend/libraries/utils/src/bots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

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

0 comments on commit bcada18

Please sign in to comment.