From fd1827f618d5c6760af8c8b3705775bf51c2a13e Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Tue, 12 Dec 2023 14:58:40 -0300 Subject: [PATCH] fix: hide the edit/delete action based on permission (#5393) * fix: hide the edit/delete item for not allowed or not own the message * fix e2e test --- app/containers/MessageActions/index.tsx | 22 +++++++++++++--------- e2e/tests/room/11-autoTranslate.spec.ts | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/containers/MessageActions/index.tsx b/app/containers/MessageActions/index.tsx index 1f90e772b..e67d029df 100644 --- a/app/containers/MessageActions/index.tsx +++ b/app/containers/MessageActions/index.tsx @@ -454,12 +454,13 @@ const MessageActions = React.memo( }); // Edit - if (!videoConfBlock) { + const isEditAllowed = allowEdit(message); + if (!videoConfBlock && (isOwn(message) || isEditAllowed)) { options.push({ title: I18n.t('Edit'), icon: 'edit', onPress: () => handleEdit(message), - enabled: allowEdit(message) + enabled: isEditAllowed }); } @@ -518,13 +519,16 @@ const MessageActions = React.memo( }); // Delete - options.push({ - title: I18n.t('Delete'), - icon: 'delete', - danger: true, - onPress: () => handleDelete(message), - enabled: allowDelete(message) - }); + const isDeleteAllowed = allowDelete(message); + if (isOwn(message) || isDeleteAllowed) { + options.push({ + title: I18n.t('Delete'), + icon: 'delete', + danger: true, + onPress: () => handleDelete(message), + enabled: isDeleteAllowed + }); + } return options; }; diff --git a/e2e/tests/room/11-autoTranslate.spec.ts b/e2e/tests/room/11-autoTranslate.spec.ts index b8fe76db4..df7ba928b 100644 --- a/e2e/tests/room/11-autoTranslate.spec.ts +++ b/e2e/tests/room/11-autoTranslate.spec.ts @@ -186,7 +186,7 @@ describe('Auto Translate', () => { await waitForVisible('action-sheet-handle'); await element(by.id('action-sheet-handle')).swipe('up', 'fast', 0.5); - await element(by[textMatcher]('Edit')).atIndex(0).swipe('up', 'fast', 0.5); + await element(by[textMatcher]('Get link')).atIndex(0).swipe('up', 'fast', 0.5); await waitForVisibleTextMatcher('View original', textMatcher); await element(by[textMatcher]('View original')).atIndex(0).tap();