Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(channels): prevent removal of channel owners from participants (#4472)
teo22a88e741b03
diff --git a/js/app/packages/channel/Participants/ChannelParticipantsTab.tsx b/js/app/packages/channel/Participants/ChannelParticipantsTab.tsxindex 3af4aa8c35..364bfd7f6a 100644--- a/js/app/packages/channel/Participants/ChannelParticipantsTab.tsx+++ b/js/app/packages/channel/Participants/ChannelParticipantsTab.tsx@@ -56,6 +56,9 @@ export function ChannelParticipantsTab(props: { channelId: string }) {const removeParticipant = (participantId: string) => {if (!isEditable()) return;+ const participant = participants().find((p) => p.user_id === participantId);+ if (participant?.role === 'owner') return;+removeParticipantsMutation.mutate({channelId: props.channelId,participants: [participantId],diff --git a/js/app/packages/channel/Participants/ParticipantsListItem.tsx b/js/app/packages/channel/Participants/ParticipantsListItem.tsxindex a542c46f3c..35822c27f5 100644--- a/js/app/packages/channel/Participants/ParticipantsListItem.tsx+++ b/js/app/packages/channel/Participants/ParticipantsListItem.tsx@@ -15,7 +15,9 @@ export function ParticipantsListItem(props: {onRemove: () => void;}) {const canRemove =- props.editable && props.currentUserId !== props.participant.user_id;+ props.editable &&+ props.currentUserId !== props.participant.user_id &&+ props.participant.role !== 'owner';const navigationHandlers = useSplitNavigationHandler<HTMLButtonElement>(async (event) => {diff --git a/rust/cloud-storage/channels/src/domain/service.rs b/rust/cloud-storage/channels/src/domain/service.rsindex cb57502e71..df7e0c5c6b 100644--- a/rust/cloud-storage/channels/src/domain/service.rs+++ b/rust/cloud-storage/channels/src/domain/service.rs@@ -987,6 +987,19 @@ where"cannot add or remove participants from direct message channel".to_string(),));}+ let active_participants = self+ .repo+ .get_participants(channel_id)+ .await+ .map_err(|e| ChannelMutationErr::Repo(e.into()))?;+ let targets_owner = active_participants+ .iter()+ .any(|p| p.role == ParticipantRole::Owner && req.participants.contains(&p.user_id));+ if targets_owner {+ return Err(ChannelMutationErr::Unauthorized(+ "cannot remove the channel owner".to_string(),+ ));+ }for participant in req.participants {self.repo.remove_participant(channel_id, participant)diff --git a/rust/cloud-storage/channels/src/domain/service/test.rs b/rust/cloud-storage/channels/src/domain/service/test.rsindex 8a25d3b609..98c358e6fa 100644--- a/rust/cloud-storage/channels/src/domain/service/test.rs+++ b/rust/cloud-storage/channels/src/domain/service/test.rs@@ -289,6 +289,7 @@ struct FakeMutationRepoState {attachments: Vec<MutatedAttachment>,patched_content: Option<String>,activity_upserts: usize,+ removed_participants: Vec<String>,}impl FakeMutationRepo {@@ -333,6 +334,7 @@ impl FakeMutationRepo {attachments: vec![],patched_content: None,activity_upserts: 0,+ removed_participants: vec![],})),}}@@ -535,8 +537,13 @@ impl ChannelRepo for FakeMutationRepo {async fn remove_participant(&self,_channel_id: Uuid,- _user_id: String,+ user_id: String,) -> Result<(), Self::Err> {+ self.state+ .lock()+ .unwrap()+ .removed_participants+ .push(user_id);Ok(())}@@ -1530,3 +1537,57 @@ async fn thread_replies_resolve_and_hydrate() {assert_eq!(replies[1].reactions.len(), 0);assert_eq!(replies[1].attachments.len(), 1);}++#[tokio::test]+async fn remove_participants_rejects_removing_channel_owner() {+ let channel_id = Uuid::new_v4();+ let repo = FakeMutationRepo::new(channel_id, "macro|[email protected]");+ let svc = mutation_service(+ repo.clone(),+ FakeEvents::default(),+ FakeReferenceSharing::default(),+ );++ let err = svc+ .remove_participants(+ sender("macro|[email protected]"),+ channel_id,+ RemoveParticipantsRequest {+ participants: vec![+ "macro|[email protected]".to_string(),+ "macro|[email protected]".to_string(),+ ],+ },+ )+ .await+ .unwrap_err();++ assert!(matches!(err, ChannelMutationErr::Unauthorized(_)));+ assert!(repo.state.lock().unwrap().removed_participants.is_empty());+}++#[tokio::test]+async fn remove_participants_allows_removing_non_owner() {+ let channel_id = Uuid::new_v4();+ let repo = FakeMutationRepo::new(channel_id, "macro|[email protected]");+ let svc = mutation_service(+ repo.clone(),+ FakeEvents::default(),+ FakeReferenceSharing::default(),+ );++ svc.remove_participants(+ sender("macro|[email protected]"),+ channel_id,+ RemoveParticipantsRequest {+ participants: vec!["macro|[email protected]".to_string()],+ },+ )+ .await+ .unwrap();++ assert_eq!(+ repo.state.lock().unwrap().removed_participants,+ vec!["macro|[email protected]".to_string()]+ );+}