From c7b4a3d7f066c1f79771f169f0708848847cfc1b Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Fri, 11 Nov 2022 14:28:41 -0300 Subject: [PATCH] [IMPROVE] Add delete-own-message permission (#4663) --- app/containers/MessageActions/index.tsx | 19 +++++++++++++++---- app/lib/methods/getPermissions.ts | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/containers/MessageActions/index.tsx b/app/containers/MessageActions/index.tsx index e19598341..a2ca5dc71 100644 --- a/app/containers/MessageActions/index.tsx +++ b/app/containers/MessageActions/index.tsx @@ -40,6 +40,7 @@ export interface IMessageActionsProps { editMessagePermission?: string[]; deleteMessagePermission?: string[]; forceDeleteMessagePermission?: string[]; + deleteOwnMessagePermission?: string[]; pinMessagePermission?: string[]; createDirectMessagePermission?: string[]; } @@ -71,6 +72,7 @@ const MessageActions = React.memo( editMessagePermission, deleteMessagePermission, forceDeleteMessagePermission, + deleteOwnMessagePermission, pinMessagePermission, createDirectMessagePermission }, @@ -80,19 +82,27 @@ const MessageActions = React.memo( hasEditPermission: false, hasDeletePermission: false, hasForceDeletePermission: false, - hasPinPermission: false + hasPinPermission: false, + hasDeleteOwnPermission: false }; const { showActionSheet, hideActionSheet } = useActionSheet(); const getPermissions = async () => { try { - const permission = [editMessagePermission, deleteMessagePermission, forceDeleteMessagePermission, pinMessagePermission]; + const permission = [ + editMessagePermission, + deleteMessagePermission, + forceDeleteMessagePermission, + pinMessagePermission, + deleteOwnMessagePermission + ]; const result = await hasPermission(permission, room.rid); permissions = { hasEditPermission: result[0], hasDeletePermission: result[1], hasForceDeletePermission: result[2], - hasPinPermission: result[3] + hasPinPermission: result[3], + hasDeleteOwnPermission: result[4] }; } catch { // Do nothing @@ -134,7 +144,7 @@ const MessageActions = React.memo( if (tmid === message.id) { return false; } - const deleteOwn = isOwn(message); + const deleteOwn = isOwn(message) && permissions.hasDeleteOwnPermission; if (!(permissions.hasDeletePermission || (Message_AllowDeleting && deleteOwn) || permissions.hasForceDeletePermission)) { return false; } @@ -505,6 +515,7 @@ const mapStateToProps = (state: IApplicationState) => ({ isMasterDetail: state.app.isMasterDetail, editMessagePermission: state.permissions['edit-message'], deleteMessagePermission: state.permissions['delete-message'], + deleteOwnMessagePermission: state.permissions['delete-own-message'], forceDeleteMessagePermission: state.permissions['force-delete-message'], pinMessagePermission: state.permissions['pin-message'], createDirectMessagePermission: state.permissions['create-d'] diff --git a/app/lib/methods/getPermissions.ts b/app/lib/methods/getPermissions.ts index 33fdc203b..a73146923 100644 --- a/app/lib/methods/getPermissions.ts +++ b/app/lib/methods/getPermissions.ts @@ -57,7 +57,8 @@ export const SUPPORTED_PERMISSIONS = [ 'edit-omnichannel-contact', 'edit-livechat-room-customfields', 'view-canned-responses', - 'mobile-upload-file' + 'mobile-upload-file', + 'delete-own-message' ] as const; export async function setPermissions(): Promise {