Fix joining descendant channels, style channel invites
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
87b2d599c1
commit
2ccd153233
8 changed files with 260 additions and 193 deletions
|
@ -1381,16 +1381,8 @@ impl Database {
|
|||
) -> Result<RoomGuard<JoinRoom>> {
|
||||
self.room_transaction(room_id, |tx| async move {
|
||||
if let Some(channel_id) = channel_id {
|
||||
channel_member::Entity::find()
|
||||
.filter(
|
||||
channel_member::Column::ChannelId
|
||||
.eq(channel_id)
|
||||
.and(channel_member::Column::UserId.eq(user_id))
|
||||
.and(channel_member::Column::Accepted.eq(true)),
|
||||
)
|
||||
.one(&*tx)
|
||||
.await?
|
||||
.ok_or_else(|| anyhow!("no such channel membership"))?;
|
||||
self.check_user_is_channel_member(channel_id, user_id, &*tx)
|
||||
.await?;
|
||||
|
||||
room_participant::ActiveModel {
|
||||
room_id: ActiveValue::set(room_id),
|
||||
|
@ -1738,7 +1730,6 @@ impl Database {
|
|||
}
|
||||
|
||||
let (channel_id, room) = self.get_channel_room(room_id, &tx).await?;
|
||||
|
||||
let channel_members = if let Some(channel_id) = channel_id {
|
||||
self.get_channel_members_internal(channel_id, &tx).await?
|
||||
} else {
|
||||
|
@ -3595,6 +3586,25 @@ impl Database {
|
|||
Ok(user_ids)
|
||||
}
|
||||
|
||||
async fn check_user_is_channel_member(
|
||||
&self,
|
||||
channel_id: ChannelId,
|
||||
user_id: UserId,
|
||||
tx: &DatabaseTransaction,
|
||||
) -> Result<()> {
|
||||
let channel_ids = self.get_channel_ancestors(channel_id, tx).await?;
|
||||
channel_member::Entity::find()
|
||||
.filter(
|
||||
channel_member::Column::ChannelId
|
||||
.is_in(channel_ids)
|
||||
.and(channel_member::Column::UserId.eq(user_id)),
|
||||
)
|
||||
.one(&*tx)
|
||||
.await?
|
||||
.ok_or_else(|| anyhow!("user is not a channel member"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn check_user_is_channel_admin(
|
||||
&self,
|
||||
channel_id: ChannelId,
|
||||
|
@ -3611,7 +3621,7 @@ impl Database {
|
|||
)
|
||||
.one(&*tx)
|
||||
.await?
|
||||
.ok_or_else(|| anyhow!("user is not allowed to remove this channel"))?;
|
||||
.ok_or_else(|| anyhow!("user is not a channel admin"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -313,6 +313,38 @@ fn assert_members_eq(
|
|||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_joining_channel_ancestor_member(
|
||||
deterministic: Arc<Deterministic>,
|
||||
cx_a: &mut TestAppContext,
|
||||
cx_b: &mut TestAppContext,
|
||||
) {
|
||||
deterministic.forbid_parking();
|
||||
let mut server = TestServer::start(&deterministic).await;
|
||||
|
||||
let client_a = server.create_client(cx_a, "user_a").await;
|
||||
let client_b = server.create_client(cx_b, "user_b").await;
|
||||
|
||||
let parent_id = server
|
||||
.make_channel("parent", (&client_a, cx_a), &mut [(&client_b, cx_b)])
|
||||
.await;
|
||||
|
||||
let sub_id = client_a
|
||||
.channel_store()
|
||||
.update(cx_a, |channel_store, _| {
|
||||
channel_store.create_channel("sub_channel", Some(parent_id))
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let active_call_b = cx_b.read(ActiveCall::global);
|
||||
|
||||
assert!(active_call_b
|
||||
.update(cx_b, |active_call, cx| active_call.join_channel(sub_id, cx))
|
||||
.await
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_channel_room(
|
||||
deterministic: Arc<Deterministic>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue