Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
stream_data: Add content/metadata access argument to change permission.
Shubham Padiab786e70b8900
diff --git a/web/src/stream_card_popover.ts b/web/src/stream_card_popover.tsindex 3f55c1c8cba..9591eeffdaa 100644--- a/web/src/stream_card_popover.ts+++ b/web/src/stream_card_popover.ts@@ -51,10 +51,12 @@ export function initialize(): void {// modals.close_active_if_any() is mainly used to handle navigation to channel settings// using the popover that is opened when clicking on channel pills in the invite user modal.modals.close_active_if_any();- const can_change_name_description = stream_data.can_edit_description(sub);- const can_change_stream_permissions = stream_data.can_change_permissions(sub);+ const can_change_stream_permissions = stream_data.can_change_permissions(+ sub,+ false,+ );let stream_edit_hash = hash_util.channels_settings_edit_url(sub, "general");- if (!can_change_stream_permissions && !can_change_name_description) {+ if (!can_change_stream_permissions) {stream_edit_hash = hash_util.channels_settings_edit_url(sub, "personal");}browser_history.go_to_location(stream_edit_hash);diff --git a/web/src/stream_data.ts b/web/src/stream_data.tsindex c0a9374d8cc..953a14cfc2e 100644--- a/web/src/stream_data.ts+++ b/web/src/stream_data.ts@@ -607,36 +607,17 @@ export function can_preview(sub: StreamSubscription): boolean {return sub.subscribed || !sub.invite_only || sub.previously_subscribed;}-export function can_change_permissions(sub: StreamSubscription): boolean {- // Whether the current user has permission to administer this stream.- // Organisation admins have this permission regardless of whether- // they are part of can_administer_channel_group. Non-subscribers with- // these permission can edit name and description of a private channel- // without being subscribed to it.-- if (sub.invite_only && !sub.subscribed) {+export function can_change_permissions(+ sub: StreamSubscription,+ require_content_access = true,+): boolean {+ if (require_content_access && !has_content_access(sub)) {+ return false;+ } else if (!require_content_access && !has_metadata_access(sub)) {return false;}- if (current_user.is_admin) {- return true;- }-- return user_groups.is_user_in_setting_group(- sub.can_administer_channel_group,- people.my_current_user_id(),- );-}--export function can_edit_description(sub: StreamSubscription): boolean {- if (current_user.is_admin) {- return true;- }-- return user_groups.is_user_in_setting_group(- sub.can_administer_channel_group,- people.my_current_user_id(),- );+ return can_administer_accessible_channel(sub);}export function can_view_subscribers(sub: StreamSubscription): boolean {diff --git a/web/src/stream_popover.ts b/web/src/stream_popover.tsindex 31e1665690f..1cf65e2cb62 100644--- a/web/src/stream_popover.ts+++ b/web/src/stream_popover.ts@@ -150,10 +150,12 @@ function build_stream_popover(opts: {elt: HTMLElement; stream_id: number}): void// Admin can change any stream's name & description either stream is public or// private, subscribed or unsubscribed.- const can_change_name_description = stream_data.can_edit_description(sub);- const can_change_stream_permissions = stream_data.can_change_permissions(sub);+ const can_change_stream_permissions = stream_data.can_change_permissions(+ sub,+ false,+ );let stream_edit_hash = hash_util.channels_settings_edit_url(sub, "general");- if (!can_change_stream_permissions && !can_change_name_description) {+ if (!can_change_stream_permissions) {stream_edit_hash = hash_util.channels_settings_edit_url(sub, "personal");}browser_history.go_to_location(stream_edit_hash);diff --git a/web/src/stream_settings_data.ts b/web/src/stream_settings_data.tsindex a2198d37c14..9c6aadb55c5 100644--- a/web/src/stream_settings_data.ts+++ b/web/src/stream_settings_data.ts@@ -40,9 +40,7 @@ export function get_sub_for_settings(sub: StreamSubscription): SettingsSubscriptis_creator: sub.creator_id === current_user.user_id,is_realm_admin: current_user.is_admin,- // Admin can change any stream's name & description either stream is public or- // private, subscribed or unsubscribed.- can_change_name_description: stream_data.can_edit_description(sub),+ can_change_name_description: stream_data.can_change_permissions(sub, false),should_display_subscription_button: stream_data.can_toggle_subscription(sub),should_display_preview_button: stream_data.can_preview(sub),diff --git a/web/tests/peer_data.test.cjs b/web/tests/peer_data.test.cjsindex 154ec182478..20bc592ec69 100644--- a/web/tests/peer_data.test.cjs+++ b/web/tests/peer_data.test.cjs@@ -17,17 +17,16 @@ const peer_data = zrequire("peer_data");const people = zrequire("people");const {set_current_user} = zrequire("state_data");const stream_data = zrequire("stream_data");+const user_groups = zrequire("user_groups");set_current_user({});page_params.realm_users = [];-const me = {email: "[email protected]",full_name: "Current User",user_id: 100,};-// set up user dataconst fred = {email: "[email protected]",@@ -52,19 +51,29 @@ const bot_botson = {role: 300,};+const nobody_group = {+ name: "Nobody",+ id: 1,+ members: new Set([]),+ is_system_group: true,+ direct_subgroup_ids: new Set([]),+};+function contains_sub(subs, sub) {return subs.some((s) => s.name === sub.name);}-function test(label, f) {run_test(label, ({override}) => {peer_data.clear_for_testing();stream_data.clear_subscriptions();-people.init();people.add_active_user(me);people.initialize_current_user(me.user_id);+ user_groups.initialize({+ realm_user_groups: [nobody_group],+ });+f({override});});}@@ -96,7 +105,13 @@ test("unsubscribe", () => {});test("subscribers", () => {- const sub = {name: "Rome", subscribed: true, stream_id: 1001};+ const sub = {+ name: "Rome",+ subscribed: true,+ stream_id: 1001,+ can_add_subscribers_group: nobody_group.id,+ can_administer_channel_group: nobody_group.id,+ };stream_data.add_sub(sub);people.add_active_user(fred);