From 1393e5ee9d3332e0450b7fb42883a0c43f1c8713 Mon Sep 17 00:00:00 2001 From: rhahao <26148770+rhahao@users.noreply.github.com> Date: Mon, 25 Sep 2023 19:22:01 +0300 Subject: [PATCH] fix(controller): ignore mfa status when finding user --- .../congregation-admin-controller.js | 95 ++++++++++--------- src/controllers/congregation-controller.js | 4 +- 2 files changed, 51 insertions(+), 48 deletions(-) diff --git a/src/controllers/congregation-admin-controller.js b/src/controllers/congregation-admin-controller.js index 1f0e0d28..3299c36c 100644 --- a/src/controllers/congregation-admin-controller.js +++ b/src/controllers/congregation-admin-controller.js @@ -57,63 +57,66 @@ export const findUserByCongregation = async (req, res, next) => { const search = req.query.search; - if (id) { - const cong = congregations.findCongregationById(id); - if (cong) { - const isValid = await cong.isMember(uid); + if (!id) { + res.locals.type = 'warn'; + res.locals.message = 'the congregation id params is undefined'; + res.status(400).json({ message: 'CONG_ID_INVALID' }); - if (isValid) { - if (search && search.length > 0) { - const userData = await users.findUserByEmail(search); - - if (userData && !userData.disabled && userData.mfaEnabled) { - if (userData.cong_id === id) { - res.locals.type = 'info'; - res.locals.message = 'user is already member of the congregation'; - res.status(200).json({ message: 'ALREADY_MEMBER' }); - return; - } + return; + } - if (userData.cong_id !== '') { - res.locals.type = 'warn'; - res.locals.message = 'user could not be found'; - res.status(404).json({ message: 'ACCOUNT_NOT_FOUND' }); - return; - } + const cong = congregations.findCongregationById(id); - res.locals.type = 'info'; - res.locals.message = 'user details fetched successfully'; - res.status(200).json(userData); - return; - } + if (!cong) { + res.locals.type = 'warn'; + res.locals.message = 'no congregation could not be found with the provided id'; + res.status(404).json({ message: 'CONGREGATION_NOT_FOUND' }); + return; + } - res.locals.type = 'warn'; - res.locals.message = 'user could not be found'; - res.status(404).json({ message: 'ACCOUNT_NOT_FOUND' }); - return; - } + const isValid = await cong.isMember(uid); - res.locals.type = 'warn'; - res.locals.message = 'the search parameter is not correct'; - res.status(400).json({ message: 'SEARCH_INVALID' }); - return; - } + if (!isValid) { + res.locals.type = 'warn'; + res.locals.message = 'user not authorized to access the provided congregation'; + res.status(403).json({ message: 'UNAUTHORIZED_REQUEST' }); + return; + } - res.locals.type = 'warn'; - res.locals.message = 'user not authorized to access the provided congregation'; - res.status(403).json({ message: 'UNAUTHORIZED_REQUEST' }); - return; - } + if (!search || search?.length === 0) { + res.locals.type = 'warn'; + res.locals.message = 'the search parameter is not correct'; + res.status(400).json({ message: 'SEARCH_INVALID' }); + return; + } + + const userData = await users.findUserByEmail(search); + if (!userData) { res.locals.type = 'warn'; - res.locals.message = 'no congregation could not be found with the provided id'; - res.status(404).json({ message: 'CONGREGATION_NOT_FOUND' }); + res.locals.message = 'user could not be found'; + res.status(404).json({ message: 'ACCOUNT_NOT_FOUND' }); return; } - res.locals.type = 'warn'; - res.locals.message = 'the congregation id params is undefined'; - res.status(400).json({ message: 'CONG_ID_INVALID' }); + if (userData.cong_id === id) { + res.locals.type = 'info'; + res.locals.message = 'user is already member of the congregation'; + res.status(200).json({ message: 'ALREADY_MEMBER' }); + return; + } + + if (userData.cong_id !== '') { + res.locals.type = 'warn'; + res.locals.message = 'user could not be found'; + res.status(404).json({ message: 'ACCOUNT_NOT_FOUND' }); + return; + } + + res.locals.type = 'info'; + res.locals.message = 'user details fetched successfully'; + res.status(200).json(userData); + return; } catch (err) { next(err); } diff --git a/src/controllers/congregation-controller.js b/src/controllers/congregation-controller.js index 2f983329..428e51fb 100644 --- a/src/controllers/congregation-controller.js +++ b/src/controllers/congregation-controller.js @@ -205,7 +205,7 @@ export const getCongregationBackup = async (req, res, next) => { const lmmoRole = user.cong_role.includes('lmmo') || user.cong_role.includes('lmmo-backup'); const secretaryRole = user.cong_role.includes('secretary'); - const weekendEditorRole = user.cong_role.includes('coordinator') || user.cong_role.includes('public_talk)coordinator'); + const weekendEditorRole = user.cong_role.includes('coordinator') || user.cong_role.includes('public_talk_coordinator'); const publisherRole = isPublisher || isMS || isElder; if (!lmmoRole && !secretaryRole && !publisherRole && !weekendEditorRole) { @@ -226,6 +226,7 @@ export const getCongregationBackup = async (req, res, next) => { if (lmmoRole || weekendEditorRole) { obj.cong_schedule = backupData.cong_schedule; obj.cong_sourceMaterial = backupData.cong_sourceMaterial; + obj.cong_publicTalks = backupData.cong_publicTalks; } if (secretaryRole) { @@ -240,7 +241,6 @@ export const getCongregationBackup = async (req, res, next) => { if (weekendEditorRole) { obj.cong_visitingSpeakers = backupData.cong_visitingSpeakers; - obj.cong_publicTalks = backupData.cong_publicTalks; } }