Skip to content

Commit

Permalink
fix(controller): ignore mfa status when finding user
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Sep 25, 2023
1 parent b7f5d77 commit 1393e5e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 48 deletions.
95 changes: 49 additions & 46 deletions src/controllers/congregation-admin-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/congregation-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 1393e5e

Please sign in to comment.