From 2c4438aa09e9977042f746e08d530678ea9af054 Mon Sep 17 00:00:00 2001 From: Rahul Goyal Date: Sun, 17 Nov 2024 00:40:28 +0530 Subject: [PATCH 1/4] Added seperate function for unobfuscated contact details and filtered id in update data step. --- controllers/users.js | 2 +- models/profileDiffs.js | 25 +++++++++++++++++++++++++ models/users.js | 10 +++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index 1fa81c282..02e5e3f2d 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -654,7 +654,7 @@ const updateUser = async (req, res) => { try { const { id: profileDiffId, message } = req.body; - const profileDiffData = await profileDiffsQuery.fetchProfileDiff(profileDiffId); + const profileDiffData = await profileDiffsQuery.fetchProfileDiffUnobfuscated(profileDiffId); if (!profileDiffData) return res.boom.notFound("Profile Diff doesn't exist"); const { approval, timestamp, userId, ...profileDiff } = profileDiffData; diff --git a/models/profileDiffs.js b/models/profileDiffs.js index 494e192c9..f2e8895aa 100644 --- a/models/profileDiffs.js +++ b/models/profileDiffs.js @@ -133,6 +133,30 @@ const fetchProfileDiff = async (profileDiffId) => { } }; +/** + * Fetches the unobfuscated profileDiff data of the provided profileDiff Id + * @param profileDiffId profileDiffId of the diffs need to be fetched + * @returns unobfuscated profileDiff Data + */ +const fetchProfileDiffUnobfuscated = async (profileDiffId) => { + try { + const profileDiff = await profileDiffsModel.doc(profileDiffId).get(); + + if (!profileDiff.exists) { + return { profileDiffExists: false }; + } + const profileDiffData = profileDiff.data(); + return { + id: profileDiff.id, + profileDiffExists: true, + ...profileDiffData, + }; + } catch (err) { + logger.error("Error retrieving profile Diff", err); + throw err; + } +}; + /** Add profileDiff * * @param profileDiffData { Object }: Data to be added @@ -181,4 +205,5 @@ module.exports = { add, updateProfileDiff, fetchProfileDiffsWithPagination, + fetchProfileDiffUnobfuscated, }; diff --git a/models/users.js b/models/users.js index e0746de92..7f681d25a 100644 --- a/models/users.js +++ b/models/users.js @@ -42,9 +42,17 @@ const addOrUpdate = async (userData, userId = null) => { const isNewUser = !user.data(); // user exists update user if (user.data()) { + // remove id field if exist in fetched data or profileDiff + const currentData = user.data(); + if ("id" in currentData) { + delete currentData.id; + } + if ("id" in userData) { + delete userData.id; + } await userModel.doc(userId).set( { - ...user.data(), + ...currentData, ...userData, updated_at: Date.now(), }, From a6983a2e4545f52ac4caf5a7cf7d6695423fb5a0 Mon Sep 17 00:00:00 2001 From: RahulGoyal-tech Date: Wed, 20 Nov 2024 19:14:21 +0530 Subject: [PATCH 2/4] Removed id filtering for current data --- models/users.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/models/users.js b/models/users.js index 7f681d25a..74c54a4f1 100644 --- a/models/users.js +++ b/models/users.js @@ -43,16 +43,12 @@ const addOrUpdate = async (userData, userId = null) => { // user exists update user if (user.data()) { // remove id field if exist in fetched data or profileDiff - const currentData = user.data(); - if ("id" in currentData) { - delete currentData.id; - } if ("id" in userData) { delete userData.id; } await userModel.doc(userId).set( { - ...currentData, + ...user.data(), ...userData, updated_at: Date.now(), }, From e2aa779294c68a83d622e80e4c62e0c7153cd5b5 Mon Sep 17 00:00:00 2001 From: Rahul Goyal Date: Fri, 22 Nov 2024 08:32:06 +0530 Subject: [PATCH 3/4] Updated error message --- models/profileDiffs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/profileDiffs.js b/models/profileDiffs.js index f2e8895aa..34b64e340 100644 --- a/models/profileDiffs.js +++ b/models/profileDiffs.js @@ -152,7 +152,7 @@ const fetchProfileDiffUnobfuscated = async (profileDiffId) => { ...profileDiffData, }; } catch (err) { - logger.error("Error retrieving profile Diff", err); + logger.error("Error retrieving Unobfuscated profile Diff", err); throw err; } }; From d47204d832ae4a4a11cd016fde24c61fdd7e7a9f Mon Sep 17 00:00:00 2001 From: Rahul Goyal Date: Fri, 29 Nov 2024 08:42:09 +0530 Subject: [PATCH 4/4] Added dev feature flag --- controllers/users.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index 02e5e3f2d..c1518b72c 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -653,8 +653,14 @@ const getUserImageForVerification = async (req, res) => { const updateUser = async (req, res) => { try { const { id: profileDiffId, message } = req.body; - - const profileDiffData = await profileDiffsQuery.fetchProfileDiffUnobfuscated(profileDiffId); + const devFeatureFlag = req.query.dev; + let profileDiffData; + if (devFeatureFlag === "true") { + profileDiffData = await profileDiffsQuery.fetchProfileDiffUnobfuscated(profileDiffId); + } else { + profileDiffData = await profileDiffsQuery.fetchProfileDiff(profileDiffId); + } + Object.freeze(profileDiffData); if (!profileDiffData) return res.boom.notFound("Profile Diff doesn't exist"); const { approval, timestamp, userId, ...profileDiff } = profileDiffData;