mirror of https://github.com/zulip/zulip.git
user_profile: Show streams to subscribe for user's own profile.
We did not show the streams to subscribe in dropdown in user profile modal when user is not allowed to subscribe others even in the user's own profile modal which is not correct. This commit fixes it to show the streams in dropdown for user's own profile irrespective of whether user is allowed to subscribe others or not.
This commit is contained in:
parent
8c45e1dfed
commit
180ed2e50f
|
@ -347,7 +347,7 @@ export function get_streams_for_user(user_id: number): {
|
|||
}
|
||||
if (is_user_subscribed(sub.stream_id, user_id)) {
|
||||
subscribed_subs.push(sub);
|
||||
} else if (can_subscribe_others(sub)) {
|
||||
} else if (can_subscribe_user(sub, user_id)) {
|
||||
can_subscribe_subs.push(sub);
|
||||
}
|
||||
}
|
||||
|
@ -532,6 +532,14 @@ export function can_subscribe_others(sub: StreamSubscription): boolean {
|
|||
);
|
||||
}
|
||||
|
||||
export function can_subscribe_user(sub: StreamSubscription, user_id: number): boolean {
|
||||
if (people.is_my_user_id(user_id)) {
|
||||
return can_toggle_subscription(sub);
|
||||
}
|
||||
|
||||
return can_subscribe_others(sub);
|
||||
}
|
||||
|
||||
export function can_unsubscribe_others(sub: StreamSubscription): boolean {
|
||||
// Whether the current user has permission to remove other users
|
||||
// from the stream. Organization administrators can remove users
|
||||
|
|
|
@ -237,7 +237,16 @@ test("get_streams_for_user", () => {
|
|||
history_public_to_subscribers: false,
|
||||
stream_post_policy: settings_config.stream_post_policy_values.admins.code,
|
||||
};
|
||||
const subs = [denmark, social, test, world];
|
||||
const errors = {
|
||||
color: "green",
|
||||
name: "errors",
|
||||
stream_id: 5,
|
||||
is_muted: false,
|
||||
invite_only: false,
|
||||
history_public_to_subscribers: false,
|
||||
stream_post_policy: settings_config.stream_post_policy_values.admins.code,
|
||||
};
|
||||
const subs = [denmark, social, test, world, errors];
|
||||
for (const sub of subs) {
|
||||
stream_data.add_sub(sub);
|
||||
}
|
||||
|
@ -247,6 +256,10 @@ test("get_streams_for_user", () => {
|
|||
peer_data.set_subscribers(test.stream_id, [test_user.user_id]);
|
||||
peer_data.set_subscribers(world.stream_id, [me.user_id]);
|
||||
|
||||
page_params.realm_invite_to_stream_policy =
|
||||
settings_config.common_policy_values.by_admins_only.code;
|
||||
assert.deepEqual(stream_data.get_streams_for_user(me.user_id).can_subscribe, [social, errors]);
|
||||
|
||||
// test_user is subscribed to all three streams, but current user (me)
|
||||
// gets only two because of subscriber visibility policy of stream:
|
||||
// #denmark: current user is subscribed to it so he can see its subscribers.
|
||||
|
@ -261,8 +274,18 @@ test("get_streams_for_user", () => {
|
|||
assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, []);
|
||||
// Verify can subscribe if we're an administrator.
|
||||
page_params.is_admin = true;
|
||||
assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, [world]);
|
||||
assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, [
|
||||
world,
|
||||
errors,
|
||||
]);
|
||||
page_params.is_admin = false;
|
||||
|
||||
page_params.realm_invite_to_stream_policy =
|
||||
settings_config.common_policy_values.by_members.code;
|
||||
assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, [
|
||||
world,
|
||||
errors,
|
||||
]);
|
||||
});
|
||||
|
||||
test("renames", () => {
|
||||
|
|
Loading…
Reference in New Issue