[IMPROVE] Add delete-own-message permission (#4663)
This commit is contained in:
parent
64c17761e8
commit
c7b4a3d7f0
|
@ -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']
|
||||
|
|
|
@ -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> {
|
||||
|
|
Loading…
Reference in New Issue