Only allow Manage Members on root channels
This commit is contained in:
parent
abdf302367
commit
c6d33d4bb9
6 changed files with 150 additions and 31 deletions
|
@ -190,7 +190,9 @@ impl Database {
|
|||
let parent = self.get_channel_internal(parent_id, &*tx).await?;
|
||||
|
||||
if parent.visibility != ChannelVisibility::Public {
|
||||
Err(anyhow!("public channels must descend from public channels"))?;
|
||||
Err(ErrorCode::BadPublicNesting
|
||||
.with_tag("direction", "parent")
|
||||
.anyhow())?;
|
||||
}
|
||||
}
|
||||
} else if visibility == ChannelVisibility::Members {
|
||||
|
@ -202,7 +204,9 @@ impl Database {
|
|||
channel.id != channel_id && channel.visibility == ChannelVisibility::Public
|
||||
})
|
||||
{
|
||||
Err(anyhow!("cannot make a parent of a public channel private"))?;
|
||||
Err(ErrorCode::BadPublicNesting
|
||||
.with_tag("direction", "children")
|
||||
.anyhow())?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3281,6 +3281,18 @@ fn notify_membership_updated(
|
|||
user_id: UserId,
|
||||
peer: &Peer,
|
||||
) {
|
||||
let user_channels_update = proto::UpdateUserChannels {
|
||||
channel_memberships: result
|
||||
.new_channels
|
||||
.channel_memberships
|
||||
.iter()
|
||||
.map(|cm| proto::ChannelMembership {
|
||||
channel_id: cm.channel_id.to_proto(),
|
||||
role: cm.role.into(),
|
||||
})
|
||||
.collect(),
|
||||
..Default::default()
|
||||
};
|
||||
let mut update = build_channels_update(result.new_channels, vec![]);
|
||||
update.delete_channels = result
|
||||
.removed_channels
|
||||
|
@ -3290,6 +3302,8 @@ fn notify_membership_updated(
|
|||
update.remove_channel_invitations = vec![result.channel_id.to_proto()];
|
||||
|
||||
for connection_id in connection_pool.user_connection_ids(user_id) {
|
||||
peer.send(connection_id, user_channels_update.clone())
|
||||
.trace_err();
|
||||
peer.send(connection_id, update.clone()).trace_err();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1100,16 +1100,21 @@ async fn test_channel_membership_notifications(
|
|||
let user_b = client_b.user_id().unwrap();
|
||||
|
||||
let channels = server
|
||||
.make_channel_tree(&[("zed", None), ("vim", Some("zed"))], (&client_a, cx_a))
|
||||
.make_channel_tree(
|
||||
&[("zed", None), ("vim", Some("zed")), ("opensource", None)],
|
||||
(&client_a, cx_a),
|
||||
)
|
||||
.await;
|
||||
let zed_channel = channels[0];
|
||||
let vim_channel = channels[1];
|
||||
let opensource_channel = channels[2];
|
||||
|
||||
try_join_all(client_a.channel_store().update(cx_a, |channel_store, cx| {
|
||||
[
|
||||
channel_store.set_channel_visibility(zed_channel, proto::ChannelVisibility::Public, cx),
|
||||
channel_store.set_channel_visibility(vim_channel, proto::ChannelVisibility::Public, cx),
|
||||
channel_store.invite_member(zed_channel, user_b, proto::ChannelRole::Guest, cx),
|
||||
channel_store.invite_member(zed_channel, user_b, proto::ChannelRole::Admin, cx),
|
||||
channel_store.invite_member(opensource_channel, user_b, proto::ChannelRole::Member, cx),
|
||||
]
|
||||
}))
|
||||
.await
|
||||
|
@ -1144,6 +1149,34 @@ async fn test_channel_membership_notifications(
|
|||
},
|
||||
],
|
||||
);
|
||||
|
||||
client_b.channel_store().update(cx_b, |channel_store, _| {
|
||||
channel_store.is_channel_admin(zed_channel)
|
||||
});
|
||||
|
||||
client_b
|
||||
.channel_store()
|
||||
.update(cx_b, |channel_store, cx| {
|
||||
channel_store.respond_to_channel_invite(opensource_channel, true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
cx_a.run_until_parked();
|
||||
|
||||
client_a
|
||||
.channel_store()
|
||||
.update(cx_a, |channel_store, cx| {
|
||||
channel_store.set_member_role(opensource_channel, user_b, ChannelRole::Admin, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
cx_a.run_until_parked();
|
||||
|
||||
client_b.channel_store().update(cx_b, |channel_store, _| {
|
||||
channel_store.is_channel_admin(opensource_channel)
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue