From 52832807b9c5198c269f77fcdfc2eb09c38e0287 Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Wed, 5 Jul 2023 21:54:45 +0200 Subject: [PATCH] Revert "Remove all uses of `actorEmail` as part of personalDetails migration" --- src/libs/E2E/apiMocks/openReport.js | 1 + src/libs/ReportActionsUtils.js | 2 +- src/libs/ReportUtils.js | 19 +++++++++++++------ src/libs/actions/Task.js | 18 +++++------------- .../report/ContextMenu/ContextMenuActions.js | 2 +- .../home/report/ReportActionItemSingle.js | 4 ++-- src/pages/tasks/NewTaskPage.js | 19 ++++++++++++++++++- tests/actions/IOUTest.js | 2 ++ tests/actions/ReportTest.js | 3 +++ tests/ui/UnreadIndicatorsTest.js | 19 ++++++++++--------- tests/utils/TestHelper.js | 4 +++- 11 files changed, 59 insertions(+), 34 deletions(-) diff --git a/src/libs/E2E/apiMocks/openReport.js b/src/libs/E2E/apiMocks/openReport.js index 8ad00627b52a..3eb9c7890299 100644 --- a/src/libs/E2E/apiMocks/openReport.js +++ b/src/libs/E2E/apiMocks/openReport.js @@ -67,6 +67,7 @@ export default () => ({ text: '123 Ios', }, ], + actorEmail: 'fake3@gmail.com', actorAccountID: 10773236, message: [ { diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 9a280711e947..86096b300c12 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -266,7 +266,7 @@ function isConsecutiveActionMadeByPreviousActor(reportActions, actionIndex) { return false; } - return currentAction.actorAccountID === previousAction.actorAccountID; + return currentAction.actorEmail === previousAction.actorEmail; } /** diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 9bd942e65b85..1631b71d6049 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -199,7 +199,7 @@ function sortReportsByLastRead(reports) { */ function canEditReportAction(reportAction) { return ( - reportAction.actorAccountID === currentUserAccountID && + reportAction.actorEmail === currentUserEmail && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !isReportMessageAttachment(lodashGet(reportAction, ['message', 0], {})) && !ReportActionsUtils.isDeletedAction(reportAction) && @@ -235,7 +235,7 @@ function canDeleteReportAction(reportAction, reportID) { ) { return false; } - if (reportAction.actorAccountID === currentUserAccountID) { + if (reportAction.actorEmail === currentUserEmail) { return true; } const report = lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {}); @@ -732,12 +732,12 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false, if (isChatThread(report)) { const parentReportAction = ReportActionsUtils.getParentReportAction(report); - const actorAccountID = lodashGet(parentReportAction, 'actorAccountID', 0); - const actorDisplayName = lodashGet(allPersonalDetails, [actorAccountID, 'displayName'], ''); + const actorEmail = lodashGet(parentReportAction, 'actorEmail', ''); + const actorAccountID = lodashGet(parentReportAction, 'actorAccountID', ''); const actorIcon = { id: actorAccountID, source: UserUtils.getAvatar(lodashGet(personalDetails, [actorAccountID, 'avatar']), actorAccountID), - name: actorDisplayName, + name: actorEmail, type: CONST.ICON_TYPE_AVATAR, }; @@ -1222,6 +1222,7 @@ function buildOptimisticAddCommentReportAction(text, file) { reportAction: { reportActionID: NumberUtils.rand64(), actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, + actorEmail: currentUserEmail, actorAccountID: currentUserAccountID, person: [ { @@ -1454,6 +1455,7 @@ function buildOptimisticIOUReportAction(type, amount, currency, comment, partici return { actionName: CONST.REPORT.ACTIONS.TYPE.IOU, actorAccountID: currentUserAccountID, + actorEmail: currentUserEmail, automatic: false, avatar: lodashGet(currentUserPersonalDetails, 'avatar', UserUtils.getDefaultAvatar(currentUserAccountID)), isAttachment: false, @@ -1492,6 +1494,7 @@ function buildOptimisticReportPreview(reportID, iouReportID, payeeAccountID) { originalMessage: { linkedReportID: iouReportID, }, + actorEmail: currentUserEmail, actorAccountID: currentUserAccountID, }; } @@ -1506,6 +1509,7 @@ function buildOptimisticTaskReportAction(taskReportID, actionName, message = '') return { actionName, actorAccountID: currentUserAccountID, + actorEmail: currentUserEmail, automatic: false, avatar: lodashGet(currentUserPersonalDetails, 'avatar', UserUtils.getDefaultAvatar(currentUserAccountID)), isAttachment: false, @@ -1604,6 +1608,7 @@ function buildOptimisticCreatedReportAction(ownerEmail) { actionName: CONST.REPORT.ACTIONS.TYPE.CREATED, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, actorAccountID: currentUserAccountID, + actorEmail: currentUserEmail, message: [ { type: CONST.REPORT.MESSAGE.TYPE.TEXT, @@ -1643,6 +1648,7 @@ function buildOptimisticEditedTaskReportAction(ownerEmail) { actionName: CONST.REPORT.ACTIONS.TYPE.TASKEDITED, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, actorAccountID: currentUserAccountID, + actorEmail: currentUserEmail, message: [ { type: CONST.REPORT.MESSAGE.TYPE.TEXT, @@ -1807,6 +1813,7 @@ function buildOptimisticTaskReport(ownerEmail, ownerAccountID, assigneeAccountID description, ownerEmail, ownerAccountID, + // managerEmail: assignee, managerID: assigneeAccountID, type: CONST.REPORT.TYPE.TASK, parentReportID, @@ -2129,7 +2136,7 @@ function shouldShowFlagComment(reportAction, report) { !isArchivedRoom(report) && !chatIncludesChronos(report) && !isConciergeChatReport(report.reportID) && - reportAction.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE + reportAction.actorEmail !== CONST.EMAIL.CONCIERGE ); } diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 610315b63e84..3d19a632a634 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -13,16 +13,6 @@ import * as UserUtils from '../UserUtils'; import * as PersonalDetailsUtils from '../PersonalDetailsUtils'; import * as ReportActionsUtils from '../ReportActionsUtils'; -let currentUserEmail; -let currentUserAccountID; -Onyx.connect({ - key: ONYXKEYS.SESSION, - callback: (val) => { - currentUserEmail = lodashGet(val, 'email', ''); - currentUserAccountID = lodashGet(val, 'accountID', 0); - }, -}); - /** * Clears out the task info from the store */ @@ -34,6 +24,8 @@ function clearOutTaskInfo() { * Assign a task to a user * Function title is createTask for consistency with the rest of the actions * and also because we can create a task without assigning it to anyone + * @param {String} currentUserEmail + * @param {Number} currentUserAccountID * @param {String} parentReportID * @param {String} title * @param {String} description @@ -42,7 +34,7 @@ function clearOutTaskInfo() { * */ -function createTaskAndNavigate(parentReportID, title, description, assignee, assigneeAccountID = 0) { +function createTaskAndNavigate(currentUserEmail, currentUserAccountID, parentReportID, title, description, assignee, assigneeAccountID = 0) { // Create the task report const optimisticTaskReport = ReportUtils.buildOptimisticTaskReport(currentUserEmail, currentUserAccountID, assigneeAccountID, parentReportID, title, description); @@ -259,7 +251,7 @@ function reopenTask(taskReportID, taskTitle) { statusNum: CONST.REPORT.STATUS.OPEN, lastVisibleActionCreated: reopenedTaskReportAction.created, lastMessageText: message, - lastActorEmail: currentUserEmail, + lastActorEmail: reopenedTaskReportAction.actorEmail, lastActorAccountID: reopenedTaskReportAction.actorAccountID, lastReadTime: reopenedTaskReportAction.created, }, @@ -594,7 +586,7 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum value: { lastVisibleActionCreated: optimisticCancelReportAction.created, lastMessageText: message, - lastActorEmail: currentUserEmail, + lastActorEmail: optimisticCancelReportAction.actorEmail, lastActorAccountID: optimisticCancelReportAction.actorAccountID, }, }, diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 4b7ddaec1f99..b05c29804d19 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -325,7 +325,7 @@ export default [ !isArchivedRoom && !isChronosReport && !ReportUtils.isConciergeChatReport(reportID) && - reportAction.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE, + reportAction.actorEmail !== CONST.EMAIL.CONCIERGE, onPress: (closePopover, {reportID, reportAction}) => { if (closePopover) { hideContextMenu(false, () => Navigation.navigate(ROUTES.getFlagCommentRoute(reportID, reportAction.reportActionID))); diff --git a/src/pages/home/report/ReportActionItemSingle.js b/src/pages/home/report/ReportActionItemSingle.js index 79f6e336604a..0fc8b1c72326 100644 --- a/src/pages/home/report/ReportActionItemSingle.js +++ b/src/pages/home/report/ReportActionItemSingle.js @@ -73,8 +73,8 @@ const showWorkspaceDetails = (reportID) => { function ReportActionItemSingle(props) { const actorAccountID = props.action.actorAccountID; let {displayName} = props.personalDetailsList[actorAccountID] || {}; - const {avatar, login, pendingFields} = props.personalDetailsList[actorAccountID] || {}; - let actorHint = (login || displayName).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''); + const {avatar, pendingFields} = props.personalDetailsList[actorAccountID] || {}; + let actorHint = lodashGet(props.action, 'actorEmail', '').replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''); const isWorkspaceActor = ReportUtils.isPolicyExpenseChat(props.report) && !actorAccountID; let avatarSource = UserUtils.getAvatar(avatar, actorAccountID); diff --git a/src/pages/tasks/NewTaskPage.js b/src/pages/tasks/NewTaskPage.js index 9d3ea9a9ac04..f69ac83a89ff 100644 --- a/src/pages/tasks/NewTaskPage.js +++ b/src/pages/tasks/NewTaskPage.js @@ -49,6 +49,11 @@ const propTypes = { }), ), + /** Current user session */ + session: PropTypes.shape({ + email: PropTypes.string.isRequired, + }), + /** All reports shared with the user */ reports: PropTypes.objectOf(reportPropTypes), @@ -60,6 +65,7 @@ const defaultProps = { task: {}, personalDetails: {}, reports: {}, + session: {}, }; function NewTaskPage(props) { @@ -118,7 +124,15 @@ function NewTaskPage(props) { return; } - TaskUtils.createTaskAndNavigate(parentReport.reportID, props.task.title, props.task.description, props.task.assignee, props.task.assigneeAccountID); + TaskUtils.createTaskAndNavigate( + props.session.email, + props.session.accountID, + parentReport.reportID, + props.task.title, + props.task.description, + props.task.assignee, + props.task.assigneeAccountID, + ); } if (!Permissions.canUseTasks(props.betas)) { @@ -203,6 +217,9 @@ export default compose( personalDetails: { key: ONYXKEYS.PERSONAL_DETAILS_LIST, }, + session: { + key: ONYXKEYS.SESSION, + }, }), withLocalize, )(NewTaskPage); diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index b9e30d1b0831..112377f373d5 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -372,6 +372,7 @@ describe('actions/IOU', () => { const iouAction = { reportActionID: NumberUtils.rand64(), actionName: CONST.REPORT.ACTIONS.TYPE.IOU, + actorEmail: RORY_EMAIL, actorAccountID: RORY_ACCOUNT_ID, created: DateUtils.getDBTime(), originalMessage: { @@ -834,6 +835,7 @@ describe('actions/IOU', () => { const julesExistingIOUAction = { reportActionID: NumberUtils.rand64(), actionName: CONST.REPORT.ACTIONS.TYPE.IOU, + actorEmail: RORY_EMAIL, actorAccountID: RORY_ACCOUNT_ID, created: DateUtils.getDBTime(), originalMessage: { diff --git a/tests/actions/ReportTest.js b/tests/actions/ReportTest.js index 5566c66df4b7..5ebffff507b8 100644 --- a/tests/actions/ReportTest.js +++ b/tests/actions/ReportTest.js @@ -47,6 +47,7 @@ describe('actions/Report', () => { const REPORT_ACTION = { actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, actorAccountID: TEST_USER_ACCOUNT_ID, + actorEmail: TEST_USER_LOGIN, automatic: false, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png', message: [{type: 'COMMENT', html: 'Testing a comment', text: 'Testing a comment'}], @@ -229,6 +230,7 @@ describe('actions/Report', () => { 1: { actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, actorAccountID: USER_2_ACCOUNT_ID, + actorEmail: USER_2_LOGIN, automatic: false, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png', message: [{type: 'COMMENT', html: 'Comment 1', text: 'Comment 1'}], @@ -314,6 +316,7 @@ describe('actions/Report', () => { const USER_1_BASE_ACTION = { actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, actorAccountID: USER_1_ACCOUNT_ID, + actorEmail: USER_1_LOGIN, automatic: false, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png', person: [{type: 'TEXT', style: 'strong', text: 'Test User'}], diff --git a/tests/ui/UnreadIndicatorsTest.js b/tests/ui/UnreadIndicatorsTest.js index 6ddd5a86e4b2..ae19d9db74ae 100644 --- a/tests/ui/UnreadIndicatorsTest.js +++ b/tests/ui/UnreadIndicatorsTest.js @@ -176,15 +176,15 @@ function signInAndGetAppWithUnreadChat() { }, ], }, - 1: TestHelper.buildTestReportComment(MOMENT_TEN_MINUTES_AGO.clone().add(10, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '1'), - 2: TestHelper.buildTestReportComment(MOMENT_TEN_MINUTES_AGO.clone().add(20, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '2'), - 3: TestHelper.buildTestReportComment(reportAction3CreatedDate, USER_B_ACCOUNT_ID, '3'), - 4: TestHelper.buildTestReportComment(MOMENT_TEN_MINUTES_AGO.clone().add(40, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '4'), - 5: TestHelper.buildTestReportComment(MOMENT_TEN_MINUTES_AGO.clone().add(50, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '5'), - 6: TestHelper.buildTestReportComment(MOMENT_TEN_MINUTES_AGO.clone().add(60, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '6'), - 7: TestHelper.buildTestReportComment(MOMENT_TEN_MINUTES_AGO.clone().add(70, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '7'), - 8: TestHelper.buildTestReportComment(MOMENT_TEN_MINUTES_AGO.clone().add(80, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '8'), - 9: TestHelper.buildTestReportComment(reportAction9CreatedDate, USER_B_ACCOUNT_ID, '9'), + 1: TestHelper.buildTestReportComment(USER_B_EMAIL, MOMENT_TEN_MINUTES_AGO.clone().add(10, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '1'), + 2: TestHelper.buildTestReportComment(USER_B_EMAIL, MOMENT_TEN_MINUTES_AGO.clone().add(20, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '2'), + 3: TestHelper.buildTestReportComment(USER_B_EMAIL, reportAction3CreatedDate, USER_B_ACCOUNT_ID, '3'), + 4: TestHelper.buildTestReportComment(USER_B_EMAIL, MOMENT_TEN_MINUTES_AGO.clone().add(40, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '4'), + 5: TestHelper.buildTestReportComment(USER_B_EMAIL, MOMENT_TEN_MINUTES_AGO.clone().add(50, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '5'), + 6: TestHelper.buildTestReportComment(USER_B_EMAIL, MOMENT_TEN_MINUTES_AGO.clone().add(60, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '6'), + 7: TestHelper.buildTestReportComment(USER_B_EMAIL, MOMENT_TEN_MINUTES_AGO.clone().add(70, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '7'), + 8: TestHelper.buildTestReportComment(USER_B_EMAIL, MOMENT_TEN_MINUTES_AGO.clone().add(80, 'seconds').format(MOMENT_FORMAT), USER_B_ACCOUNT_ID, '8'), + 9: TestHelper.buildTestReportComment(USER_B_EMAIL, reportAction9CreatedDate, USER_B_ACCOUNT_ID, '9'), }); Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { [USER_B_ACCOUNT_ID]: TestHelper.buildPersonalDetails(USER_B_EMAIL, USER_B_ACCOUNT_ID, 'B'), @@ -321,6 +321,7 @@ describe('Unread Indicators', () => { }, [commentReportActionID]: { actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, + actorEmail: USER_C_EMAIL, actorAccountID: USER_C_ACCOUNT_ID, person: [{type: 'TEXT', style: 'strong', text: 'User C'}], created: NEW_REPORT_FIST_MESSAGE_CREATED_MOMENT.format(MOMENT_FORMAT), diff --git a/tests/utils/TestHelper.js b/tests/utils/TestHelper.js index a8424d14ed33..4f3cf2d61aa6 100644 --- a/tests/utils/TestHelper.js +++ b/tests/utils/TestHelper.js @@ -196,15 +196,17 @@ function setPersonalDetails(login, accountID) { } /** + * @param {String} actorEmail * @param {String} created * @param {Number} actorAccountID * @param {String} actionID * @returns {Object} */ -function buildTestReportComment(created, actorAccountID, actionID = null) { +function buildTestReportComment(actorEmail, created, actorAccountID, actionID = null) { const reportActionID = actionID || NumberUtils.rand64(); return { actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, + actorEmail, person: [{type: 'TEXT', style: 'strong', text: 'User B'}], created, message: [{type: 'COMMENT', html: `Comment ${actionID}`, text: `Comment ${actionID}`}],