Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all uses of actorEmail as part of personalDetails migration #21874

Merged
merged 15 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/libs/E2E/apiMocks/openReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export default () => ({
text: '123 Ios',
},
],
actorEmail: '[email protected]',
actorAccountID: 10773236,
message: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function isConsecutiveActionMadeByPreviousActor(reportActions, actionIndex) {
return false;
}

return currentAction.actorEmail === previousAction.actorEmail;
return currentAction.actorAccountID === previousAction.actorAccountID;
}

/**
Expand Down
27 changes: 7 additions & 20 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ Onyx.connect({
},
});

let loginList;
Onyx.connect({
key: ONYXKEYS.LOGIN_LIST,
callback: (val) => (loginList = _.isEmpty(val) ? [] : _.keys(val)),
});

let preferredLocale = CONST.LOCALES.DEFAULT;
Onyx.connect({
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
Expand Down Expand Up @@ -202,7 +196,7 @@ function sortReportsByLastRead(reports) {
*/
function canEditReportAction(reportAction) {
return (
reportAction.actorEmail === currentUserEmail &&
reportAction.actorAccountID === currentUserAccountID &&
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT &&
!isReportMessageAttachment(lodashGet(reportAction, ['message', 0], {})) &&
!ReportActionsUtils.isDeletedAction(reportAction) &&
Expand All @@ -222,7 +216,7 @@ function canEditReportAction(reportAction) {
*/
function canFlagReportAction(reportAction) {
return (
!loginList.includes(reportAction.actorEmail) &&
reportAction.actorAccountID !== currentUserAccountID &&
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT &&
!ReportActionsUtils.isDeletedAction(reportAction) &&
!ReportActionsUtils.isCreatedTaskReportAction(reportAction)
Expand Down Expand Up @@ -256,7 +250,7 @@ function canDeleteReportAction(reportAction, reportID) {
) {
return false;
}
if (reportAction.actorEmail === currentUserEmail) {
if (reportAction.actorAccountID === currentUserAccountID) {
return true;
}
const report = lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {});
Expand Down Expand Up @@ -737,12 +731,12 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false,
if (isThread(report)) {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);

const actorEmail = lodashGet(parentReportAction, 'actorEmail', '');
const actorAccountID = lodashGet(parentReportAction, 'actorAccountID', '');
const actorAccountID = lodashGet(parentReportAction, 'actorAccountID', 0);
const actorDisplayName = lodashGet(allPersonalDetails, [actorAccountID, 'displayName'], '');
const actorIcon = {
id: actorAccountID,
source: UserUtils.getAvatar(lodashGet(personalDetails, [actorAccountID, 'avatar']), actorAccountID),
name: actorEmail,
name: actorDisplayName,
type: CONST.ICON_TYPE_AVATAR,
};

Expand Down Expand Up @@ -1208,7 +1202,6 @@ function buildOptimisticAddCommentReportAction(text, file) {
reportAction: {
reportActionID: NumberUtils.rand64(),
actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
actorEmail: currentUserEmail,
actorAccountID: currentUserAccountID,
person: [
{
Expand Down Expand Up @@ -1441,7 +1434,6 @@ 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,
Expand Down Expand Up @@ -1480,7 +1472,6 @@ function buildOptimisticReportPreview(reportID, iouReportID, payeeAccountID) {
originalMessage: {
linkedReportID: iouReportID,
},
actorEmail: currentUserEmail,
actorAccountID: currentUserAccountID,
};
}
Expand All @@ -1495,7 +1486,6 @@ function buildOptimisticTaskReportAction(taskReportID, actionName, message = '')
return {
actionName,
actorAccountID: currentUserAccountID,
actorEmail: currentUserEmail,
automatic: false,
avatar: lodashGet(currentUserPersonalDetails, 'avatar', UserUtils.getDefaultAvatar(currentUserAccountID)),
isAttachment: false,
Expand Down Expand Up @@ -1594,7 +1584,6 @@ 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,
Expand Down Expand Up @@ -1634,7 +1623,6 @@ 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,
Expand Down Expand Up @@ -1799,7 +1787,6 @@ function buildOptimisticTaskReport(ownerEmail, ownerAccountID, assigneeAccountID
description,
ownerEmail,
ownerAccountID,
// managerEmail: assignee,
managerID: assigneeAccountID,
type: CONST.REPORT.TYPE.TASK,
parentReportID,
Expand Down Expand Up @@ -2102,7 +2089,7 @@ function shouldShowFlagComment(reportAction, report) {
!isArchivedRoom(report) &&
!chatIncludesChronos(report) &&
!isConciergeChatReport(report.reportID) &&
reportAction.actorEmail !== CONST.EMAIL.CONCIERGE
reportAction.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE
);
}

Expand Down
18 changes: 13 additions & 5 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ 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
*/
Expand All @@ -24,8 +34,6 @@ 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
Expand All @@ -34,7 +42,7 @@ function clearOutTaskInfo() {
*
*/

function createTaskAndNavigate(currentUserEmail, currentUserAccountID, parentReportID, title, description, assignee, assigneeAccountID = 0) {
function createTaskAndNavigate(parentReportID, title, description, assignee, assigneeAccountID = 0) {
// Create the task report
const optimisticTaskReport = ReportUtils.buildOptimisticTaskReport(currentUserEmail, currentUserAccountID, assigneeAccountID, parentReportID, title, description);

Expand Down Expand Up @@ -250,7 +258,7 @@ function reopenTask(taskReportID, taskTitle) {
statusNum: CONST.REPORT.STATUS.OPEN,
lastVisibleActionCreated: reopenedTaskReportAction.created,
lastMessageText: message,
lastActorEmail: reopenedTaskReportAction.actorEmail,
lastActorEmail: currentUserEmail,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB, I think we should still keep it as reopenedTaskReportAction.actorEmail
In case we change ReportUtils::buildOptimisticTaskReportAction() in future and reopenedTaskReportAction get's updated, this direct reference might introduce some bugs.
Same below

Copy link
Contributor Author

@Beamanator Beamanator Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm keen to completely get rid of actorEmail AND we're getting rid of lastActorEmail in this PR: #22008

So I think we'll keep it like this for now 🙏

lastActorAccountID: reopenedTaskReportAction.actorAccountID,
lastReadTime: reopenedTaskReportAction.created,
},
Expand Down Expand Up @@ -585,7 +593,7 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum
value: {
lastVisibleActionCreated: optimisticCancelReportAction.created,
lastMessageText: message,
lastActorEmail: optimisticCancelReportAction.actorEmail,
lastActorEmail: currentUserEmail,
lastActorAccountID: optimisticCancelReportAction.actorAccountID,
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export default [
!isArchivedRoom &&
!isChronosReport &&
!ReportUtils.isConciergeChatReport(reportID) &&
reportAction.actorEmail !== CONST.EMAIL.CONCIERGE,
reportAction.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE,
onPress: (closePopover, {reportID, reportAction}) => {
if (closePopover) {
hideContextMenu(false, () => Navigation.navigate(ROUTES.getFlagCommentRoute(reportID, reportAction.reportActionID)));
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItemSingle.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function ReportActionItemSingle(props) {
const actorAccountID = props.action.actorAccountID;
let {displayName} = props.personalDetailsList[actorAccountID] || {};
const {avatar, pendingFields} = props.personalDetailsList[actorAccountID] || {};
let actorHint = lodashGet(props.action, 'actorEmail', '').replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, '');
let actorHint = displayName.replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we get email here from personal details list and if email is not present then fallback to login?
I think here we are trying to remove prefix from merged accounts emails

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Juuuust to be clear @MonilBhavsar do you mean, we should check the login from personalDetailsList first - and if that doesn't exist, we fall back to displayName?

If that's what you meant, then yes I agree :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

displayName from personalDetailsList always fallback to login if display name is not set, isn't it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean, we should check the login from personalDetailsList first - and if that doesn't exist, we fall back to displayName?

Yes correct! Exactly what I mean :D

displayName from personalDetailsList always fallback to login if display name is not set, isn't it?

Yes, in case display name is set it won't be login. And in that line we specifically want to process login(email). So we can first check if login exists, if not we can fallback to displayName.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

displayName from personalDetailsList always fallback to login if display name is not set, isn't it?

Technically no, not always - for example in OpenPublicProfilePage we won't default their displayName to login since you shouldn't know that at that point

const isWorkspaceActor = ReportUtils.isPolicyExpenseChat(props.report) && !actorAccountID;
let avatarSource = UserUtils.getAvatar(avatar, actorAccountID);

Expand Down
19 changes: 1 addition & 18 deletions src/pages/tasks/NewTaskPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ const propTypes = {
}),
),

/** Current user session */
session: PropTypes.shape({
email: PropTypes.string.isRequired,
}),

/** All reports shared with the user */
reports: PropTypes.objectOf(reportPropTypes),

Expand All @@ -63,7 +58,6 @@ const defaultProps = {
task: {},
personalDetails: {},
reports: {},
session: {},
};

function NewTaskPage(props) {
Expand Down Expand Up @@ -120,15 +114,7 @@ function NewTaskPage(props) {
return;
}

TaskUtils.createTaskAndNavigate(
props.session.email,
props.session.accountID,
parentReport.reportID,
props.task.title,
props.task.description,
props.task.assignee,
props.task.assigneeAccountID,
);
TaskUtils.createTaskAndNavigate(parentReport.reportID, props.task.title, props.task.description, props.task.assignee, props.task.assigneeAccountID);
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
}

if (!Permissions.canUseTasks(props.betas)) {
Expand Down Expand Up @@ -206,9 +192,6 @@ export default compose(
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
withLocalize,
)(NewTaskPage);
2 changes: 0 additions & 2 deletions tests/actions/IOUTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ 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: {
Expand Down Expand Up @@ -835,7 +834,6 @@ 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: {
Expand Down
3 changes: 0 additions & 3 deletions tests/actions/ReportTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ 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'}],
Expand Down Expand Up @@ -230,7 +229,6 @@ 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'}],
Expand Down Expand Up @@ -316,7 +314,6 @@ 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'}],
Expand Down
19 changes: 9 additions & 10 deletions tests/ui/UnreadIndicatorsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ function signInAndGetAppWithUnreadChat() {
},
],
},
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'),
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'),
});
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {
[USER_B_ACCOUNT_ID]: TestHelper.buildPersonalDetails(USER_B_EMAIL, USER_B_ACCOUNT_ID, 'B'),
Expand Down Expand Up @@ -321,7 +321,6 @@ 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),
Expand Down
4 changes: 1 addition & 3 deletions tests/utils/TestHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,15 @@ function setPersonalDetails(login, accountID) {
}

/**
* @param {String} actorEmail
* @param {String} created
* @param {Number} actorAccountID
* @param {String} actionID
* @returns {Object}
*/
function buildTestReportComment(actorEmail, created, actorAccountID, actionID = null) {
function buildTestReportComment(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}`}],
Expand Down