Store ODC form results in onboardingDataCollection (#15609)

* registration/onboarding page

* show only if in split test group

* rate limiter, skip errors

* fix storybook logo

* remove skip payload

* fix typos

* prettier

* store ODC form results in onboardingDataCollection

* add userId

* prettier

* pick what properties should be stored

* remove unused props

* remove userId index

* update user profile

* update user profile

* use setOp

* added test

* remove userId from schema

* clean after user delete

* mock unit test

* limit to 255 chars

* updatedAt field

* prettier

* firstName, lastName as separate vars

* move subscribe at the end

* check if user exists

GitOrigin-RevId: 6d76927e97b5f4ed664ffb9b8806b3516c77eb9b
This commit is contained in:
Domagoj Kriskovic 2023-11-08 14:29:03 +01:00 committed by Copybot
parent 33981d7f91
commit 330a9c8e3a
5 changed files with 80 additions and 0 deletions

View file

@ -0,0 +1,45 @@
const {
OnboardingDataCollection,
} = require('../../models/OnboardingDataCollection')
const OError = require('@overleaf/o-error')
async function getOnboardingDataCollection(userId) {
try {
return await OnboardingDataCollection.findOne({ _id: userId }).exec()
} catch (error) {
throw OError.tag(error, 'Failed to get OnboardingDataCollection')
}
}
async function upsertOnboardingDataCollection({
userId,
firstName,
lastName,
usedLatex,
primaryOccupation,
updatedAt,
}) {
const odc = await OnboardingDataCollection.findOneAndUpdate(
{ _id: userId },
{
firstName,
lastName,
usedLatex,
primaryOccupation,
updatedAt,
},
{ upsert: true }
)
return odc
}
function deleteOnboardingDataCollection(id) {
return OnboardingDataCollection.deleteOne({ _id: id })
}
module.exports = {
getOnboardingDataCollection,
upsertOnboardingDataCollection,
deleteOnboardingDataCollection,
}

View file

@ -15,6 +15,7 @@ const UserSessionsManager = require('./UserSessionsManager')
const InstitutionsAPI = require('../Institutions/InstitutionsAPI')
const Modules = require('../../infrastructure/Modules')
const Errors = require('../Errors/Errors')
const OnboardingDataCollectionManager = require('../OnboardingDataCollection/OnboardingDataCollectionManager')
module.exports = {
deleteUser: callbackify(deleteUser),
@ -72,6 +73,7 @@ async function expireDeletedUser(userId) {
}).exec()
await Feedback.deleteMany({ userId }).exec()
await OnboardingDataCollectionManager.deleteOnboardingDataCollection(userId)
deletedUser.user = undefined
deletedUser.deleterData.deleterIpAddress = undefined

View file

@ -81,6 +81,9 @@ async function setupDb() {
db.userAuditLogEntries = internalDb.collection('userAuditLogEntries')
db.users = internalDb.collection('users')
db.userstubs = internalDb.collection('userstubs')
db.onboardingDataCollection = internalDb.collection(
'onboardingDataCollection'
)
}
async function getCollectionNames() {

View file

@ -0,0 +1,24 @@
const mongoose = require('../infrastructure/Mongoose')
const { Schema } = mongoose
const OnboardingDataCollectionSchema = new Schema(
{
firstName: { type: String, default: null },
lastName: { type: String, default: null },
primaryOccupation: { type: String, default: null },
usedLatex: { type: String, default: null },
updatedAt: { type: Date, default: Date.now },
},
{
collection: 'onboardingDataCollection',
minimize: false,
}
)
module.exports = {
OnboardingDataCollection: mongoose.model(
'OnboardingDataCollection',
OnboardingDataCollectionSchema
),
OnboardingDataCollectionSchema,
}

View file

@ -96,6 +96,10 @@ describe('UserDeleter', function () {
deleteMany: sinon.stub().returns({ exec: sinon.stub().resolves() }),
}
this.OnboardingDataCollectionManager = {
deleteOnboardingDataCollection: sinon.stub().resolves(),
}
this.UserDeleter = SandboxedModule.require(modulePath, {
requires: {
'../../models/User': { User },
@ -113,6 +117,8 @@ describe('UserDeleter', function () {
UserAuditLogEntry: this.UserAuditLogEntry,
},
'../../infrastructure/Modules': this.Modules,
'../OnboardingDataCollection/OnboardingDataCollectionManager':
this.OnboardingDataCollectionManager,
},
})
})