user_groups: Add can_manage_group field to user_group object.

This commit adds can_manage_group field in user_group
object in frontend and also adds code to update the field
value from server events.
This commit is contained in:
Ujjawal Modi 2023-08-04 19:15:37 +05:30 committed by Tim Abbott
parent 5d613ce98d
commit 20229d0d3d
5 changed files with 15 additions and 0 deletions

View File

@ -133,6 +133,7 @@ export const user_group_schema = z.object({
members: z.array(z.number()),
is_system_group: z.boolean(),
direct_subgroup_ids: z.array(z.number()),
can_manage_group: z.number(),
can_mention_group: z.number(),
});

View File

@ -12,6 +12,7 @@ export type UserGroupUpdateEvent = {
data: {
name?: string;
description?: string;
can_manage_group?: number;
can_mention_group?: number;
};
};

View File

@ -48,6 +48,7 @@ export function add(user_group_raw: UserGroupRaw): void {
members: new Set(user_group_raw.members),
is_system_group: user_group_raw.is_system_group,
direct_subgroup_ids: new Set(user_group_raw.direct_subgroup_ids),
can_manage_group: user_group_raw.can_manage_group,
can_mention_group: user_group_raw.can_mention_group,
};
@ -90,6 +91,12 @@ export function update(event: UserGroupUpdateEvent): void {
user_group_name_dict.delete(group.name);
user_group_name_dict.set(group.name, group);
}
if (event.data.can_manage_group !== undefined) {
group.can_manage_group = event.data.can_manage_group;
user_group_name_dict.delete(group.name);
user_group_name_dict.set(group.name, group);
}
}
export function get_user_group_from_name(name: string): UserGroup | undefined {

View File

@ -428,6 +428,7 @@ const hamletcharacters = user_group_item({
members: new Set([100, 104]),
is_system_group: false,
direct_subgroup_ids: new Set([]),
can_manage_group: 2,
can_mention_group: 2,
});
@ -438,6 +439,7 @@ const backend = user_group_item({
members: new Set([101]),
is_system_group: false,
direct_subgroup_ids: new Set([1]),
can_manage_group: 1,
can_mention_group: 1,
});
@ -448,6 +450,7 @@ const call_center = user_group_item({
members: new Set([102]),
is_system_group: false,
direct_subgroup_ids: new Set([]),
can_manage_group: 2,
can_mention_group: 2,
});

View File

@ -17,6 +17,7 @@ run_test("user_groups", () => {
members: new Set([1, 2]),
is_system_group: false,
direct_subgroup_ids: new Set([4, 5]),
can_manage_group: 1,
can_mention_group: 2,
};
@ -35,6 +36,7 @@ run_test("user_groups", () => {
members: new Set([3]),
is_system_group: false,
direct_subgroup_ids: new Set([]),
can_manage_group: 1,
can_mention_group: 2,
};
const all = {
@ -43,6 +45,7 @@ run_test("user_groups", () => {
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,
};