Finish integration tests for channel moving
Refactor channel store to combine the channels_by_id and channel_paths into a 'ChannelIndex'
This commit is contained in:
parent
9e68d4a8ea
commit
3a62d2988a
5 changed files with 214 additions and 108 deletions
|
@ -846,7 +846,8 @@ impl Database {
|
|||
/// - (`Some(id)`, `None`) Remove a channel from a given parent, and leave other parents
|
||||
/// - (`Some(id)`, `Some(id)`) Move channel from one parent to another, leaving other parents
|
||||
///
|
||||
/// Returns the channel that was moved + it's sub channels
|
||||
/// Returns the channel that was moved + it's sub channels for use
|
||||
/// by the members for `to`
|
||||
pub async fn move_channel(
|
||||
&self,
|
||||
user: UserId,
|
||||
|
@ -861,14 +862,9 @@ impl Database {
|
|||
self.check_user_is_channel_admin(from, user, &*tx).await?;
|
||||
|
||||
let mut channel_descendants = None;
|
||||
if let Some(from_parent) = from_parent {
|
||||
self.check_user_is_channel_admin(from_parent, user, &*tx)
|
||||
.await?;
|
||||
|
||||
self.remove_channel_from_parent(from, from_parent, &*tx)
|
||||
.await?;
|
||||
}
|
||||
|
||||
// Note that we have to do the linking before the removal, so that we
|
||||
// can leave the channel_path table in a consistent state.
|
||||
if let Some(to) = to {
|
||||
self.check_user_is_channel_admin(to, user, &*tx).await?;
|
||||
|
||||
|
@ -880,20 +876,28 @@ impl Database {
|
|||
None => self.get_channel_descendants([from], &*tx).await?,
|
||||
};
|
||||
|
||||
// Repair the parent ID of the channel in case it was from a cached call
|
||||
if let Some(channel) = channel_descendants.get_mut(&from) {
|
||||
if let Some(from_parent) = from_parent {
|
||||
channel.remove(&from_parent);
|
||||
}
|
||||
if let Some(to) = to {
|
||||
channel.insert(to);
|
||||
}
|
||||
if let Some(from_parent) = from_parent {
|
||||
self.check_user_is_channel_admin(from_parent, user, &*tx)
|
||||
.await?;
|
||||
|
||||
self.remove_channel_from_parent(from, from_parent, &*tx)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let channels;
|
||||
if let Some(to) = to {
|
||||
if let Some(channel) = channel_descendants.get_mut(&from) {
|
||||
// Remove the other parents
|
||||
channel.clear();
|
||||
channel.insert(to);
|
||||
}
|
||||
|
||||
let channels = self
|
||||
.get_all_channels(channel_descendants, &*tx)
|
||||
.await?;
|
||||
channels = self
|
||||
.get_all_channels(channel_descendants, &*tx)
|
||||
.await?;
|
||||
} else {
|
||||
channels = vec![];
|
||||
}
|
||||
|
||||
Ok(channels)
|
||||
})
|
||||
|
|
|
@ -657,7 +657,7 @@ async fn test_channels_moving(db: &Arc<Database>) {
|
|||
// zed - crdb - livestreaming - livestreaming_dag - livestreaming_dag_sub_id
|
||||
// \--------/
|
||||
|
||||
// make sure we're getting the new link
|
||||
// make sure we're getting just the new link
|
||||
pretty_assertions::assert_eq!(
|
||||
channels,
|
||||
vec![
|
||||
|
@ -665,12 +665,7 @@ async fn test_channels_moving(db: &Arc<Database>) {
|
|||
id: livestreaming_dag_sub_id,
|
||||
name: "livestreaming_dag_sub".to_string(),
|
||||
parent_id: Some(livestreaming_id),
|
||||
},
|
||||
Channel {
|
||||
id: livestreaming_dag_sub_id,
|
||||
name: "livestreaming_dag_sub".to_string(),
|
||||
parent_id: Some(livestreaming_dag_id),
|
||||
},
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -738,16 +733,6 @@ async fn test_channels_moving(db: &Arc<Database>) {
|
|||
name: "livestreaming".to_string(),
|
||||
parent_id: Some(gpui2_id),
|
||||
},
|
||||
Channel {
|
||||
id: livestreaming_id,
|
||||
name: "livestreaming".to_string(),
|
||||
parent_id: Some(zed_id),
|
||||
},
|
||||
Channel {
|
||||
id: livestreaming_id,
|
||||
name: "livestreaming".to_string(),
|
||||
parent_id: Some(crdb_id),
|
||||
},
|
||||
Channel {
|
||||
id: livestreaming_dag_id,
|
||||
name: "livestreaming_dag".to_string(),
|
||||
|
@ -826,16 +811,10 @@ async fn test_channels_moving(db: &Arc<Database>) {
|
|||
// zed - crdb -- livestreaming - livestreaming_dag - livestreaming_dag_sub
|
||||
// \---------/
|
||||
|
||||
// Make sure the recently removed link isn't returned
|
||||
// Since we're not moving it to anywhere, there's nothing to notify anyone about
|
||||
pretty_assertions::assert_eq!(
|
||||
channels,
|
||||
vec![
|
||||
Channel {
|
||||
id: livestreaming_dag_sub_id,
|
||||
name: "livestreaming_dag_sub".to_string(),
|
||||
parent_id: Some(livestreaming_dag_id),
|
||||
},
|
||||
]
|
||||
vec![]
|
||||
);
|
||||
|
||||
|
||||
|
|
|
@ -2400,7 +2400,7 @@ async fn move_channel(
|
|||
let channel_id = ChannelId::from_proto(request.channel_id);
|
||||
let from_parent = request.from_parent.map(ChannelId::from_proto);
|
||||
let to = request.to.map(ChannelId::from_proto);
|
||||
let channels = db
|
||||
let channels_to_send = db
|
||||
.move_channel(
|
||||
session.user_id,
|
||||
channel_id,
|
||||
|
@ -2432,7 +2432,7 @@ async fn move_channel(
|
|||
let members = db.get_channel_members(to).await?;
|
||||
let connection_pool = session.connection_pool().await;
|
||||
let update = proto::UpdateChannels {
|
||||
channels: channels.into_iter().map(|channel| proto::Channel {
|
||||
channels: channels_to_send.into_iter().map(|channel| proto::Channel {
|
||||
id: channel.id.to_proto(),
|
||||
name: channel.name,
|
||||
parent_id: channel.parent_id.map(ChannelId::to_proto),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue