mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01: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:
@@ -26,6 +26,7 @@ const GeoIpLookup = require('../../infrastructure/GeoIpLookup')
|
||||
const SplitTestHandler = require('../SplitTests/SplitTestHandler')
|
||||
const SplitTestSessionHandler = require('../SplitTests/SplitTestSessionHandler')
|
||||
const SubscriptionLocator = require('../Subscription/SubscriptionLocator')
|
||||
const TutorialHandler = require('../Tutorial/TutorialHandler')
|
||||
|
||||
/**
|
||||
* @import { GetProjectsRequest, GetProjectsResponse, AllUsersProjects, MongoProject } from "./types"
|
||||
@@ -114,7 +115,7 @@ async function projectListPage(req, res, next) {
|
||||
const user = await User.findById(
|
||||
userId,
|
||||
`email emails features alphaProgram betaProgram lastPrimaryEmailCheck labsProgram signUpDate${
|
||||
isSaas ? ' enrollment writefull' : ''
|
||||
isSaas ? ' enrollment writefull completedTutorials' : ''
|
||||
}`
|
||||
)
|
||||
|
||||
@@ -351,8 +352,26 @@ async function projectListPage(req, res, next) {
|
||||
affiliation => affiliation.licence && affiliation.licence !== 'free'
|
||||
)
|
||||
|
||||
const inactiveTutorials = TutorialHandler.getInactiveTutorials(user)
|
||||
|
||||
const usGovBannerHooksResponse = await Modules.promises.hooks.fire(
|
||||
'getUSGovBanner',
|
||||
userEmails,
|
||||
hasPaidAffiliation,
|
||||
inactiveTutorials.includes('us-gov-banner')
|
||||
)
|
||||
|
||||
const usGovBanner = (usGovBannerHooksResponse &&
|
||||
usGovBannerHooksResponse[0]) || {
|
||||
showUSGovBanner: false,
|
||||
usGovBannerVariant: null,
|
||||
}
|
||||
|
||||
const { showUSGovBanner, usGovBannerVariant } = usGovBanner
|
||||
|
||||
const showGroupsAndEnterpriseBanner =
|
||||
Features.hasFeature('saas') &&
|
||||
!showUSGovBanner &&
|
||||
!userIsMemberOfGroupSubscription &&
|
||||
!hasPaidAffiliation
|
||||
|
||||
@@ -455,6 +474,8 @@ async function projectListPage(req, res, next) {
|
||||
prefetchedProjectsBlob,
|
||||
showGroupsAndEnterpriseBanner,
|
||||
groupsAndEnterpriseBannerVariant,
|
||||
showUSGovBanner,
|
||||
usGovBannerVariant,
|
||||
showWritefullPromoBanner,
|
||||
showLATAMBanner,
|
||||
recommendedCurrency,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ block append meta
|
||||
meta(name="ol-groupSubscriptionsPendingEnrollment" data-type="json" content=groupSubscriptionsPendingEnrollment)
|
||||
meta(name="ol-hasIndividualRecurlySubscription" data-type="boolean" content=hasIndividualRecurlySubscription)
|
||||
meta(name="ol-groupSsoSetupSuccess" data-type="boolean" content=groupSsoSetupSuccess)
|
||||
meta(name="ol-showUSGovBanner" data-type="boolean" content=showUSGovBanner)
|
||||
meta(name="ol-usGovBannerVariant" data-type="string" content=usGovBannerVariant)
|
||||
|
||||
block content
|
||||
main.content.content-alt.project-list-react#main-content
|
||||
|
||||
Reference in New Issue
Block a user