mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 10:42:08 +00:00
Allow moving channels to the root
This commit is contained in:
parent
32367eba14
commit
b5cbfb8f1d
2 changed files with 43 additions and 11 deletions
|
@ -1209,24 +1209,29 @@ impl Database {
|
||||||
admin_id: UserId,
|
admin_id: UserId,
|
||||||
) -> Result<Option<MoveChannelResult>> {
|
) -> Result<Option<MoveChannelResult>> {
|
||||||
self.transaction(|tx| async move {
|
self.transaction(|tx| async move {
|
||||||
let Some(new_parent_id) = new_parent_id else {
|
let channel = self.get_channel_internal(channel_id, &*tx).await?;
|
||||||
return Err(anyhow!("not supported"))?;
|
self.check_user_is_channel_admin(&channel, admin_id, &*tx)
|
||||||
};
|
.await?;
|
||||||
|
|
||||||
|
let new_parent_path;
|
||||||
|
let new_parent_channel;
|
||||||
|
if let Some(new_parent_id) = new_parent_id {
|
||||||
let new_parent = self.get_channel_internal(new_parent_id, &*tx).await?;
|
let new_parent = self.get_channel_internal(new_parent_id, &*tx).await?;
|
||||||
self.check_user_is_channel_admin(&new_parent, admin_id, &*tx)
|
self.check_user_is_channel_admin(&new_parent, admin_id, &*tx)
|
||||||
.await?;
|
.await?;
|
||||||
let channel = self.get_channel_internal(channel_id, &*tx).await?;
|
|
||||||
|
|
||||||
self.check_user_is_channel_admin(&channel, admin_id, &*tx)
|
new_parent_path = new_parent.path();
|
||||||
.await?;
|
new_parent_channel = Some(new_parent);
|
||||||
|
} else {
|
||||||
|
new_parent_path = String::new();
|
||||||
|
new_parent_channel = None;
|
||||||
|
};
|
||||||
|
|
||||||
let previous_participants = self
|
let previous_participants = self
|
||||||
.get_channel_participant_details_internal(&channel, &*tx)
|
.get_channel_participant_details_internal(&channel, &*tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let old_path = format!("{}{}/", channel.parent_path, channel.id);
|
let old_path = format!("{}{}/", channel.parent_path, channel.id);
|
||||||
let new_parent_path = format!("{}{}/", new_parent.parent_path, new_parent.id);
|
|
||||||
let new_path = format!("{}{}/", new_parent_path, channel.id);
|
let new_path = format!("{}{}/", new_parent_path, channel.id);
|
||||||
|
|
||||||
if old_path == new_path {
|
if old_path == new_path {
|
||||||
|
@ -1235,7 +1240,19 @@ impl Database {
|
||||||
|
|
||||||
let mut model = channel.into_active_model();
|
let mut model = channel.into_active_model();
|
||||||
model.parent_path = ActiveValue::Set(new_parent_path);
|
model.parent_path = ActiveValue::Set(new_parent_path);
|
||||||
model.update(&*tx).await?;
|
let channel = model.update(&*tx).await?;
|
||||||
|
|
||||||
|
if new_parent_channel.is_none() {
|
||||||
|
channel_member::ActiveModel {
|
||||||
|
id: ActiveValue::NotSet,
|
||||||
|
channel_id: ActiveValue::Set(channel_id),
|
||||||
|
user_id: ActiveValue::Set(admin_id),
|
||||||
|
accepted: ActiveValue::Set(true),
|
||||||
|
role: ActiveValue::Set(ChannelRole::Admin),
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
let descendent_ids =
|
let descendent_ids =
|
||||||
ChannelId::find_by_statement::<QueryIds>(Statement::from_sql_and_values(
|
ChannelId::find_by_statement::<QueryIds>(Statement::from_sql_and_values(
|
||||||
|
@ -1251,7 +1268,10 @@ impl Database {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let participants_to_update: HashMap<_, _> = self
|
let participants_to_update: HashMap<_, _> = self
|
||||||
.participants_to_notify_for_channel_change(&new_parent, &*tx)
|
.participants_to_notify_for_channel_change(
|
||||||
|
new_parent_channel.as_ref().unwrap_or(&channel),
|
||||||
|
&*tx,
|
||||||
|
)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -438,6 +438,18 @@ async fn test_db_channel_moving_bugs(db: &Arc<Database>) {
|
||||||
(livestreaming_id, &[zed_id, projects_id]),
|
(livestreaming_id, &[zed_id, projects_id]),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Move the project channel to the root
|
||||||
|
db.move_channel(projects_id, None, user_id).await.unwrap();
|
||||||
|
let result = db.get_channels_for_user(user_id).await.unwrap();
|
||||||
|
assert_channel_tree(
|
||||||
|
result.channels,
|
||||||
|
&[
|
||||||
|
(zed_id, &[]),
|
||||||
|
(projects_id, &[]),
|
||||||
|
(livestreaming_id, &[projects_id]),
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
test_both_dbs!(
|
test_both_dbs!(
|
||||||
|
|
Loading…
Reference in a new issue