From 90522fae94d3929305f34eba965f078dbabc841e Mon Sep 17 00:00:00 2001 From: adithya_dinesh Date: Fri, 23 Feb 2024 20:58:56 +0530 Subject: [PATCH 1/3] filter list issue fixed --- src/services/mentees.js | 64 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/src/services/mentees.js b/src/services/mentees.js index 0f24d68e8..d9d1b5160 100644 --- a/src/services/mentees.js +++ b/src/services/mentees.js @@ -925,8 +925,42 @@ module.exports = class MenteesHelper { relatedOrgs = userOrgDetails.data.result.related_orgs } if (visibilityPolicy === common.ASSOCIATED) { - organization_ids.push(...relatedOrgs) + const associatedAdditionalFilter = + filter_type.toLowerCase() == common.MENTEE_ROLE + ? { + external_session_visibility_policy: { + [Op.ne]: 'CURRENT', + }, + } + : { + mentor_visibility_policy: { + [Op.ne]: 'CURRENT', + }, + } + + const organizationExtension = await organisationExtensionQueries.findAll( + { + [Op.and]: [ + { + organization_id: { + [Op.in]: [...relatedOrgs, orgPolicies.organization_id], + }, + }, + associatedAdditionalFilter, + ], + }, + { + attributes: ['organization_id'], + } + ) + if (organizationExtension) { + const organizationIds = organizationExtension.map((orgExt) => orgExt.organization_id) + organization_ids.push(...organizationIds) + } } else { + // filter out the organizations + // CASE 1 : in case of mentee listing filterout organizations with external_session_visibility_policy = ALL + // CASE 2 : in case of mentor listing filterout organizations with mentor_visibility_policy = ALL const filterQuery = filter_type.toLowerCase() == common.MENTEE_ROLE ? { @@ -935,14 +969,36 @@ module.exports = class MenteesHelper { : { mentor_visibility_policy: common.ALL, } + + // this filter is applied for the below condition + // SM session_visibility_policy (in case of mentee list) or external_mentor_visibility policy (in case of mentor list) = ALL + // and CASE 1 (mentee list) : Mentees is related to the SM org but external_session_visibility is CURRENT (exclude these mentees) + // CASE 2 : (mentor list) : Mentors is related to SM Org but mentor_visibility set to CURRENT (exclude these mentors) + const additionalFilter = + filter_type.toLowerCase() == common.MENTEE_ROLE + ? { + external_session_visibility_policy: { + [Op.ne]: 'CURRENT', + }, + } + : { + mentor_visibility_policy: { + [Op.ne]: 'CURRENT', + }, + } const organizationExtension = await organisationExtensionQueries.findAll( { [Op.or]: [ filterQuery, { - organization_id: { - [Op.in]: [...relatedOrgs, orgPolicies.organization_id], - }, + [Op.and]: [ + { + organization_id: { + [Op.in]: [...relatedOrgs, orgPolicies.organization_id], + }, + }, + additionalFilter, + ], }, ], }, From 49a65fdb45ffe5ca9bff818a6dcd9be801ace334 Mon Sep 17 00:00:00 2001 From: adithya_dinesh Date: Fri, 23 Feb 2024 21:41:01 +0530 Subject: [PATCH 2/3] filter list issue fix --- src/services/mentees.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/services/mentees.js b/src/services/mentees.js index d9d1b5160..269138c79 100644 --- a/src/services/mentees.js +++ b/src/services/mentees.js @@ -896,9 +896,9 @@ module.exports = class MenteesHelper { static async getOrganizationIdBasedOnPolicy(userId, organization_id, filter_type) { try { let organization_ids = [] - + filter_type = filter_type.toLowerCase() const attributes = - filter_type.toLowerCase() == common.MENTEE_ROLE + filter_type == common.MENTEE_ROLE ? ['organization_id', 'session_visibility_policy'] : ['organization_id', 'external_mentor_visibility_policy'] @@ -910,7 +910,7 @@ module.exports = class MenteesHelper { ) const visibilityPolicy = - filter_type.toLowerCase() == common.MENTEE_ROLE + filter_type == common.MENTEE_ROLE ? orgPolicies.session_visibility_policy : orgPolicies.external_mentor_visibility_policy @@ -926,7 +926,7 @@ module.exports = class MenteesHelper { } if (visibilityPolicy === common.ASSOCIATED) { const associatedAdditionalFilter = - filter_type.toLowerCase() == common.MENTEE_ROLE + filter_type == common.MENTEE_ROLE ? { external_session_visibility_policy: { [Op.ne]: 'CURRENT', @@ -943,7 +943,7 @@ module.exports = class MenteesHelper { [Op.and]: [ { organization_id: { - [Op.in]: [...relatedOrgs, orgPolicies.organization_id], + [Op.in]: [...relatedOrgs], }, }, associatedAdditionalFilter, @@ -953,6 +953,7 @@ module.exports = class MenteesHelper { attributes: ['organization_id'], } ) + organization_ids.push(orgPolicies.organization_id) if (organizationExtension) { const organizationIds = organizationExtension.map((orgExt) => orgExt.organization_id) organization_ids.push(...organizationIds) @@ -962,7 +963,7 @@ module.exports = class MenteesHelper { // CASE 1 : in case of mentee listing filterout organizations with external_session_visibility_policy = ALL // CASE 2 : in case of mentor listing filterout organizations with mentor_visibility_policy = ALL const filterQuery = - filter_type.toLowerCase() == common.MENTEE_ROLE + filter_type == common.MENTEE_ROLE ? { external_session_visibility_policy: common.ALL, } @@ -975,7 +976,7 @@ module.exports = class MenteesHelper { // and CASE 1 (mentee list) : Mentees is related to the SM org but external_session_visibility is CURRENT (exclude these mentees) // CASE 2 : (mentor list) : Mentors is related to SM Org but mentor_visibility set to CURRENT (exclude these mentors) const additionalFilter = - filter_type.toLowerCase() == common.MENTEE_ROLE + filter_type == common.MENTEE_ROLE ? { external_session_visibility_policy: { [Op.ne]: 'CURRENT', @@ -994,7 +995,7 @@ module.exports = class MenteesHelper { [Op.and]: [ { organization_id: { - [Op.in]: [...relatedOrgs, orgPolicies.organization_id], + [Op.in]: [...relatedOrgs], }, }, additionalFilter, @@ -1006,6 +1007,7 @@ module.exports = class MenteesHelper { attributes: ['organization_id'], } ) + organization_ids.push(orgPolicies.organization_id) if (organizationExtension) { const organizationIds = organizationExtension.map((orgExt) => orgExt.organization_id) organization_ids.push(...organizationIds) From abce386dd80922fe137a63bdd1e7bb7c3f0491e7 Mon Sep 17 00:00:00 2001 From: adithya_dinesh Date: Sat, 24 Feb 2024 01:19:48 +0530 Subject: [PATCH 3/3] filter list issue fix --- src/services/mentees.js | 48 ++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/services/mentees.js b/src/services/mentees.js index 269138c79..1bf7ddc56 100644 --- a/src/services/mentees.js +++ b/src/services/mentees.js @@ -893,16 +893,16 @@ module.exports = class MenteesHelper { } } - static async getOrganizationIdBasedOnPolicy(userId, organization_id, filter_type) { + static async getOrganizationIdBasedOnPolicy(userId, organization_id, filterType) { try { - let organization_ids = [] - filter_type = filter_type.toLowerCase() + let organizationIds = [] + filterType = filterType.toLowerCase() const attributes = - filter_type == common.MENTEE_ROLE + filterType == common.MENTEE_ROLE ? ['organization_id', 'session_visibility_policy'] : ['organization_id', 'external_mentor_visibility_policy'] - const orgPolicies = await organisationExtensionQueries.findOne( + const orgExtension = await organisationExtensionQueries.findOne( { organization_id }, { attributes: attributes, @@ -910,23 +910,23 @@ module.exports = class MenteesHelper { ) const visibilityPolicy = - filter_type == common.MENTEE_ROLE - ? orgPolicies.session_visibility_policy - : orgPolicies.external_mentor_visibility_policy + filterType == common.MENTEE_ROLE + ? orgExtension.session_visibility_policy + : orgExtension.external_mentor_visibility_policy - if (orgPolicies?.organization_id) { + if (orgExtension?.organization_id) { if (visibilityPolicy === common.CURRENT) { - organization_ids.push(orgPolicies.organization_id) + organizationIds.push(orgExtension.organization_id) } else if (visibilityPolicy === common.ASSOCIATED || visibilityPolicy === common.ALL) { - organization_ids.push(orgPolicies.organization_id) + organizationIds.push(orgExtension.organization_id) let relatedOrgs = [] - let userOrgDetails = await userRequests.fetchDefaultOrgDetails(orgPolicies.organization_id) + let userOrgDetails = await userRequests.fetchDefaultOrgDetails(orgExtension.organization_id) if (userOrgDetails.success && userOrgDetails.data?.result?.related_orgs?.length > 0) { relatedOrgs = userOrgDetails.data.result.related_orgs } if (visibilityPolicy === common.ASSOCIATED) { const associatedAdditionalFilter = - filter_type == common.MENTEE_ROLE + filterType == common.MENTEE_ROLE ? { external_session_visibility_policy: { [Op.ne]: 'CURRENT', @@ -953,17 +953,19 @@ module.exports = class MenteesHelper { attributes: ['organization_id'], } ) - organization_ids.push(orgPolicies.organization_id) + organizationIds.push(orgExtension.organization_id) if (organizationExtension) { - const organizationIds = organizationExtension.map((orgExt) => orgExt.organization_id) - organization_ids.push(...organizationIds) + const organizationIdsFromOrgExtension = organizationExtension.map( + (orgExt) => orgExt.organization_id + ) + organizationIds.push(...organizationIdsFromOrgExtension) } } else { // filter out the organizations // CASE 1 : in case of mentee listing filterout organizations with external_session_visibility_policy = ALL // CASE 2 : in case of mentor listing filterout organizations with mentor_visibility_policy = ALL const filterQuery = - filter_type == common.MENTEE_ROLE + filterType == common.MENTEE_ROLE ? { external_session_visibility_policy: common.ALL, } @@ -976,7 +978,7 @@ module.exports = class MenteesHelper { // and CASE 1 (mentee list) : Mentees is related to the SM org but external_session_visibility is CURRENT (exclude these mentees) // CASE 2 : (mentor list) : Mentors is related to SM Org but mentor_visibility set to CURRENT (exclude these mentors) const additionalFilter = - filter_type == common.MENTEE_ROLE + filterType == common.MENTEE_ROLE ? { external_session_visibility_policy: { [Op.ne]: 'CURRENT', @@ -1007,10 +1009,12 @@ module.exports = class MenteesHelper { attributes: ['organization_id'], } ) - organization_ids.push(orgPolicies.organization_id) + organizationIds.push(orgExtension.organization_id) if (organizationExtension) { - const organizationIds = organizationExtension.map((orgExt) => orgExt.organization_id) - organization_ids.push(...organizationIds) + const organizationIdsFromOrgExtension = organizationExtension.map( + (orgExt) => orgExt.organization_id + ) + organizationIds.push(...organizationIdsFromOrgExtension) } } } @@ -1018,7 +1022,7 @@ module.exports = class MenteesHelper { return { success: true, - result: organization_ids, + result: organizationIds, } } catch (error) { return {