From 89ea43c41086efe81ff1d868e783b7ab6208d59b Mon Sep 17 00:00:00 2001 From: megrogan Date: Fri, 22 Sep 2023 11:14:18 +0100 Subject: [PATCH 1/2] Disable mention_all permission til users upgraded --- .../home/GroupPermissionsEditor.svelte | 4 +-- .../home/GroupPermissionsViewer.svelte | 2 +- .../src/services/common/chatMappers.ts | 4 ++- .../src/services/group/candid/idl.d.ts | 2 ++ .../src/services/user/candid/idl.js | 1 - .../src/services/user/candid/types.d.ts | 1 - .../src/services/user/mappers.ts | 28 ++++++++++++++++++- 7 files changed, 35 insertions(+), 7 deletions(-) diff --git a/frontend/app/src/components/home/GroupPermissionsEditor.svelte b/frontend/app/src/components/home/GroupPermissionsEditor.svelte index 5a36277fd5..a7b18b44bc 100644 --- a/frontend/app/src/components/home/GroupPermissionsEditor.svelte +++ b/frontend/app/src/components/home/GroupPermissionsEditor.svelte @@ -51,7 +51,7 @@ {roles} label={$_("permissions.replyInThread")} bind:rolePermission={permissions.replyInThread} /> - + bind:rolePermission={permissions.mentionAllMembers} /> --> diff --git a/frontend/app/src/components/home/GroupPermissionsViewer.svelte b/frontend/app/src/components/home/GroupPermissionsViewer.svelte index 1f4a4db8ac..26df44699a 100644 --- a/frontend/app/src/components/home/GroupPermissionsViewer.svelte +++ b/frontend/app/src/components/home/GroupPermissionsViewer.svelte @@ -20,7 +20,7 @@ $: partitioned = partitionPermissions(permissions); function filterPermissions([key, _]: PermissionsEntry): boolean { - if (isPublic && key === "inviteUsers") { + if ((isPublic && key === "inviteUsers") || key === "mentionAllMembers") { return false; } return true; diff --git a/frontend/openchat-agent/src/services/common/chatMappers.ts b/frontend/openchat-agent/src/services/common/chatMappers.ts index e5924e2373..2b23231072 100644 --- a/frontend/openchat-agent/src/services/common/chatMappers.ts +++ b/frontend/openchat-agent/src/services/common/chatMappers.ts @@ -29,7 +29,6 @@ import type { ApiPollVotes, ApiTotalPollVotes, ApiPollConfig, - ApiGroupPermissions, ApiPermissionRole, ApiGiphyContent, ApiGiphyImageVariant, @@ -62,6 +61,9 @@ import type { ApiLeaveGroupResponse, ApiChat, } from "../user/candid/idl"; +import type { + ApiGroupPermissions, +} from "../group/candid/idl"; import type { Message, ThreadSummary, diff --git a/frontend/openchat-agent/src/services/group/candid/idl.d.ts b/frontend/openchat-agent/src/services/group/candid/idl.d.ts index fb0936fa15..6395842f98 100644 --- a/frontend/openchat-agent/src/services/group/candid/idl.d.ts +++ b/frontend/openchat-agent/src/services/group/candid/idl.d.ts @@ -65,6 +65,7 @@ import { AccessGateUpdate, DeclineInvitationResponse, ConvertIntoCommunityResponse, + GroupPermissions, } from "./types"; export { _SERVICE as GroupService, @@ -132,6 +133,7 @@ export { AccessGateUpdate as ApiGroupGateUpdate, DeclineInvitationResponse as ApiDeclineInvitationResponse, ConvertIntoCommunityResponse as ApiConvertIntoCommunityResponse, + GroupPermissions as ApiGroupPermissions, }; export const idlFactory: IDL.InterfaceFactory; diff --git a/frontend/openchat-agent/src/services/user/candid/idl.js b/frontend/openchat-agent/src/services/user/candid/idl.js index f964f5228d..790149a81c 100644 --- a/frontend/openchat-agent/src/services/user/candid/idl.js +++ b/frontend/openchat-agent/src/services/user/candid/idl.js @@ -147,7 +147,6 @@ export const idlFactory = ({ IDL }) => { }); const GroupPermissions = IDL.Record({ 'block_users' : PermissionRole, - 'mention_all_members' : PermissionRole, 'change_permissions' : PermissionRole, 'delete_messages' : PermissionRole, 'send_messages' : PermissionRole, diff --git a/frontend/openchat-agent/src/services/user/candid/types.d.ts b/frontend/openchat-agent/src/services/user/candid/types.d.ts index b3dae93880..acf2e0db22 100644 --- a/frontend/openchat-agent/src/services/user/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/user/candid/types.d.ts @@ -846,7 +846,6 @@ export interface GroupNameChanged { } export interface GroupPermissions { 'block_users' : PermissionRole, - 'mention_all_members' : PermissionRole, 'change_permissions' : PermissionRole, 'delete_messages' : PermissionRole, 'send_messages' : PermissionRole, diff --git a/frontend/openchat-agent/src/services/user/mappers.ts b/frontend/openchat-agent/src/services/user/mappers.ts index 45dd348fc2..1d879d77c8 100644 --- a/frontend/openchat-agent/src/services/user/mappers.ts +++ b/frontend/openchat-agent/src/services/user/mappers.ts @@ -57,6 +57,8 @@ import type { ApiDeleteCommunityResponse, ApiArchiveUnarchiveChatsResponse, ApiSendMessageWithTransferToChannelResponse, + ApiGroupPermissions, + ApiPermissionRole, } from "./candid/idl"; import type { EventsResponse, @@ -112,6 +114,8 @@ import type { ManageFavouritesResponse, LeaveCommunityResponse, DeleteCommunityResponse, + ChatPermissions, + PermissionRole, } from "openchat-shared"; import { nullMembership, CommonResponses, UnsupportedValueError } from "openchat-shared"; import { @@ -126,7 +130,6 @@ import { chatMetrics, completedCryptoTransfer, accessGate, - groupPermissions, message, messageContent, } from "../common/chatMappers"; @@ -799,6 +802,29 @@ function groupChatSummary(candid: ApiGroupChatSummary): GroupChatSummary { }; } +function groupPermissions(candid: ApiGroupPermissions): ChatPermissions { + return { + changeRoles: permissionRole(candid.change_roles), + updateGroup: permissionRole(candid.update_group), + inviteUsers: permissionRole(candid.invite_users), + removeMembers: permissionRole(candid.remove_members), + deleteMessages: permissionRole(candid.delete_messages), + pinMessages: permissionRole(candid.pin_messages), + createPolls: permissionRole(candid.create_polls), + sendMessages: permissionRole(candid.send_messages), + reactToMessages: permissionRole(candid.react_to_messages), + replyInThread: permissionRole(candid.reply_in_thread), + mentionAllMembers: "admin" + }; +} + +function permissionRole(candid: ApiPermissionRole): PermissionRole { + if ("Owner" in candid) return "owner"; + if ("Admins" in candid) return "admin"; + if ("Moderators" in candid) return "moderator"; + return "member"; +} + function threadSyncDetails(candid: ApiThreadSyncDetails): ThreadSyncDetails { return { threadRootMessageIndex: candid.root_message_index, From f6f00d173fb7fa3f98dfae4567285d8e874db2e2 Mon Sep 17 00:00:00 2001 From: megrogan Date: Fri, 22 Sep 2023 11:33:48 +0100 Subject: [PATCH 2/2] Fix --- .../src/services/common/chatMappers.ts | 21 +++++++++++-- .../src/services/group/candid/idl.d.ts | 2 -- .../src/services/user/candid/idl.d.ts | 2 ++ .../src/services/user/candid/idl.js | 18 ++++++++++- .../src/services/user/candid/types.d.ts | 18 ++++++++++- .../src/services/user/mappers.ts | 30 ++----------------- 6 files changed, 56 insertions(+), 35 deletions(-) diff --git a/frontend/openchat-agent/src/services/common/chatMappers.ts b/frontend/openchat-agent/src/services/common/chatMappers.ts index 2b23231072..2b01e9b844 100644 --- a/frontend/openchat-agent/src/services/common/chatMappers.ts +++ b/frontend/openchat-agent/src/services/common/chatMappers.ts @@ -29,6 +29,8 @@ import type { ApiPollVotes, ApiTotalPollVotes, ApiPollConfig, + ApiGroupPermissions, + ApiGroupPermissionsReduced, ApiPermissionRole, ApiGiphyContent, ApiGiphyImageVariant, @@ -61,9 +63,6 @@ import type { ApiLeaveGroupResponse, ApiChat, } from "../user/candid/idl"; -import type { - ApiGroupPermissions, -} from "../group/candid/idl"; import type { Message, ThreadSummary, @@ -839,6 +838,22 @@ export function groupPermissions(candid: ApiGroupPermissions): ChatPermissions { }; } +export function groupPermissionsReduced(candid: ApiGroupPermissionsReduced): ChatPermissions { + return { + changeRoles: permissionRole(candid.change_roles), + updateGroup: permissionRole(candid.update_group), + inviteUsers: permissionRole(candid.invite_users), + removeMembers: permissionRole(candid.remove_members), + deleteMessages: permissionRole(candid.delete_messages), + pinMessages: permissionRole(candid.pin_messages), + createPolls: permissionRole(candid.create_polls), + sendMessages: permissionRole(candid.send_messages), + reactToMessages: permissionRole(candid.react_to_messages), + replyInThread: permissionRole(candid.reply_in_thread), + mentionAllMembers: "admin", + }; +} + export function communityPermissions(candid: ApiCommunityPermissions): CommunityPermissions { return { changeRoles: communityPermissionRole(candid.change_roles), diff --git a/frontend/openchat-agent/src/services/group/candid/idl.d.ts b/frontend/openchat-agent/src/services/group/candid/idl.d.ts index 6395842f98..fb0936fa15 100644 --- a/frontend/openchat-agent/src/services/group/candid/idl.d.ts +++ b/frontend/openchat-agent/src/services/group/candid/idl.d.ts @@ -65,7 +65,6 @@ import { AccessGateUpdate, DeclineInvitationResponse, ConvertIntoCommunityResponse, - GroupPermissions, } from "./types"; export { _SERVICE as GroupService, @@ -133,7 +132,6 @@ export { AccessGateUpdate as ApiGroupGateUpdate, DeclineInvitationResponse as ApiDeclineInvitationResponse, ConvertIntoCommunityResponse as ApiConvertIntoCommunityResponse, - GroupPermissions as ApiGroupPermissions, }; export const idlFactory: IDL.InterfaceFactory; diff --git a/frontend/openchat-agent/src/services/user/candid/idl.d.ts b/frontend/openchat-agent/src/services/user/candid/idl.d.ts index 8ac140d45c..8440a50896 100644 --- a/frontend/openchat-agent/src/services/user/candid/idl.d.ts +++ b/frontend/openchat-agent/src/services/user/candid/idl.d.ts @@ -135,6 +135,7 @@ import { DeleteCommunityResponse, ArchiveUnarchiveChatsResponse, SetCommunityIndexesResponse, + GroupPermissionsReduced } from "./types"; export { _SERVICE as UserService, @@ -272,6 +273,7 @@ export { DeleteCommunityResponse as ApiDeleteCommunityResponse, ArchiveUnarchiveChatsResponse as ApiArchiveUnarchiveChatsResponse, SetCommunityIndexesResponse as ApiSetCommunityIndexesResponse, + GroupPermissionsReduced as ApiGroupPermissionsReduced, }; export const idlFactory: IDL.InterfaceFactory; diff --git a/frontend/openchat-agent/src/services/user/candid/idl.js b/frontend/openchat-agent/src/services/user/candid/idl.js index 790149a81c..5ba7d6c797 100644 --- a/frontend/openchat-agent/src/services/user/candid/idl.js +++ b/frontend/openchat-agent/src/services/user/candid/idl.js @@ -146,6 +146,22 @@ export const idlFactory = ({ IDL }) => { 'Members' : IDL.Null, }); const GroupPermissions = IDL.Record({ + 'block_users' : PermissionRole, + 'mention_all_members' : PermissionRole, + 'change_permissions' : PermissionRole, + 'delete_messages' : PermissionRole, + 'send_messages' : PermissionRole, + 'remove_members' : PermissionRole, + 'update_group' : PermissionRole, + 'invite_users' : PermissionRole, + 'change_roles' : PermissionRole, + 'add_members' : PermissionRole, + 'create_polls' : PermissionRole, + 'pin_messages' : PermissionRole, + 'reply_in_thread' : PermissionRole, + 'react_to_messages' : PermissionRole, + }); + const GroupPermissionsReduced = IDL.Record({ 'block_users' : PermissionRole, 'change_permissions' : PermissionRole, 'delete_messages' : PermissionRole, @@ -868,7 +884,7 @@ export const idlFactory = ({ IDL }) => { }); const GroupChatSummary = IDL.Record({ 'is_public' : IDL.Bool, - 'permissions' : GroupPermissions, + 'permissions' : GroupPermissionsReduced, 'metrics' : ChatMetrics, 'subtype' : IDL.Opt(GroupSubtype), 'date_last_pinned' : IDL.Opt(TimestampMillis), diff --git a/frontend/openchat-agent/src/services/user/candid/types.d.ts b/frontend/openchat-agent/src/services/user/candid/types.d.ts index acf2e0db22..c617c8e789 100644 --- a/frontend/openchat-agent/src/services/user/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/user/candid/types.d.ts @@ -755,7 +755,7 @@ export interface GroupChatCreated { } export interface GroupChatSummary { 'is_public' : boolean, - 'permissions' : GroupPermissions, + 'permissions' : GroupPermissionsReduced, 'metrics' : ChatMetrics, 'subtype' : [] | [GroupSubtype], 'date_last_pinned' : [] | [TimestampMillis], @@ -845,6 +845,22 @@ export interface GroupNameChanged { 'previous_name' : string, } export interface GroupPermissions { + 'block_users' : PermissionRole, + 'mention_all_members' : PermissionRole, + 'change_permissions' : PermissionRole, + 'delete_messages' : PermissionRole, + 'send_messages' : PermissionRole, + 'remove_members' : PermissionRole, + 'update_group' : PermissionRole, + 'invite_users' : PermissionRole, + 'change_roles' : PermissionRole, + 'add_members' : PermissionRole, + 'create_polls' : PermissionRole, + 'pin_messages' : PermissionRole, + 'reply_in_thread' : PermissionRole, + 'react_to_messages' : PermissionRole, +} +export interface GroupPermissionsReduced { 'block_users' : PermissionRole, 'change_permissions' : PermissionRole, 'delete_messages' : PermissionRole, diff --git a/frontend/openchat-agent/src/services/user/mappers.ts b/frontend/openchat-agent/src/services/user/mappers.ts index 1d879d77c8..3ca4fa1adf 100644 --- a/frontend/openchat-agent/src/services/user/mappers.ts +++ b/frontend/openchat-agent/src/services/user/mappers.ts @@ -57,8 +57,6 @@ import type { ApiDeleteCommunityResponse, ApiArchiveUnarchiveChatsResponse, ApiSendMessageWithTransferToChannelResponse, - ApiGroupPermissions, - ApiPermissionRole, } from "./candid/idl"; import type { EventsResponse, @@ -114,8 +112,6 @@ import type { ManageFavouritesResponse, LeaveCommunityResponse, DeleteCommunityResponse, - ChatPermissions, - PermissionRole, } from "openchat-shared"; import { nullMembership, CommonResponses, UnsupportedValueError } from "openchat-shared"; import { @@ -132,6 +128,7 @@ import { accessGate, message, messageContent, + groupPermissionsReduced, } from "../common/chatMappers"; import { ensureReplicaIsUpToDate } from "../common/replicaUpToDateChecker"; import { ReplicaNotUpToDateError } from "../error"; @@ -777,7 +774,7 @@ function groupChatSummary(candid: ApiGroupChatSummary): GroupChatSummary { canisterId: candid.chat_id.toString(), })), memberCount: candid.participant_count, - permissions: groupPermissions(candid.permissions), + permissions: groupPermissionsReduced(candid.permissions), metrics: chatMetrics(candid.metrics), subtype: optional(candid.subtype, apiGroupSubtype), previewed: false, @@ -802,29 +799,6 @@ function groupChatSummary(candid: ApiGroupChatSummary): GroupChatSummary { }; } -function groupPermissions(candid: ApiGroupPermissions): ChatPermissions { - return { - changeRoles: permissionRole(candid.change_roles), - updateGroup: permissionRole(candid.update_group), - inviteUsers: permissionRole(candid.invite_users), - removeMembers: permissionRole(candid.remove_members), - deleteMessages: permissionRole(candid.delete_messages), - pinMessages: permissionRole(candid.pin_messages), - createPolls: permissionRole(candid.create_polls), - sendMessages: permissionRole(candid.send_messages), - reactToMessages: permissionRole(candid.react_to_messages), - replyInThread: permissionRole(candid.reply_in_thread), - mentionAllMembers: "admin" - }; -} - -function permissionRole(candid: ApiPermissionRole): PermissionRole { - if ("Owner" in candid) return "owner"; - if ("Admins" in candid) return "admin"; - if ("Moderators" in candid) return "moderator"; - return "member"; -} - function threadSyncDetails(candid: ApiThreadSyncDetails): ThreadSyncDetails { return { threadRootMessageIndex: candid.root_message_index,