From 20229d0d3d2b05e36fcf38894cd33b273e459890 Mon Sep 17 00:00:00 2001 From: Ujjawal Modi Date: Fri, 4 Aug 2023 19:15:37 +0530 Subject: [PATCH] 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. --- web/src/state_data.ts | 1 + web/src/types.ts | 1 + web/src/user_groups.ts | 7 +++++++ web/tests/composebox_typeahead.test.js | 3 +++ web/tests/user_groups.test.js | 3 +++ 5 files changed, 15 insertions(+) diff --git a/web/src/state_data.ts b/web/src/state_data.ts index ac95c3c8b6..af90a2a461 100644 --- a/web/src/state_data.ts +++ b/web/src/state_data.ts @@ -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(), }); diff --git a/web/src/types.ts b/web/src/types.ts index 9a16d8b135..3510f879a5 100644 --- a/web/src/types.ts +++ b/web/src/types.ts @@ -12,6 +12,7 @@ export type UserGroupUpdateEvent = { data: { name?: string; description?: string; + can_manage_group?: number; can_mention_group?: number; }; }; diff --git a/web/src/user_groups.ts b/web/src/user_groups.ts index aca722584d..41b9b3d72c 100644 --- a/web/src/user_groups.ts +++ b/web/src/user_groups.ts @@ -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 { diff --git a/web/tests/composebox_typeahead.test.js b/web/tests/composebox_typeahead.test.js index c8e85548d0..925c38abad 100644 --- a/web/tests/composebox_typeahead.test.js +++ b/web/tests/composebox_typeahead.test.js @@ -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, }); diff --git a/web/tests/user_groups.test.js b/web/tests/user_groups.test.js index 9c4d7949a8..23f02af722 100644 --- a/web/tests/user_groups.test.js +++ b/web/tests/user_groups.test.js @@ -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, };