left_sidebar: Hide new topic button on restricted compose permission.

Earlier, in left stream sidebar, new topic button was shown for all
stream rows irrespective of compose permission of the user for
individual streams.

This commit changes the behaviour by hiding the new topic button if
user doesn't have appropriate compose permission for individual
streams.

Fixes: zulip#31800.
This commit is contained in:
Pratik Chanda 2024-10-23 00:30:15 +05:30 committed by Karl Stolley
parent d8cf3ff2e9
commit 34ff1de338
3 changed files with 20 additions and 0 deletions

View File

@ -445,6 +445,7 @@ export function set_in_home_view(stream_id: number, in_home: boolean): void {
function build_stream_sidebar_li(sub: StreamSubscription): JQuery {
const name = sub.name;
const is_muted = stream_data.is_muted(sub.stream_id);
const can_post_messages = stream_data.can_post_messages_in_stream(sub);
const args = {
name,
id: sub.stream_id,
@ -455,6 +456,7 @@ function build_stream_sidebar_li(sub: StreamSubscription): JQuery {
color: sub.color,
pin_to_top: sub.pin_to_top,
hide_unread_count: settings_data.should_mask_unread_count(is_muted),
can_post_messages,
};
const $list_item = $(render_stream_sidebar_row(args));
return $list_item;

View File

@ -11,9 +11,11 @@
<a href="{{url}}" title="{{name}}" class="stream-name">{{name}}</a>
<div class="left-sidebar-controls">
{{#if can_post_messages}}
<div class="channel-new-topic-button tippy-zulip-tooltip hidden-for-spectators" data-tippy-content="{{t 'New topic'}}" data-stream-id="{{id}}">
<i class="channel-new-topic-icon zulip-icon zulip-icon-square-plus" aria-hidden="true"></i>
</div>
{{/if}}
</div>
<div class="stream-markers-and-unreads">

View File

@ -7,9 +7,14 @@ const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params");
const people = zrequire("people");
const {set_current_user} = zrequire("state_data");
set_global("document", "document-stub");
page_params.realm_users = [];
const current_user = {};
set_current_user(current_user);
// We use this with override.
let unread_unmuted_count;
@ -39,6 +44,16 @@ const {initialize_user_settings} = zrequire("user_settings");
const user_settings = {};
initialize_user_settings({user_settings});
const me = {
email: "me@example.com",
user_id: 30,
full_name: "Me Myself",
date_joined: new Date(),
};
people.add_active_user(me);
people.initialize_current_user(me.user_id);
const devel = {
name: "devel",
stream_id: 100,
@ -673,6 +688,7 @@ test_ui("rename_stream", ({mock_template, override}) => {
color: payload.color,
pin_to_top: true,
hide_unread_count: true,
can_post_messages: true,
});
return {to_$: () => $li_stub};
});