Settings only offered to members who can manage something (permission::can_manage_community)
Browse files at this commit92a09380f49c7f734801bade4419587720ae8636Parent: 395f5e1- fix
- Settings only offered to members who can manage something (permission::can_manage_community)
- settings page never empty (Leave always shown)
- builder action grid aligned again
5 changed files +20 -4
- crates/client/src/gui/builder/ui.rs +1 -0
- crates/client/src/gui/community_card.rs +5 -1
- crates/client/src/gui/community_settings.rs +4 -3
- crates/client/src/gui/sidebar.rs +2 -0
- crates/common/src/permission.rs +8 -0
crates/client/src/gui/builder/ui.rsmodified+1 -0
| @@ -97,6 +97,7 @@ pub(super) fn action_button( | ||
| 97 | 97 | ) -> Stateful<Div> { |
| 98 | 98 | parts::press(id, palette.tokens, action) |
| 99 | 99 | .tip(tip) |
| 100 | + .px_0() | |
| 100 | 101 | .min_w(px(size::THUMB)) |
| 101 | 102 | .text_size(text(text::CAPTION)) |
| 102 | 103 | .font_weight(FontWeight::MEDIUM) |
crates/client/src/gui/community_card.rsmodified+5 -1
| @@ -87,6 +87,7 @@ pub(super) fn community_popover( | ||
| 87 | 87 | id, |
| 88 | 88 | true, |
| 89 | 89 | permission::can_leave(yumush.actor_rank()), |
| 90 | + permission::can_manage_community(yumush.actor_rank()), | |
| 90 | 91 | yumush, |
| 91 | 92 | &entity, |
| 92 | 93 | &popover, |
| @@ -99,6 +100,7 @@ pub(super) fn room_rows( | ||
| 99 | 100 | id: Id, |
| 100 | 101 | group: bool, |
| 101 | 102 | can_leave: bool, |
| 103 | + can_manage: bool, | |
| 102 | 104 | yumush: &Yumush, |
| 103 | 105 | entity: &Entity<Yumush>, |
| 104 | 106 | popover: &Entity<PopoverState>, |
| @@ -133,7 +135,9 @@ pub(super) fn room_rows( | ||
| 133 | 135 | palette.text, |
| 134 | 136 | |yumush, id, window, cx| yumush.open_invite(id, window, cx), |
| 135 | 137 | )) |
| 136 | - .child(row( | |
| 138 | + }) | |
| 139 | + .when(group && can_manage, |this| { | |
| 140 | + this.child(row( | |
| 137 | 141 | "room_settings", |
| 138 | 142 | words.settings, |
| 139 | 143 | IconName::Settings, |
crates/client/src/gui/community_settings.rsmodified+4 -3
| @@ -199,10 +199,11 @@ impl Yumush { | ||
| 199 | 199 | .into_any_element(), |
| 200 | 200 | ); |
| 201 | 201 | } |
| 202 | - if !sections.is_empty() { | |
| 203 | - let first = sections.remove(0); | |
| 204 | - sections.insert(0, with_danger(first, danger)); | |
| 202 | + if sections.is_empty() { | |
| 203 | + sections.push(section(w().community_settings.general, palette, Vec::new())); | |
| 205 | 204 | } |
| 205 | + let first = sections.remove(0); | |
| 206 | + sections.insert(0, with_danger(first, danger)); | |
| 206 | 207 | |
| 207 | 208 | page( |
| 208 | 209 | "community_settings_scroll", |
crates/client/src/gui/sidebar.rsmodified+2 -0
| @@ -563,6 +563,7 @@ impl Yumush { | ||
| 563 | 563 | let active = self.chat.is_selected(community.id); |
| 564 | 564 | let group = community.kind.is_group(); |
| 565 | 565 | let can_leave = group && (!active || permission::can_leave(self.actor_rank())); |
| 566 | + let can_manage = !active || permission::can_manage_community(self.actor_rank()); | |
| 566 | 567 | let muted = self.chat.muted.contains(&community.id); |
| 567 | 568 | let unread = self.chat.unread.get(&community.id); |
| 568 | 569 | let community_id = community.id; |
| @@ -634,6 +635,7 @@ impl Yumush { | ||
| 634 | 635 | community_id, |
| 635 | 636 | group, |
| 636 | 637 | can_leave, |
| 638 | + can_manage, | |
| 637 | 639 | yumush, |
| 638 | 640 | &menu, |
| 639 | 641 | popover, |
crates/common/src/permission.rsmodified+8 -0
| @@ -77,6 +77,14 @@ pub fn can_transfer_ownership(actor: Option<Rank>) -> bool { | ||
| 77 | 77 | actor >= Some(Rank::Owner) |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | +pub fn can_manage_community(actor: Option<Rank>) -> bool { | |
| 81 | + can_rename_community(actor) | |
| 82 | + || can_manage_voice(actor) | |
| 83 | + || can_unban(actor) | |
| 84 | + || can_read_logs(actor) | |
| 85 | + || can_delete_community(actor) | |
| 86 | +} | |
| 87 | + | |
| 80 | 88 | pub fn can_leave(actor: Option<Rank>) -> bool { |
| 81 | 89 | actor.is_some() && actor != Some(Rank::Owner) |
| 82 | 90 | } |