Merge pull request #5330 from overleaf/ab-analytics-middleware-passport-id

Fix passport user id reference in analytics ID middleware

GitOrigin-RevId: 7d237a6f358b5632c672aafd6e1e72ab53d8650f
This commit is contained in:
Timothée Alby 2021-10-04 14:28:33 +02:00 committed by Copybot
parent 0c7946f30c
commit 7c384d5f26
2 changed files with 5 additions and 5 deletions

View file

@ -232,7 +232,7 @@ async function analyticsIdMiddleware(req, res, next) {
if (sessionUser) {
// ensure `session.analyticsId` is set to the user's `analyticsId`, and fallback to their `userId` for pre-analyticsId users
session.analyticsId = sessionUser.analyticsId || sessionUser.userId
session.analyticsId = sessionUser.analyticsId || sessionUser._id
} else if (!session.analyticsId) {
// generate an `analyticsId` if needed
session.analyticsId = uuid.v4()

View file

@ -198,7 +198,7 @@ describe('AnalyticsManager', function () {
it('sets session.analyticsId with a logged in user in session having an analyticsId', async function () {
this.req.session.user = {
userId: this.userId,
_id: this.userId,
analyticsId: this.analyticsId,
}
await this.AnalyticsManager.analyticsIdMiddleware(
@ -211,7 +211,7 @@ describe('AnalyticsManager', function () {
it('sets session.analyticsId with a legacy user session without an analyticsId', async function () {
this.req.session.user = {
userId: this.userId,
_id: this.userId,
analyticsId: undefined,
}
await this.AnalyticsManager.analyticsIdMiddleware(
@ -224,7 +224,7 @@ describe('AnalyticsManager', function () {
it('updates session.analyticsId with a legacy user session without an analyticsId if different', async function () {
this.req.session.user = {
userId: this.userId,
_id: this.userId,
analyticsId: undefined,
}
this.req.analyticsId = 'foo'
@ -238,7 +238,7 @@ describe('AnalyticsManager', function () {
it('does not update session.analyticsId with a legacy user session without an analyticsId if same', async function () {
this.req.session.user = {
userId: this.userId,
_id: this.userId,
analyticsId: undefined,
}
this.req.analyticsId = this.userId