Disable git panel elements for readonly participants (#23897)

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2025-01-30 11:07:11 +02:00 committed by GitHub
parent e662e819fe
commit 1bc54c2c20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -827,6 +827,7 @@ impl GitPanel {
pub fn render_panel_header( pub fn render_panel_header(
&self, &self,
window: &mut Window, window: &mut Window,
has_write_access: bool,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> impl IntoElement { ) -> impl IntoElement {
let focus_handle = self.focus_handle(cx).clone(); let focus_handle = self.focus_handle(cx).clone();
@ -869,7 +870,7 @@ impl GitPanel {
} else { } else {
Tooltip::text("Stage all changes") Tooltip::text("Stage all changes")
}) })
.disabled(entry_count == 0) .disabled(!has_write_access || entry_count == 0)
.on_click(cx.listener( .on_click(cx.listener(
move |git_panel, _, window, cx| match all_staged { move |git_panel, _, window, cx| match all_staged {
true => git_panel.unstage_all(&UnstageAll, window, cx), true => git_panel.unstage_all(&UnstageAll, window, cx),
@ -960,7 +961,11 @@ impl GitPanel {
) )
} }
pub fn render_commit_editor(&self, cx: &Context<Self>) -> impl IntoElement { pub fn render_commit_editor(
&self,
has_write_access: bool,
cx: &Context<Self>,
) -> impl IntoElement {
let editor = self.commit_editor.clone(); let editor = self.commit_editor.clone();
let editor_focus_handle = editor.read(cx).focus_handle(cx).clone(); let editor_focus_handle = editor.read(cx).focus_handle(cx).clone();
let (can_commit, can_commit_all) = let (can_commit, can_commit_all) =
@ -968,8 +973,8 @@ impl GitPanel {
.as_ref() .as_ref()
.map_or((false, false), |active_repository| { .map_or((false, false), |active_repository| {
( (
active_repository.can_commit(false, cx), has_write_access && active_repository.can_commit(false, cx),
active_repository.can_commit(true, cx), has_write_access && active_repository.can_commit(true, cx),
) )
}); });
@ -1107,7 +1112,7 @@ impl GitPanel {
) )
} }
fn render_entries(&self, cx: &mut Context<Self>) -> impl IntoElement { fn render_entries(&self, has_write_access: bool, cx: &mut Context<Self>) -> impl IntoElement {
let entry_count = self.visible_entries.len(); let entry_count = self.visible_entries.len();
h_flex() h_flex()
@ -1118,7 +1123,7 @@ impl GitPanel {
move |git_panel, range, _window, cx| { move |git_panel, range, _window, cx| {
let mut items = Vec::with_capacity(range.end - range.start); let mut items = Vec::with_capacity(range.end - range.start);
git_panel.for_each_visible_entry(range, cx, |ix, details, cx| { git_panel.for_each_visible_entry(range, cx, |ix, details, cx| {
items.push(git_panel.render_entry(ix, details, cx)); items.push(git_panel.render_entry(ix, details, has_write_access, cx));
}); });
items items
} }
@ -1136,6 +1141,7 @@ impl GitPanel {
&self, &self,
ix: usize, ix: usize,
entry_details: GitListEntry, entry_details: GitListEntry,
has_write_access: bool,
cx: &Context<Self>, cx: &Context<Self>,
) -> impl IntoElement { ) -> impl IntoElement {
let repo_path = entry_details.repo_path.clone(); let repo_path = entry_details.repo_path.clone();
@ -1215,6 +1221,7 @@ impl GitPanel {
.is_staged .is_staged
.map_or(ToggleState::Indeterminate, ToggleState::from), .map_or(ToggleState::Indeterminate, ToggleState::from),
) )
.disabled(!has_write_access)
.fill() .fill()
.elevation(ElevationIndex::Surface) .elevation(ElevationIndex::Surface)
.on_click({ .on_click({
@ -1296,19 +1303,23 @@ impl Render for GitPanel {
.map_or(false, |active_repository| { .map_or(false, |active_repository| {
active_repository.entry_count() > 0 active_repository.entry_count() > 0
}); });
let has_co_authors = self let room = self
.workspace .workspace
.upgrade() .upgrade()
.and_then(|workspace| workspace.read(cx).active_call()?.read(cx).room().cloned()) .and_then(|workspace| workspace.read(cx).active_call()?.read(cx).room().cloned());
.map(|room| {
let room = room.read(cx); let has_write_access = room
room.local_participant().can_write() .as_ref()
&& room .map_or(true, |room| room.read(cx).local_participant().can_write());
.remote_participants()
.values() let has_co_authors = room.map_or(false, |room| {
.any(|remote_participant| remote_participant.can_write()) has_write_access
}) && room
.unwrap_or(false); .read(cx)
.remote_participants()
.values()
.any(|remote_participant| remote_participant.can_write())
});
v_flex() v_flex()
.id("git_panel") .id("git_panel")
@ -1366,15 +1377,15 @@ impl Render for GitPanel {
.font_buffer(cx) .font_buffer(cx)
.py_1() .py_1()
.bg(ElevationIndex::Surface.bg(cx)) .bg(ElevationIndex::Surface.bg(cx))
.child(self.render_panel_header(window, cx)) .child(self.render_panel_header(window, has_write_access, cx))
.child(self.render_divider(cx)) .child(self.render_divider(cx))
.child(if has_entries { .child(if has_entries {
self.render_entries(cx).into_any_element() self.render_entries(has_write_access, cx).into_any_element()
} else { } else {
self.render_empty_state(cx).into_any_element() self.render_empty_state(cx).into_any_element()
}) })
.child(self.render_divider(cx)) .child(self.render_divider(cx))
.child(self.render_commit_editor(cx)) .child(self.render_commit_editor(has_write_access, cx))
} }
} }