[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[];
|
editMessagePermission?: string[];
|
||||||
deleteMessagePermission?: string[];
|
deleteMessagePermission?: string[];
|
||||||
forceDeleteMessagePermission?: string[];
|
forceDeleteMessagePermission?: string[];
|
||||||
|
deleteOwnMessagePermission?: string[];
|
||||||
pinMessagePermission?: string[];
|
pinMessagePermission?: string[];
|
||||||
createDirectMessagePermission?: string[];
|
createDirectMessagePermission?: string[];
|
||||||
}
|
}
|
||||||
|
@ -71,6 +72,7 @@ const MessageActions = React.memo(
|
||||||
editMessagePermission,
|
editMessagePermission,
|
||||||
deleteMessagePermission,
|
deleteMessagePermission,
|
||||||
forceDeleteMessagePermission,
|
forceDeleteMessagePermission,
|
||||||
|
deleteOwnMessagePermission,
|
||||||
pinMessagePermission,
|
pinMessagePermission,
|
||||||
createDirectMessagePermission
|
createDirectMessagePermission
|
||||||
},
|
},
|
||||||
|
@ -80,19 +82,27 @@ const MessageActions = React.memo(
|
||||||
hasEditPermission: false,
|
hasEditPermission: false,
|
||||||
hasDeletePermission: false,
|
hasDeletePermission: false,
|
||||||
hasForceDeletePermission: false,
|
hasForceDeletePermission: false,
|
||||||
hasPinPermission: false
|
hasPinPermission: false,
|
||||||
|
hasDeleteOwnPermission: false
|
||||||
};
|
};
|
||||||
const { showActionSheet, hideActionSheet } = useActionSheet();
|
const { showActionSheet, hideActionSheet } = useActionSheet();
|
||||||
|
|
||||||
const getPermissions = async () => {
|
const getPermissions = async () => {
|
||||||
try {
|
try {
|
||||||
const permission = [editMessagePermission, deleteMessagePermission, forceDeleteMessagePermission, pinMessagePermission];
|
const permission = [
|
||||||
|
editMessagePermission,
|
||||||
|
deleteMessagePermission,
|
||||||
|
forceDeleteMessagePermission,
|
||||||
|
pinMessagePermission,
|
||||||
|
deleteOwnMessagePermission
|
||||||
|
];
|
||||||
const result = await hasPermission(permission, room.rid);
|
const result = await hasPermission(permission, room.rid);
|
||||||
permissions = {
|
permissions = {
|
||||||
hasEditPermission: result[0],
|
hasEditPermission: result[0],
|
||||||
hasDeletePermission: result[1],
|
hasDeletePermission: result[1],
|
||||||
hasForceDeletePermission: result[2],
|
hasForceDeletePermission: result[2],
|
||||||
hasPinPermission: result[3]
|
hasPinPermission: result[3],
|
||||||
|
hasDeleteOwnPermission: result[4]
|
||||||
};
|
};
|
||||||
} catch {
|
} catch {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
@ -134,7 +144,7 @@ const MessageActions = React.memo(
|
||||||
if (tmid === message.id) {
|
if (tmid === message.id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const deleteOwn = isOwn(message);
|
const deleteOwn = isOwn(message) && permissions.hasDeleteOwnPermission;
|
||||||
if (!(permissions.hasDeletePermission || (Message_AllowDeleting && deleteOwn) || permissions.hasForceDeletePermission)) {
|
if (!(permissions.hasDeletePermission || (Message_AllowDeleting && deleteOwn) || permissions.hasForceDeletePermission)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -505,6 +515,7 @@ const mapStateToProps = (state: IApplicationState) => ({
|
||||||
isMasterDetail: state.app.isMasterDetail,
|
isMasterDetail: state.app.isMasterDetail,
|
||||||
editMessagePermission: state.permissions['edit-message'],
|
editMessagePermission: state.permissions['edit-message'],
|
||||||
deleteMessagePermission: state.permissions['delete-message'],
|
deleteMessagePermission: state.permissions['delete-message'],
|
||||||
|
deleteOwnMessagePermission: state.permissions['delete-own-message'],
|
||||||
forceDeleteMessagePermission: state.permissions['force-delete-message'],
|
forceDeleteMessagePermission: state.permissions['force-delete-message'],
|
||||||
pinMessagePermission: state.permissions['pin-message'],
|
pinMessagePermission: state.permissions['pin-message'],
|
||||||
createDirectMessagePermission: state.permissions['create-d']
|
createDirectMessagePermission: state.permissions['create-d']
|
||||||
|
|
|
@ -57,7 +57,8 @@ export const SUPPORTED_PERMISSIONS = [
|
||||||
'edit-omnichannel-contact',
|
'edit-omnichannel-contact',
|
||||||
'edit-livechat-room-customfields',
|
'edit-livechat-room-customfields',
|
||||||
'view-canned-responses',
|
'view-canned-responses',
|
||||||
'mobile-upload-file'
|
'mobile-upload-file',
|
||||||
|
'delete-own-message'
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export async function setPermissions(): Promise<void> {
|
export async function setPermissions(): Promise<void> {
|
||||||
|
|
Loading…
Reference in New Issue