mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-08 08:39:03 +02:00
Merge pull request #20371 from overleaf/mf-us-gov-banner
[web] Add US gov banner based on inclusion and exclusion criteria GitOrigin-RevId: c45ed280c8ef2dbdf9f3b84488e767c06fcc1ae1
This commit is contained in:
@@ -10,6 +10,7 @@ const VALID_KEYS = [
|
||||
'ai-error-assistant-consent',
|
||||
'code-editor-mode-prompt',
|
||||
'history-restore-promo',
|
||||
'us-gov-banner',
|
||||
]
|
||||
|
||||
async function completeTutorial(req, res, next) {
|
||||
@@ -27,12 +28,21 @@ async function completeTutorial(req, res, next) {
|
||||
async function postponeTutorial(req, res, next) {
|
||||
const userId = SessionManager.getLoggedInUserId(req.session)
|
||||
const tutorialKey = req.params.tutorialKey
|
||||
let postponedUntil
|
||||
if (req.body.postponedUntil) {
|
||||
postponedUntil = new Date(req.body.postponedUntil)
|
||||
}
|
||||
|
||||
if (!VALID_KEYS.includes(tutorialKey)) {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
|
||||
await TutorialHandler.setTutorialState(userId, tutorialKey, 'postponed')
|
||||
await TutorialHandler.setTutorialState(
|
||||
userId,
|
||||
tutorialKey,
|
||||
'postponed',
|
||||
postponedUntil
|
||||
)
|
||||
res.sendStatus(204)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,26 @@ const POSTPONE_DURATION_MS = 24 * 60 * 60 * 1000 // 1 day
|
||||
* @param {string} userId
|
||||
* @param {string} tutorialKey
|
||||
* @param {'completed' | 'postponed'} state
|
||||
* @param {Date} [postponedUntil] - The date until which the tutorial is postponed
|
||||
*/
|
||||
async function setTutorialState(userId, tutorialKey, state) {
|
||||
async function setTutorialState(
|
||||
userId,
|
||||
tutorialKey,
|
||||
state,
|
||||
postponedUntil = null
|
||||
) {
|
||||
const updateData = {
|
||||
state,
|
||||
updatedAt: new Date(),
|
||||
}
|
||||
|
||||
if (state === 'postponed' && postponedUntil) {
|
||||
updateData.postponedUntil = postponedUntil
|
||||
}
|
||||
|
||||
await UserUpdater.promises.updateUser(userId, {
|
||||
$set: {
|
||||
[`completedTutorials.${tutorialKey}`]: { state, updatedAt: new Date() },
|
||||
[`completedTutorials.${tutorialKey}`]: updateData,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -29,9 +44,11 @@ function getInactiveTutorials(user, tutorialKey) {
|
||||
// Legacy format: single date means the tutorial was completed
|
||||
inactiveTutorials.push(key)
|
||||
} else if (record.state === 'postponed') {
|
||||
const postponedUntil = new Date(
|
||||
const defaultPostponedUntil = new Date(
|
||||
record.updatedAt.getTime() + POSTPONE_DURATION_MS
|
||||
)
|
||||
|
||||
const postponedUntil = record.postponedUntil ?? defaultPostponedUntil
|
||||
if (new Date() < postponedUntil) {
|
||||
inactiveTutorials.push(key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user