From a31bfcf8f2c231b9835ed894028d9ed4dc511a51 Mon Sep 17 00:00:00 2001 From: LesterLyu Date: Mon, 3 Feb 2025 23:39:26 -0500 Subject: [PATCH] bugfix --- .../organizationInternalTypeTreater.js | 3 +++ .../services/partnerNetwork/appointments.js | 3 ++- backend/services/partnerNetwork/index.js | 3 ++- backend/services/partnerNetwork/referrals.js | 3 ++- backend/services/partnerNetwork/update.js | 20 ++++++++++++++++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/backend/services/genericData/organizationInternalTypeTreater.js b/backend/services/genericData/organizationInternalTypeTreater.js index d01abf53..c5097035 100644 --- a/backend/services/genericData/organizationInternalTypeTreater.js +++ b/backend/services/genericData/organizationInternalTypeTreater.js @@ -5,6 +5,9 @@ const { getPartnerOrganizationsHelper } = require("../partnerOrganization"); const afterUpdateOrganization = async function (data, oldGeneric, req) { const wasHomeOrganization = oldGeneric.status === 'Home'; const isHomeOrganization = data.fields?.[PredefinedCharacteristics['Organization Status']?._uri.split('#')[1]] === 'Home'; + + // If the organization is not a home organization, do not send a notification. + // If the organization changed to a home organization or vice versa, send a notification to all partners. if (!wasHomeOrganization && !isHomeOrganization) { return; } diff --git a/backend/services/partnerNetwork/appointments.js b/backend/services/partnerNetwork/appointments.js index 840a3455..c10aa174 100644 --- a/backend/services/partnerNetwork/appointments.js +++ b/backend/services/partnerNetwork/appointments.js @@ -11,6 +11,7 @@ const {getClient, getReferralPartnerGeneric} = require("./referrals"); const {createNotificationHelper} = require("../notification/notification"); const {sanitize} = require("../../helpers/sanitizer"); const {regexBuilder} = require("graphdb-utils"); +const {frontend} = require("../../config"); /** * Converts an appointment generic into a format in which it can be sent to a partner deployment @@ -108,7 +109,7 @@ async function sendAppointment(req, res, next) { 'Content-Type': 'application/json', 'X-RECEIVER-API-KEY': partnerGeneric[PredefinedCharacteristics['API Key']._uri.split('#')[1]], // Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com` - 'Referer': new URL(req.headers.origin).hostname, + 'Referer': new URL(frontend.addr).hostname, }, body: JSON.stringify(appointment), }); diff --git a/backend/services/partnerNetwork/index.js b/backend/services/partnerNetwork/index.js index 29477c2b..c07cddbc 100644 --- a/backend/services/partnerNetwork/index.js +++ b/backend/services/partnerNetwork/index.js @@ -10,6 +10,7 @@ const {getProviderById} = require("../genericData/serviceProvider"); const {getDynamicFormsByFormTypeHelper, getIndividualsInClass} = require("../dynamicForm"); const {convertAddressForSerialization, convertAddressForDeserialization} = require("../address/misc"); const {GDBVolunteerModel} = require("../../models/volunteer"); +const {frontend} = require("../../config"); /** * Requests that a partner deployment represented locally as the partner @@ -45,7 +46,7 @@ async function fetchOrganizationHelper(req, genericId) { 'X-RECEIVER-API-KEY': organization.apiKey, ...(!!senderApiKey && {'X-SENDER-API-KEY': senderApiKey}), // Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com` - 'Referer': new URL(req.headers.origin).hostname, + 'Referer': new URL(frontend.addr).hostname, }, }); clearTimeout(timeout); diff --git a/backend/services/partnerNetwork/referrals.js b/backend/services/partnerNetwork/referrals.js index 3fda49f8..db6e983a 100644 --- a/backend/services/partnerNetwork/referrals.js +++ b/backend/services/partnerNetwork/referrals.js @@ -14,6 +14,7 @@ const {getGenericAssets} = require("./index"); const {createNotificationHelper} = require("../notification/notification"); const {sanitize} = require("../../helpers/sanitizer"); const {regexBuilder} = require("graphdb-utils"); +const {frontend} = require("../../config"); /** * Converts a referral generic into a format in which it can be sent to a partner deployment. @@ -173,7 +174,7 @@ async function sendReferral(req, res, next) { 'Content-Type': 'application/json', 'X-RECEIVER-API-KEY': partnerGeneric[PredefinedCharacteristics['API Key']._uri.split('#')[1]], // Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com` - 'Referer': new URL(req.headers.origin).hostname, + 'Referer': new URL(frontend.addr).hostname, }, body: JSON.stringify(referral), }); diff --git a/backend/services/partnerNetwork/update.js b/backend/services/partnerNetwork/update.js index 3a80e232..a59a0944 100644 --- a/backend/services/partnerNetwork/update.js +++ b/backend/services/partnerNetwork/update.js @@ -5,7 +5,18 @@ const {GDBOrganizationModel} = require("../../models/organization"); const {getIndividualsInClass} = require("../dynamicForm"); const {createNotificationHelper} = require("../notification/notification"); const {regexBuilder} = require("graphdb-utils"); +const {frontend} = require("../../config"); +/** + * Send a notification to a partner organization to update its home organization. + * This is triggered when + * - the home organization is updated + * - a program is created, updated, or deleted + * - a volunteer is created, updated, or deleted + * @param req - The request object. + * @param partnerId - The ID of the partner organization. + * @returns {Promise} + */ async function sendPartnerUpdateNotification(req, partnerId) { const { fetchSingleGenericHelper } = require("../genericData"); const { getOrganization } = require("."); @@ -33,7 +44,7 @@ async function sendPartnerUpdateNotification(req, partnerId) { 'X-RECEIVER-API-KEY': organization.apiKey, ...(!!senderApiKey && { 'X-SENDER-API-KEY': senderApiKey }), // Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com` - 'Referer': new URL(req.headers.origin).hostname, + 'Referer': new URL(frontend.addr).hostname, }, }); clearTimeout(timeout); @@ -68,6 +79,13 @@ async function printAddress(address) { return sanitize(formatLocation(address, addressInfo)); } +/** + * Receive a notification from a partner organization to update its home organization. + * @param req - The request object. + * @param res - The response object. + * @param next - The next middleware function. + * @returns {Promise<*>} + */ async function receivePartnerUpdateNotification(req, res, next) { const { fetchOrganizationHelper, deleteOrganizationHelper, updateOrganizationHelper } = require(".");