From f1304fa205ccdb2c50fb3c84871bca0ee2ea0dd7 Mon Sep 17 00:00:00 2001 From: M Fahru Date: Wed, 1 Mar 2023 07:08:18 -0700 Subject: [PATCH] Add missing ip matcher endpoint hit when opening project dashboard react (#12015) * Add missing ip matcher endpoint hit when opening project dashboard react * Add error logger on the catch block GitOrigin-RevId: 0f69de329b1290a4f0f98ef00dda050fb09d5a08 --- .../Features/Notifications/NotificationsBuilder.js | 3 +++ .../src/Features/Project/ProjectListController.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/services/web/app/src/Features/Notifications/NotificationsBuilder.js b/services/web/app/src/Features/Notifications/NotificationsBuilder.js index f8281d3bfb..ea061ee65e 100644 --- a/services/web/app/src/Features/Notifications/NotificationsBuilder.js +++ b/services/web/app/src/Features/Notifications/NotificationsBuilder.js @@ -245,6 +245,9 @@ NotificationsBuilder.promises = { dropboxDuplicateProjectNames(userId) { return promisifyAll(dropboxDuplicateProjectNames(userId)) }, + ipMatcherAffiliation: function (userId) { + return promisifyAll(ipMatcherAffiliation(userId)) + }, } module.exports = NotificationsBuilder diff --git a/services/web/app/src/Features/Project/ProjectListController.js b/services/web/app/src/Features/Project/ProjectListController.js index 170b87b530..0f8bf772b7 100644 --- a/services/web/app/src/Features/Project/ProjectListController.js +++ b/services/web/app/src/Features/Project/ProjectListController.js @@ -20,6 +20,7 @@ const { User } = require('../../models/User') const UserPrimaryEmailCheckHandler = require('../User/UserPrimaryEmailCheckHandler') const UserController = require('../User/UserController') const LimitationsManager = require('../Subscription/LimitationsManager') +const NotificationsBuilder = require('../Notifications/NotificationsBuilder') /** @typedef {import("./types").GetProjectsRequest} GetProjectsRequest */ /** @typedef {import("./types").GetProjectsResponse} GetProjectsResponse */ @@ -283,6 +284,19 @@ async function projectListReactPage(req, res, next) { ) } + // in v2 add notifications for matching university IPs + if (Settings.overleaf != null && req.ip !== user.lastLoginIp) { + NotificationsBuilder.promises + .ipMatcherAffiliation(user._id) + .create(req.ip) + .catch(err => { + logger.error( + { err }, + 'failed to create institutional IP match notification' + ) + }) + } + const hasPaidAffiliation = userAffiliations.some( affiliation => affiliation.licence && affiliation.licence !== 'free' )