mirror of https://github.com/zulip/zulip.git
user_groups: Handle deactivated groups in webapp.
This commit is contained in:
parent
5c790aac72
commit
c53563d0e7
|
@ -146,6 +146,7 @@ export const user_group_schema = z.object({
|
||||||
direct_subgroup_ids: z.array(z.number()),
|
direct_subgroup_ids: z.array(z.number()),
|
||||||
can_manage_group: z.number(),
|
can_manage_group: z.number(),
|
||||||
can_mention_group: z.number(),
|
can_mention_group: z.number(),
|
||||||
|
deactivated: z.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const user_topic_schema = z.object({
|
export const user_topic_schema = z.object({
|
||||||
|
|
|
@ -101,6 +101,7 @@ export function toggle_user_group_info_popover(
|
||||||
group_edit_url: hash_util.group_edit_url(group, "general"),
|
group_edit_url: hash_util.group_edit_url(group, "general"),
|
||||||
is_guest: current_user.is_guest,
|
is_guest: current_user.is_guest,
|
||||||
is_system_group: group.is_system_group,
|
is_system_group: group.is_system_group,
|
||||||
|
deactivated: group.deactivated,
|
||||||
};
|
};
|
||||||
instance.setContent(ui_util.parse_html(render_user_group_info_popover(args)));
|
instance.setContent(ui_util.parse_html(render_user_group_info_popover(args)));
|
||||||
},
|
},
|
||||||
|
|
|
@ -57,6 +57,7 @@ export function add(user_group_raw: UserGroupRaw): UserGroup {
|
||||||
direct_subgroup_ids: new Set(user_group_raw.direct_subgroup_ids),
|
direct_subgroup_ids: new Set(user_group_raw.direct_subgroup_ids),
|
||||||
can_manage_group: user_group_raw.can_manage_group,
|
can_manage_group: user_group_raw.can_manage_group,
|
||||||
can_mention_group: user_group_raw.can_mention_group,
|
can_mention_group: user_group_raw.can_mention_group,
|
||||||
|
deactivated: user_group_raw.deactivated,
|
||||||
};
|
};
|
||||||
|
|
||||||
user_group_name_dict.set(user_group.name, user_group);
|
user_group_name_dict.set(user_group.name, user_group);
|
||||||
|
@ -111,9 +112,19 @@ export function get_user_group_from_name(name: string): UserGroup | undefined {
|
||||||
return user_group_name_dict.get(name);
|
return user_group_name_dict.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_realm_user_groups(): UserGroup[] {
|
export function get_realm_user_groups(include_deactivated = false): UserGroup[] {
|
||||||
const user_groups = [...user_group_by_id_dict.values()].sort((a, b) => a.id - b.id);
|
const user_groups = [...user_group_by_id_dict.values()].sort((a, b) => a.id - b.id);
|
||||||
return user_groups.filter((group) => !group.is_system_group);
|
return user_groups.filter((group) => {
|
||||||
|
if (group.is_system_group) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!include_deactivated && group.deactivated) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_user_groups_allowed_to_mention(): UserGroup[] {
|
export function get_user_groups_allowed_to_mention(): UserGroup[] {
|
||||||
|
|
|
@ -9,6 +9,11 @@
|
||||||
<div class="popover-group-menu-description">{{group_description}}</div>
|
<div class="popover-group-menu-description">{{group_description}}</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
{{#if deactivated}}
|
||||||
|
<li role="none" class="popover-menu-list-item text-item half-opacity italic hidden-for-spectators">
|
||||||
|
<span class="popover-menu-label">{{t "This group has been deactivated." }}</span>
|
||||||
|
</li>
|
||||||
|
{{/if}}
|
||||||
<li role="separator" class="popover-menu-separator"></li>
|
<li role="separator" class="popover-menu-separator"></li>
|
||||||
<li role="none" class="popover-menu-list-item">
|
<li role="none" class="popover-menu-list-item">
|
||||||
{{#if members.length}}
|
{{#if members.length}}
|
||||||
|
@ -28,7 +33,7 @@
|
||||||
<span class="popover-group-menu-placeholder"><i>{{t 'This group has no members.'}}</i></span>
|
<span class="popover-group-menu-placeholder"><i>{{t 'This group has no members.'}}</i></span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</li>
|
</li>
|
||||||
{{#unless (or is_guest is_system_group)}}
|
{{#unless (or is_guest is_system_group deactivated)}}
|
||||||
<li role="separator" class="popover-menu-separator hidden-for-spectators"></li>
|
<li role="separator" class="popover-menu-separator hidden-for-spectators"></li>
|
||||||
<li role="none" class="link-item popover-menu-list-item hidden-for-spectators">
|
<li role="none" class="link-item popover-menu-list-item hidden-for-spectators">
|
||||||
<a href="{{group_edit_url}}" role="menuitem" class="navigate-link-on-enter popover-menu-link" tabindex="0">
|
<a href="{{group_edit_url}}" role="menuitem" class="navigate-link-on-enter popover-menu-link" tabindex="0">
|
||||||
|
|
|
@ -432,6 +432,7 @@ const hamletcharacters = user_group_item({
|
||||||
direct_subgroup_ids: new Set([]),
|
direct_subgroup_ids: new Set([]),
|
||||||
can_manage_group: 2,
|
can_manage_group: 2,
|
||||||
can_mention_group: 2,
|
can_mention_group: 2,
|
||||||
|
deactivated: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const backend = user_group_item({
|
const backend = user_group_item({
|
||||||
|
@ -445,6 +446,7 @@ const backend = user_group_item({
|
||||||
direct_subgroup_ids: new Set([1]),
|
direct_subgroup_ids: new Set([1]),
|
||||||
can_manage_group: 1,
|
can_manage_group: 1,
|
||||||
can_mention_group: 1,
|
can_mention_group: 1,
|
||||||
|
deactivated: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const call_center = user_group_item({
|
const call_center = user_group_item({
|
||||||
|
@ -458,6 +460,7 @@ const call_center = user_group_item({
|
||||||
direct_subgroup_ids: new Set([]),
|
direct_subgroup_ids: new Set([]),
|
||||||
can_manage_group: 2,
|
can_manage_group: 2,
|
||||||
can_mention_group: 2,
|
can_mention_group: 2,
|
||||||
|
deactivated: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const make_emoji = (emoji_dict) => ({
|
const make_emoji = (emoji_dict) => ({
|
||||||
|
|
|
@ -21,6 +21,7 @@ run_test("user_groups", () => {
|
||||||
direct_subgroup_ids: new Set([4, 5]),
|
direct_subgroup_ids: new Set([4, 5]),
|
||||||
can_manage_group: 1,
|
can_manage_group: 1,
|
||||||
can_mention_group: 2,
|
can_mention_group: 2,
|
||||||
|
deactivated: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const params = {};
|
const params = {};
|
||||||
|
@ -42,6 +43,7 @@ run_test("user_groups", () => {
|
||||||
direct_subgroup_ids: new Set([]),
|
direct_subgroup_ids: new Set([]),
|
||||||
can_manage_group: 1,
|
can_manage_group: 1,
|
||||||
can_mention_group: 2,
|
can_mention_group: 2,
|
||||||
|
deactivated: false,
|
||||||
};
|
};
|
||||||
const all = {
|
const all = {
|
||||||
name: "Everyone",
|
name: "Everyone",
|
||||||
|
@ -51,6 +53,17 @@ run_test("user_groups", () => {
|
||||||
direct_subgroup_ids: new Set([4, 5, 6]),
|
direct_subgroup_ids: new Set([4, 5, 6]),
|
||||||
can_manage_group: 1,
|
can_manage_group: 1,
|
||||||
can_mention_group: 1,
|
can_mention_group: 1,
|
||||||
|
deactivated: false,
|
||||||
|
};
|
||||||
|
const deactivated_group = {
|
||||||
|
name: "Deactivated test group",
|
||||||
|
id: 3,
|
||||||
|
members: new Set([1, 2, 3]),
|
||||||
|
is_system_group: false,
|
||||||
|
direct_subgroup_ids: new Set([4, 5, 6]),
|
||||||
|
can_manage_group: 1,
|
||||||
|
can_mention_group: 1,
|
||||||
|
deactivated: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
user_groups.add(admins);
|
user_groups.add(admins);
|
||||||
|
@ -92,11 +105,18 @@ run_test("user_groups", () => {
|
||||||
assert.equal(user_groups.get_user_group_from_name("new admins").id, 1);
|
assert.equal(user_groups.get_user_group_from_name("new admins").id, 1);
|
||||||
|
|
||||||
user_groups.add(all);
|
user_groups.add(all);
|
||||||
|
user_groups.add(deactivated_group);
|
||||||
const user_groups_array = user_groups.get_realm_user_groups();
|
const user_groups_array = user_groups.get_realm_user_groups();
|
||||||
assert.equal(user_groups_array.length, 2);
|
assert.equal(user_groups_array.length, 2);
|
||||||
assert.equal(user_groups_array[1].name, "Everyone");
|
assert.equal(user_groups_array[1].name, "Everyone");
|
||||||
assert.equal(user_groups_array[0].name, "new admins");
|
assert.equal(user_groups_array[0].name, "new admins");
|
||||||
|
|
||||||
|
const all_user_groups_array = user_groups.get_realm_user_groups(true);
|
||||||
|
assert.equal(all_user_groups_array.length, 3);
|
||||||
|
assert.equal(all_user_groups_array[2].name, "Deactivated test group");
|
||||||
|
assert.equal(all_user_groups_array[1].name, "Everyone");
|
||||||
|
assert.equal(all_user_groups_array[0].name, "new admins");
|
||||||
|
|
||||||
const groups_of_users = user_groups.get_user_groups_of_user(user_id_part_of_a_group);
|
const groups_of_users = user_groups.get_user_groups_of_user(user_id_part_of_a_group);
|
||||||
assert.equal(groups_of_users.length, 1);
|
assert.equal(groups_of_users.length, 1);
|
||||||
assert.equal(groups_of_users[0].name, "Everyone");
|
assert.equal(groups_of_users[0].name, "Everyone");
|
||||||
|
|
|
@ -155,6 +155,7 @@ def build_page_params_for_home_page_load(
|
||||||
user_settings_object=True,
|
user_settings_object=True,
|
||||||
linkifier_url_template=True,
|
linkifier_url_template=True,
|
||||||
user_list_incomplete=True,
|
user_list_incomplete=True,
|
||||||
|
include_deactivated_groups=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if user_profile is not None:
|
if user_profile is not None:
|
||||||
|
|
Loading…
Reference in New Issue