stream_bots: Display unsubscribe button on bots full profile modal.

Displaying unsubscribe button on bots full profile modal, allowing bot
owners to ubsubscribe their bots from streams.

Admins can also unsubscribe any bot from any subscribed streams from
bots full profile modal.

Fixes part of: #21402
This commit is contained in:
yogesh sirsat 2022-06-28 02:04:21 +05:30 committed by Tim Abbott
parent 23fbd38b4c
commit d3b4b1cefd
3 changed files with 11 additions and 2 deletions

View File

@ -316,6 +316,9 @@ test_people("basics", () => {
assert.equal(people.get_bot_owner_user(bot_botson).full_name, "Isaac Newton"); assert.equal(people.get_bot_owner_user(bot_botson).full_name, "Isaac Newton");
assert.equal(people.can_admin_user(me), true);
assert.equal(people.can_admin_user(bot_botson), false);
// Add our cross-realm bot. It won't add to our human // Add our cross-realm bot. It won't add to our human
// count, and it has no owner. // count, and it has no owner.
people.add_cross_realm_user(welcome_bot); people.add_cross_realm_user(welcome_bot);

View File

@ -113,6 +113,13 @@ export function get_bot_owner_user(user) {
return get_by_user_id(owner_id); return get_by_user_id(owner_id);
} }
export function can_admin_user(user) {
return (
(user.is_bot && user.bot_owner_id && user.bot_owner_id === page_params.user_id) ||
is_my_user_id(user.user_id)
);
}
export function id_matches_email_operand(user_id, email) { export function id_matches_email_operand(user_id, email) {
const person = get_by_email(email); const person = get_by_email(email);

View File

@ -55,7 +55,7 @@ function initialize_bot_owner(element_id, bot_id) {
function format_user_stream_list_item(stream, user) { function format_user_stream_list_item(stream, user) {
const show_unsubscribe_button = const show_unsubscribe_button =
people.is_my_user_id(user.user_id) || settings_data.user_can_unsubscribe_other_users(); people.can_admin_user(user) || settings_data.user_can_unsubscribe_other_users();
const show_private_stream_unsub_tooltip = const show_private_stream_unsub_tooltip =
people.is_my_user_id(user.user_id) && stream.invite_only; people.is_my_user_id(user.user_id) && stream.invite_only;
return render_user_stream_list_item({ return render_user_stream_list_item({
@ -252,7 +252,6 @@ function handle_remove_stream_subscription(target_user_id, sub, success, failure
error: failure, error: failure,
}); });
} else { } else {
// Unsubscribed by admin.
subscriber_api.remove_user_id_from_stream(target_user_id, sub, success, failure); subscriber_api.remove_user_id_from_stream(target_user_id, sub, success, failure);
} }
} }