From 2486f893eb075a2ec203d1cac7b615e1bc1fefc1 Mon Sep 17 00:00:00 2001 From: andrew rumble Date: Tue, 3 Sep 2024 15:30:34 +0100 Subject: [PATCH] Add an endpoint for rails to record salesforce mappings GitOrigin-RevId: fcca974a69217dc885c458543a82b4dcc338d98b --- .../Analytics/AccountMappingHelper.mjs | 23 +++++++++++++++++++ .../Analytics/AnalyticsController.mjs | 13 +++++++++++ .../Features/Analytics/AnalyticsRouter.mjs | 6 +++++ 3 files changed, 42 insertions(+) diff --git a/services/web/app/src/Features/Analytics/AccountMappingHelper.mjs b/services/web/app/src/Features/Analytics/AccountMappingHelper.mjs index c5525d3053..76e4bc51bc 100644 --- a/services/web/app/src/Features/Analytics/AccountMappingHelper.mjs +++ b/services/web/app/src/Features/Analytics/AccountMappingHelper.mjs @@ -28,8 +28,30 @@ export function extractAccountMappingsFromSubscription( } return accountMappings } + +export function generateV1Mapping(v1Id, salesforceId, createdAt) { + return { + source: 'salesforce', + sourceEntity: 'account', + sourceEntityId: salesforceId, + target: 'v1', + targetEntity: 'university', + targetEntityId: v1Id, + createdAt, + } } +function generateSubscriptionToV1Mapping(subscriptionId, v1Id) { + return { + source: 'v1', + sourceEntity: 'university', + sourceEntityId: v1Id, + target: 'v2', + targetEntity: 'subscription', + targetEntityId: subscriptionId, + createdAt: new Date().toISOString(), + } +} function generateSubscriptionToSalesforceMapping(subscriptionId, salesforceId) { return { @@ -45,4 +67,5 @@ function generateSubscriptionToSalesforceMapping(subscriptionId, salesforceId) { export default { extractAccountMappingsFromSubscription, + generateV1Mapping, } diff --git a/services/web/app/src/Features/Analytics/AnalyticsController.mjs b/services/web/app/src/Features/Analytics/AnalyticsController.mjs index 7665e7ecd9..8ae54518b9 100644 --- a/services/web/app/src/Features/Analytics/AnalyticsController.mjs +++ b/services/web/app/src/Features/Analytics/AnalyticsController.mjs @@ -4,6 +4,18 @@ import SessionManager from '../Authentication/SessionManager.js' import GeoIpLookup from '../../infrastructure/GeoIpLookup.js' import Features from '../../infrastructure/Features.js' import { expressify } from '@overleaf/promise-utils' +import { generateV1Mapping } from './AccountMappingHelper.mjs' + +async function registerSalesforceMapping(req, res, next) { + if (!Features.hasFeature('analytics')) { + return res.sendStatus(202) + } + const { createdAt, salesforceId, v1Id } = req.body + AnalyticsManager.registerAccountMapping( + generateV1Mapping(v1Id, salesforceId, createdAt) + ) + res.sendStatus(202) +} async function updateEditingSession(req, res, next) { if (!Features.hasFeature('analytics')) { @@ -47,6 +59,7 @@ function recordEvent(req, res, next) { } export default { + registerSalesforceMapping: expressify(registerSalesforceMapping), updateEditingSession: expressify(updateEditingSession), recordEvent, } diff --git a/services/web/app/src/Features/Analytics/AnalyticsRouter.mjs b/services/web/app/src/Features/Analytics/AnalyticsRouter.mjs index 523bbcf146..933d4b0c13 100644 --- a/services/web/app/src/Features/Analytics/AnalyticsRouter.mjs +++ b/services/web/app/src/Features/Analytics/AnalyticsRouter.mjs @@ -41,5 +41,11 @@ export default { RateLimiterMiddleware.rateLimit(rateLimiters.uniExternalCollabProxy), AnalyticsProxy.call('/uniExternalCollaboration') ) + + publicApiRouter.post( + '/analytics/register-v-1-salesforce-mapping', + AuthenticationController.requirePrivateApiAuth(), + AnalyticsController.registerSalesforceMapping + ) }, }