Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

user_profile: Add remove button to each group row in groups tab.

Pratik Chanda16e9099015d1
diff --git a/web/src/user_profile.ts b/web/src/user_profile.ts
index 3fc6d4ac359..d8ba92cb2c9 100644
--- a/web/src/user_profile.ts
+++ b/web/src/user_profile.ts
@@ -56,6 +56,7 @@ import type {HTMLSelectOneElement} from "./types.ts";
import * as ui_report from "./ui_report.ts";
import type {UploadWidget} from "./upload_widget.ts";
import * as user_deactivation_ui from "./user_deactivation_ui.ts";
+import * as user_group_edit_members from "./user_group_edit_members.ts";
import * as user_groups from "./user_groups.ts";
import type {UserGroup} from "./user_groups.ts";
import * as user_pill from "./user_pill.ts";
@@ -301,12 +302,17 @@ function format_user_stream_list_item_html(stream: StreamSubscription, user: Use
});
}
-function format_user_group_list_item_html(group: UserGroup): string {
+function format_user_group_list_item_html(group: UserGroup, user: User): string {
+ const is_direct_member = group.members.has(user.user_id);
+ const is_me = user.user_id === current_user.user_id;
+ const can_leave_user_group = is_me && settings_data.can_leave_user_group(group.id);
return render_user_group_list_item({
group_id: group.id,
name: group.name,
group_edit_url: hash_util.group_edit_url(group, "general"),
is_guest: current_user.is_guest,
+ is_direct_member,
+ can_remove_members: settings_data.can_manage_user_group(group.id) || can_leave_user_group,
});
}
@@ -349,7 +355,7 @@ function render_user_group_list(groups: UserGroup[], user: User): void {
$container.parent().removeClass("empty-list");
},
modifier_html(item) {
- return format_user_group_list_item_html(item);
+ return format_user_group_list_item_html(item, user);
},
$simplebar_container: $("#user-profile-modal .modal__body"),
});
@@ -1215,6 +1221,43 @@ export function initialize(): void {
handle_remove_stream_subscription(target_user_id, sub, removal_success, removal_failure);
});
+ $("body").on("click", "#user-profile-modal .remove-member-button", (e) => {
+ e.preventDefault();
+ const $group_row = $(e.currentTarget).closest("[data-group-id]");
+ const group_id = Number.parseInt($group_row.attr("data-group-id")!, 10);
+ const target_user_id = Number.parseInt($("#user-profile-modal").attr("data-user-id")!, 10);
+ const target_user_group = user_groups.get_user_group_from_id(group_id);
+ const $alert_box = $("#user-profile-groups-tab .user-profile-group-list-alert");
+
+ function removal_success(): void {
+ ui_report.success($t_html({defaultMessage: "Removed successfully!"}), $alert_box, 1200);
+ }
+
+ function removal_failure(): void {
+ let error_message;
+ if (people.is_my_user_id(target_user_id)) {
+ error_message = $t(
+ {defaultMessage: "Error leaving group {group_name}"},
+ {group_name: target_user_group.name},
+ );
+ } else {
+ error_message = $t(
+ {defaultMessage: "Error removing user from group {group_name}"},
+ {group_name: target_user_group.name},
+ );
+ }
+
+ ui_report.client_error(error_message, $alert_box, 1200);
+ }
+
+ user_group_edit_members.edit_user_group_membership({
+ group: target_user_group,
+ removed: [target_user_id],
+ success: removal_success,
+ error: removal_failure,
+ });
+ });
+
$("body").on("click", "#user-profile-modal #clear_stream_search", (e) => {
const $input = $("#user-profile-streams-tab .stream-search");
$input.val("");
diff --git a/web/styles/popovers.css b/web/styles/popovers.css
index aac389ce3d8..81ecaa8a784 100644
--- a/web/styles/popovers.css
+++ b/web/styles/popovers.css
@@ -588,6 +588,10 @@ ul.popover-group-menu-member-list {
margin-bottom: 8px;
}
+ .user-profile-group-list-alert {
+ margin-bottom: 8px;
+ }
+
.stream-privacy {
display: inline-block;
}
@@ -641,7 +645,8 @@ ul.popover-group-menu-member-list {
margin-bottom: 5px;
-webkit-overflow-scrolling: touch;
- .remove-subscription-button {
+ .remove-subscription-button,
+ .remove-member-button {
padding-top: 2px;
padding-bottom: 2px;
}
@@ -674,7 +679,8 @@ ul.popover-group-menu-member-list {
padding-right: 10px;
}
- &.remove_subscription {
+ &.remove_subscription,
+ &.remove_member {
text-align: right;
}
}
diff --git a/web/templates/user_group_list_item.hbs b/web/templates/user_group_list_item.hbs
index b9378b5f263..e03edf0c2d3 100644
--- a/web/templates/user_group_list_item.hbs
+++ b/web/templates/user_group_list_item.hbs
@@ -6,4 +6,13 @@
<a class="group_list_item_link" href="{{group_edit_url}}">{{name}}</a>
{{/if}}
</td>
+ {{#if can_remove_members }}
+ <td class="remove_member">
+ <div class="group_list_remove">
+ <button type="button" name="remove" class="remove-member-button button small rounded button-danger" {{#unless is_direct_member}}disabled="disabled"{{/unless}} >
+ {{t 'Remove' }}
+ </button>
+ </div>
+ </td>
+ {{/if}}
</tr>
diff --git a/web/templates/user_profile_modal.hbs b/web/templates/user_profile_modal.hbs
index 0126a4fd8e0..1624debae76 100644
--- a/web/templates/user_profile_modal.hbs
+++ b/web/templates/user_profile_modal.hbs
@@ -128,6 +128,7 @@
</div>
<div class="tabcontent" id="user-profile-groups-tab">
+ <div class="alert user-profile-group-list-alert"></div>
<div class="subscription-group-list empty-list">
<table class="user-group-list" data-empty="{{t 'No user group subscriptions.'}}"></table>
</div>