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
|
@ -23,7 +23,7 @@ use gpui::{
|
|||
use menu::{Cancel, Confirm, SecondaryConfirm, SelectNext, SelectPrev};
|
||||
use project::{Fs, Project};
|
||||
use rpc::{
|
||||
proto::{self, PeerId},
|
||||
proto::{self, ChannelVisibility, PeerId},
|
||||
ErrorCode, ErrorExt,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
@ -1134,13 +1134,6 @@ impl CollabPanel {
|
|||
"Rename",
|
||||
Some(Box::new(SecondaryConfirm)),
|
||||
cx.handler_for(&this, move |this, cx| this.rename_channel(channel_id, cx)),
|
||||
)
|
||||
.entry(
|
||||
"Move this channel",
|
||||
None,
|
||||
cx.handler_for(&this, move |this, cx| {
|
||||
this.start_move_channel(channel_id, cx)
|
||||
}),
|
||||
);
|
||||
|
||||
if let Some(channel_name) = clipboard_channel_name {
|
||||
|
@ -1153,23 +1146,52 @@ impl CollabPanel {
|
|||
);
|
||||
}
|
||||
|
||||
context_menu = context_menu
|
||||
.separator()
|
||||
.entry(
|
||||
"Invite Members",
|
||||
None,
|
||||
cx.handler_for(&this, move |this, cx| this.invite_members(channel_id, cx)),
|
||||
)
|
||||
.entry(
|
||||
if self.channel_store.read(cx).is_root_channel(channel_id) {
|
||||
context_menu = context_menu.separator().entry(
|
||||
"Manage Members",
|
||||
None,
|
||||
cx.handler_for(&this, move |this, cx| this.manage_members(channel_id, cx)),
|
||||
)
|
||||
.entry(
|
||||
"Delete",
|
||||
} else {
|
||||
context_menu = context_menu.entry(
|
||||
"Move this channel",
|
||||
None,
|
||||
cx.handler_for(&this, move |this, cx| this.remove_channel(channel_id, cx)),
|
||||
cx.handler_for(&this, move |this, cx| {
|
||||
this.start_move_channel(channel_id, cx)
|
||||
}),
|
||||
);
|
||||
if self.channel_store.read(cx).is_public_channel(channel_id) {
|
||||
context_menu = context_menu.separator().entry(
|
||||
"Make Channel Private",
|
||||
None,
|
||||
cx.handler_for(&this, move |this, cx| {
|
||||
this.set_channel_visibility(
|
||||
channel_id,
|
||||
ChannelVisibility::Members,
|
||||
cx,
|
||||
)
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
context_menu = context_menu.separator().entry(
|
||||
"Make Channel Public",
|
||||
None,
|
||||
cx.handler_for(&this, move |this, cx| {
|
||||
this.set_channel_visibility(
|
||||
channel_id,
|
||||
ChannelVisibility::Public,
|
||||
cx,
|
||||
)
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
context_menu = context_menu.entry(
|
||||
"Delete",
|
||||
None,
|
||||
cx.handler_for(&this, move |this, cx| this.remove_channel(channel_id, cx)),
|
||||
);
|
||||
}
|
||||
|
||||
context_menu
|
||||
|
@ -1490,10 +1512,6 @@ impl CollabPanel {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
fn invite_members(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
|
||||
self.show_channel_modal(channel_id, channel_modal::Mode::InviteMembers, cx);
|
||||
}
|
||||
|
||||
fn manage_members(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
|
||||
self.show_channel_modal(channel_id, channel_modal::Mode::ManageMembers, cx);
|
||||
}
|
||||
|
@ -1530,6 +1548,27 @@ impl CollabPanel {
|
|||
}
|
||||
}
|
||||
|
||||
fn set_channel_visibility(
|
||||
&mut self,
|
||||
channel_id: ChannelId,
|
||||
visibility: ChannelVisibility,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.channel_store
|
||||
.update(cx, |channel_store, cx| {
|
||||
channel_store.set_channel_visibility(channel_id, visibility, cx)
|
||||
})
|
||||
.detach_and_prompt_err("Failed to set channel visibility", cx, |e, _| match e.error_code() {
|
||||
ErrorCode::BadPublicNesting =>
|
||||
if e.error_tag("direction") == Some("parent") {
|
||||
Some("To make a channel public, its parent channel must be public.".to_string())
|
||||
} else {
|
||||
Some("To make a channel private, all of its subchannels must be private.".to_string())
|
||||
},
|
||||
_ => None
|
||||
});
|
||||
}
|
||||
|
||||
fn start_move_channel(&mut self, channel_id: ChannelId, _cx: &mut ViewContext<Self>) {
|
||||
self.channel_clipboard = Some(ChannelMoveClipboard { channel_id });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue