Merge pull request #14380 from overleaf/jdt-history-onboarding-saves

save onboarding completion on user

GitOrigin-RevId: bcb4d9d1909aa11e5cfcf283e04fe1057460bf7b
This commit is contained in:
Jimmy Domagala-Tang 2023-08-29 15:04:27 -04:00 committed by Copybot
parent 3d9e9f6aeb
commit 3bb7a7c7ba
5 changed files with 44 additions and 1 deletions

View file

@ -437,7 +437,7 @@ const ProjectController = {
)
User.findById(
userId,
'email first_name last_name referal_id signUpDate featureSwitches features featuresEpoch refProviders alphaProgram betaProgram isAdmin ace labsProgram',
'email first_name last_name referal_id signUpDate featureSwitches features featuresEpoch refProviders alphaProgram betaProgram isAdmin ace labsProgram completedTutorials',
(err, user) => {
// Handle case of deleted user
if (user == null) {
@ -877,6 +877,7 @@ const ProjectController = {
alphaProgram: user.alphaProgram,
betaProgram: user.betaProgram,
labsProgram: user.labsProgram,
completedTutorials: user.completedTutorials,
isAdmin: hasAdminAccess(user),
},
userSettings: {

View file

@ -0,0 +1,21 @@
const SessionManager = require('../Authentication/SessionManager')
const TutorialHandler = require('./TutorialHandler')
const { expressify } = require('../../util/promises')
const VALID_KEYS = ['react-history-buttons-tutorial']
async function completeTutorial(req, res, next) {
const userId = SessionManager.getLoggedInUserId(req.session)
const tutorialKey = req.params.tutorialKey
if (!VALID_KEYS.includes(tutorialKey)) {
return res.sendStatus(400)
}
await TutorialHandler.saveCompletion(userId, tutorialKey)
res.sendStatus(204)
}
module.exports = {
completeTutorial: expressify(completeTutorial),
}

View file

@ -0,0 +1,13 @@
const UserUpdater = require('../User/UserUpdater')
async function saveCompletion(userId, tutorialKey) {
const completionDate = new Date()
await UserUpdater.promises.updateUser(userId, {
$set: {
[`completedTutorials.${tutorialKey}`]: completionDate,
},
})
}
module.exports = { saveCompletion }

View file

@ -187,6 +187,7 @@ const UserSchema = new Schema(
splitTests: Schema.Types.Mixed,
analyticsId: { type: String },
surveyResponses: Schema.Types.Mixed,
completedTutorials: Schema.Types.Mixed,
},
{ minimize: false }
)

View file

@ -21,6 +21,7 @@ const UserInfoController = require('./Features/User/UserInfoController')
const UserController = require('./Features/User/UserController')
const UserEmailsController = require('./Features/User/UserEmailsController')
const UserPagesController = require('./Features/User/UserPagesController')
const TutorialController = require('./Features/Tutorial/TutorialController')
const DocumentController = require('./Features/Documents/DocumentController')
const CompileManager = require('./Features/Compile/CompileManager')
const CompileController = require('./Features/Compile/CompileController')
@ -427,6 +428,12 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
TpdsController.getQueues
)
webRouter.post(
'/tutorial/:tutorialKey/complete',
AuthenticationController.requireLogin(),
TutorialController.completeTutorial
)
webRouter.get(
'/user/projects',
AuthenticationController.requireLogin(),