From 22b38d02b0448fe5fb65dfffce5bfbd2902bba76 Mon Sep 17 00:00:00 2001 From: ilkin-overleaf <100852799+ilkin-overleaf@users.noreply.github.com> Date: Wed, 8 Oct 2025 16:33:50 +0300 Subject: [PATCH] Merge pull request #28808 from overleaf/ii-await-user-handler [web] Promisify UserHandler GitOrigin-RevId: 2daa6f74ec566851d208bf1b3d12d89ecf183383 --- .../AuthenticationController.js | 6 ++---- .../web/app/src/Features/User/UserHandler.js | 19 +++++++++---------- .../AuthenticationControllerTests.js | 10 ++++++---- .../test/unit/src/User/UserHandlerTests.js | 10 ++++++---- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/services/web/app/src/Features/Authentication/AuthenticationController.js b/services/web/app/src/Features/Authentication/AuthenticationController.js index 99c418df1b..e33b2ce7d8 100644 --- a/services/web/app/src/Features/Authentication/AuthenticationController.js +++ b/services/web/app/src/Features/Authentication/AuthenticationController.js @@ -654,10 +654,8 @@ function _afterLoginSessionSetup(req, user, callback) { const _afterLoginSessionSetupAsync = promisify(_afterLoginSessionSetup) function _loginAsyncHandlers(req, user, anonymousAnalyticsId, isNewUser) { - UserHandler.populateTeamInvites(user, err => { - if (err != null) { - logger.warn({ err }, 'error setting up login data') - } + UserHandler.promises.populateTeamInvites(user).catch(err => { + logger.warn({ err }, 'error setting up login data') }) LoginRateLimiter.recordSuccessfulLogin(user.email, () => {}) AuthenticationController._recordSuccessfulLogin(user._id, () => {}) diff --git a/services/web/app/src/Features/User/UserHandler.js b/services/web/app/src/Features/User/UserHandler.js index cdd2e51431..e5c1d24986 100644 --- a/services/web/app/src/Features/User/UserHandler.js +++ b/services/web/app/src/Features/User/UserHandler.js @@ -1,14 +1,13 @@ -const { callbackify, promisify } = require('@overleaf/promise-utils') +const { callbackify } = require('util') const TeamInvitesHandler = require('../Subscription/TeamInvitesHandler') const { db, READ_PREFERENCE_SECONDARY, } = require('../../infrastructure/mongodb') -function populateTeamInvites(user, callback) { - TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail( - user.email, - callback +async function populateTeamInvites(user) { + return await TeamInvitesHandler.promises.createTeamInvitesForLegacyInvitedEmail( + user.email ) } @@ -22,10 +21,10 @@ async function countActiveUsers() { } module.exports = { - populateTeamInvites, + populateTeamInvites: callbackify(populateTeamInvites), countActiveUsers: callbackify(countActiveUsers), -} -module.exports.promises = { - populateTeamInvites: promisify(populateTeamInvites), - countActiveUsers, + promises: { + populateTeamInvites, + countActiveUsers, + }, } diff --git a/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js b/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js index 1fa3aba6a6..940ce1467a 100644 --- a/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js +++ b/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js @@ -94,7 +94,9 @@ describe('AuthenticationController', function () { }, }), '../User/UserHandler': (this.UserHandler = { - populateTeamInvites: sinon.stub(), + promises: { + populateTeamInvites: sinon.stub().resolves(), + }, }), '../Analytics/AnalyticsManager': (this.AnalyticsManager = { recordEventForUserInBackground: sinon.stub(), @@ -556,7 +558,7 @@ describe('AuthenticationController', function () { }) it('should not setup the user data in the background', function () { - this.UserHandler.populateTeamInvites.called.should.equal(false) + this.UserHandler.promises.populateTeamInvites.called.should.equal(false) }) it('should record a failed login', function () { @@ -1134,7 +1136,7 @@ describe('AuthenticationController', function () { this.AuthenticationController._clearRedirectFromSession = sinon.stub() this.AuthenticationController._redirectToReconfirmPage = sinon.stub() this.UserSessionsManager.trackSession = sinon.stub() - this.UserHandler.populateTeamInvites = sinon.stub() + this.UserHandler.promises.populateTeamInvites = sinon.stub().resolves() this.LoginRateLimiter.recordSuccessfulLogin = sinon.stub() this.AuthenticationController._recordSuccessfulLogin = sinon.stub() this.AnalyticsManager.recordEvent = sinon.stub() @@ -1461,7 +1463,7 @@ describe('AuthenticationController', function () { }) it('should setup the user data in the background', function () { - this.UserHandler.populateTeamInvites + this.UserHandler.promises.populateTeamInvites .calledWith(this.user) .should.equal(true) }) diff --git a/services/web/test/unit/src/User/UserHandlerTests.js b/services/web/test/unit/src/User/UserHandlerTests.js index e990ccaf90..66dc524395 100644 --- a/services/web/test/unit/src/User/UserHandlerTests.js +++ b/services/web/test/unit/src/User/UserHandlerTests.js @@ -12,7 +12,9 @@ describe('UserHandler', function () { } this.TeamInvitesHandler = { - createTeamInvitesForLegacyInvitedEmail: sinon.stub().yields(), + promises: { + createTeamInvitesForLegacyInvitedEmail: sinon.stub().resolves(), + }, } this.db = { @@ -30,12 +32,12 @@ describe('UserHandler', function () { }) describe('populateTeamInvites', function () { - beforeEach(function (done) { - this.UserHandler.populateTeamInvites(this.user, done) + beforeEach(async function () { + await this.UserHandler.promises.populateTeamInvites(this.user) }) it('notifies the user about legacy team invites', function () { - this.TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail + this.TeamInvitesHandler.promises.createTeamInvitesForLegacyInvitedEmail .calledWith(this.user.email) .should.eq(true) })