[IMPROVE] Add delete-own-message permission (#4663)

This commit is contained in:
Reinaldo Neto 2022-11-11 14:28:41 -03:00 committed by GitHub
parent 316bc80876
commit 251cc9843b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -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']

View File

@ -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<void> {