Skip to content

Commit

Permalink
Add whisperedTo and childEmails
Browse files Browse the repository at this point in the history
  • Loading branch information
puneetlath committed Jun 24, 2023
1 parent fc04ddc commit bccd465
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions src/libs/migrations/PersonalDetailsByAccountID.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,22 @@ function getDeprecatedPersonalDetailsFromOnyx() {
}

/**
* Migrate Onyx data to hide emails where necessary.
*
* - personalDetails -> personalDetailsList
* - Key by accountID instead of email
* - Must check if users are "known" or not, and include their contact info if and only if they are "known"
* - policyMemberList_ -> policyMember_
* - Key by accountID instead of email
* - reportAction_
* - oldLogin -> oldAccountID
* - newLogin -> newAccountID
* - actorEmail -> actorAccountID
* - accountEmail -> accountID
* - childManagerEmail -> childManagerAccountID
* - originalMessage.participants -> originalMessage.participantAccountIDs
* - whisperedTo -> whisperedToAccountID
* - childOldestFourEmails -> childOldestFourAccountIDs
* - report_
* - ownerEmail -> ownerAccountID
* - managerEmail -> managerID
* - lastActorEmail -> lastActorAccountID
* - participants -> participantAccountIDs
* Migrate Onyx data for the email to accountID migration.
*
* @returns {Promise<void>}
*/
export default function () {
return Promise.all([getReportActionsFromOnyx(), getDeprecatedPersonalDetailsFromOnyx()]).then(
([oldReportActions, oldPersonalDetails]) => {
const onyxData = {};
// originalMessage.oldLogin -> originalMessage.oldAccountID x
// originalMessage.newLogin -> originalMessage.newAccountID x
// actorEmail -> actorAccountID x
// childManagerEmail -> childManagerAccountID x
// whisperedTo -> whisperedToAccountIDs x
// childOldestFourEmails -> childOldestFourAccountIDs x
// participants -> participantAccountIDs ?
// accountEmail -> accountID ?

// We migrate reportActions to have the new accountID-based data if they don't already.
// If we are not able to get the accountID for some reason, we will just clear the reportAction
Expand All @@ -84,19 +72,19 @@ export default function () {

const newReportAction = reportAction;

if (reportAction.oldLogin && !reportAction.oldAccountID) {
const oldAccountID = _.get(oldPersonalDetails, [reportAction.oldLogin, 'accountID']);
if (reportAction.originalMessage.oldLogin && !reportAction.originalMessage.oldAccountID) {
const oldAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.oldLogin, 'accountID']);
if (oldAccountID) {
newReportAction.oldAccountID = oldAccountID;
newReportAction.originalMessage.oldAccountID = oldAccountID;
} else {
return;
}
}

if (reportAction.newLogin && !reportAction.newAccountID) {
const newAccountID = _.get(oldPersonalDetails, [reportAction.newLogin, 'accountID']);
if (reportAction.originalMessage.newLogin && !reportAction.originalMessage.newAccountID) {
const newAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.newLogin, 'accountID']);
if (newAccountID) {
newReportAction.newAccountID = newAccountID;
newReportAction.originalMessage.newAccountID = newAccountID;
} else {
return;
}
Expand All @@ -111,15 +99,6 @@ export default function () {
}
}

if (reportAction.accountEmail && !reportAction.accountID) {
const accountID = _.get(oldPersonalDetails, [reportAction.accountEmail, 'accountID']);
if (accountID) {
newReportAction.accountID = accountID;
} else {
return;
}
}

if (reportAction.childManagerEmail && !reportAction.childManagerAccountID) {
const childManagerAccountID = _.get(oldPersonalDetails, [reportAction.childManagerEmail, 'accountID']);
if (childManagerAccountID) {
Expand All @@ -129,28 +108,23 @@ export default function () {
}
}

const newOriginalMessage = _.omit(reportAction.originalMessage, ['participants']);
const oldParticipants = _.get(reportAction, ['originalMessage', 'participants'], []);
const newParticipants = [];
_.each(oldParticipants, (login) => {
const accountID = _.get(oldPersonalDetails, [login, 'accountID']);
newParticipants.push(accountID);
});
newOriginalMessage.participantAccountIDs = newParticipants;
newReportAction.originalMessage = newOriginalMessage;

if (reportAction.whisperedTo) {
if (reportAction.whisperedTo && !reportAction.whisperedToAccountIDs) {
const whisperedToAccountIDs = [];
_.each(reportAction.whisperedTo, (whisperedToLogin) => {
const whisperedToAccountID = _.get(oldPersonalDetails, [whisperedToLogin, 'accountID']);
if (whisperedToAccountID) {
whisperedToAccountIDs.push(whisperedToAccountID);
}
});
newReportAction.whisperedToAccountIDs = whisperedToAccountIDs;

if (whisperedToAccountIDs.length === reportAction.whisperedTo.length) {
newReportAction.whisperedToAccountIDs = whisperedToAccountIDs;
} else {
return;
}
}

if (reportAction.childOldestFourEmails) {
if (reportAction.childOldestFourEmails && !reportAction.childOldestFourAccountIDs) {
const childOldestFourEmails = reportAction.childOldestFourEmails.split(',');
const childOldestFourAccountIDs = [];
_.each(childOldestFourEmails, (login) => {
Expand All @@ -159,9 +133,35 @@ export default function () {
childOldestFourAccountIDs.push(accountID);
}
});
newReportAction.childOldestFourAccountIDs = childOldestFourAccountIDs.join(',');

if (childOldestFourAccountIDs.length === childOldestFourEmails.length) {
newReportAction.childOldestFourAccountIDs = childOldestFourAccountIDs.join(',');
} else {
return;
}
}


if (reportAction.accountEmail && !reportAction.accountID) {
const accountID = _.get(oldPersonalDetails, [reportAction.accountEmail, 'accountID']);
if (accountID) {
newReportAction.accountID = accountID;
} else {
return;
}
}

const newOriginalMessage = _.omit(reportAction.originalMessage, ['participants']);
const oldParticipants = _.get(reportAction, ['originalMessage', 'participants'], []);
const newParticipants = [];
_.each(oldParticipants, (login) => {
const accountID = _.get(oldPersonalDetails, [login, 'accountID']);
newParticipants.push(accountID);
});
newOriginalMessage.participantAccountIDs = newParticipants;
newReportAction.originalMessage = newOriginalMessage;


newReportActionsForReport[newReportAction.reportActionID] = newReportAction;
});

Expand Down

0 comments on commit bccd465

Please sign in to comment.