diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index a45682807b..149c3ac993 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionController.js @@ -435,6 +435,7 @@ async function successfulSubscription(req, res) { title: 'thank_you', personalSubscription, postCheckoutRedirect, + user, }) } } @@ -469,6 +470,7 @@ async function canceledSubscription(req, res, next) { ) return res.render('subscriptions/canceled-subscription-react', { title: 'subscription_canceled', + user: SessionManager.getSessionUser(req.session), }) } diff --git a/services/web/app/src/Features/Subscription/TeamInvitesController.mjs b/services/web/app/src/Features/Subscription/TeamInvitesController.mjs index b575c94ff8..5b94ea0a95 100644 --- a/services/web/app/src/Features/Subscription/TeamInvitesController.mjs +++ b/services/web/app/src/Features/Subscription/TeamInvitesController.mjs @@ -65,8 +65,8 @@ async function createInvite(req, res, next) { async function viewInvite(req, res, next) { const { token } = req.params - const userId = SessionManager.getLoggedInUserId(req.session) - + const sessionUser = SessionManager.getSessionUser(req.session) + const userId = sessionUser?._id const { invite, subscription } = await TeamInvitesHandler.promises.getInvite(token) @@ -102,13 +102,13 @@ async function viewInvite(req, res, next) { await subscription.populate('groupPolicy') } - const user = await UserGetter.promises.getUser(userId) + const dbUser = await UserGetter.promises.getUser(userId) const isUserEnrolledInDifferentGroup = ( await Modules.promises.hooks.fire( 'isUserEnrolledInDifferentGroup', - user.enrollment, + dbUser.enrollment, subscription._id ) )?.[0] === true @@ -122,7 +122,7 @@ async function viewInvite(req, res, next) { validationStatus = await PermissionsManager.promises.getUserValidationStatus({ - user, + user: dbUser, groupPolicy: subscription.groupPolicy, subscription, }) @@ -143,6 +143,7 @@ async function viewInvite(req, res, next) { currentManagedUserAdminEmail, groupSSOActive, subscriptionId: subscription._id.toString(), + user: sessionUser, }) } else { let currentManagedUserAdminEmail @@ -162,6 +163,7 @@ async function viewInvite(req, res, next) { currentManagedUserAdminEmail, groupSSOActive, subscriptionId: subscription._id.toString(), + user: sessionUser, }) } } else { @@ -175,18 +177,18 @@ async function viewInvite(req, res, next) { appName: settings.appName, accountExists: userByEmail != null, emailAddress: invite.email, + user: { id: null }, }) } } async function viewInvites(req, res, next) { - const userId = SessionManager.getLoggedInUserId(req.session) - const userEmail = await UserGetter.promises.getUserEmail(userId) + const user = SessionManager.getSessionUser(req.session) const groupSubscriptions = - await SubscriptionLocator.promises.getGroupsWithTeamInvitesEmail(userEmail) + await SubscriptionLocator.promises.getGroupsWithTeamInvitesEmail(user.email) const teamInvites = groupSubscriptions.map(groupSubscription => - groupSubscription.teamInvites.find(invite => invite.email === userEmail) + groupSubscription.teamInvites.find(invite => invite.email === user.email) ) await SplitTestHandler.promises.getAssignment( @@ -197,6 +199,7 @@ async function viewInvites(req, res, next) { return res.render('subscriptions/team/group-invites', { teamInvites, + user, }) } diff --git a/services/web/app/views/subscriptions/canceled-subscription-react.pug b/services/web/app/views/subscriptions/canceled-subscription-react.pug index 16e5283f7c..6cc23c396b 100644 --- a/services/web/app/views/subscriptions/canceled-subscription-react.pug +++ b/services/web/app/views/subscriptions/canceled-subscription-react.pug @@ -1,4 +1,4 @@ -extends ../layout-marketing +extends ../layout-react block vars - bootstrap5PageStatus = 'enabled' // One of 'disabled', 'enabled', and 'queryStringOnly' @@ -7,5 +7,8 @@ block vars block entrypointVar - entrypoint = 'pages/user/subscription/canceled-subscription' +block append meta + meta(name="ol-user" data-type="json" content=user) + block content main.content.content-alt#subscription-canceled-root diff --git a/services/web/app/views/subscriptions/dashboard-react.pug b/services/web/app/views/subscriptions/dashboard-react.pug index 068f52de0a..69f71fbc99 100644 --- a/services/web/app/views/subscriptions/dashboard-react.pug +++ b/services/web/app/views/subscriptions/dashboard-react.pug @@ -1,4 +1,4 @@ -extends ../layout-marketing +extends ../layout-react block vars - bootstrap5PageStatus = 'enabled' // One of 'disabled', 'enabled', and 'queryStringOnly' diff --git a/services/web/app/views/subscriptions/successful-subscription-react.pug b/services/web/app/views/subscriptions/successful-subscription-react.pug index 0d82346b6f..1506eb9af0 100644 --- a/services/web/app/views/subscriptions/successful-subscription-react.pug +++ b/services/web/app/views/subscriptions/successful-subscription-react.pug @@ -1,4 +1,4 @@ -extends ../layout-marketing +extends ../layout-react block vars - bootstrap5PageStatus = 'enabled' // One of 'disabled', 'enabled', and 'queryStringOnly' @@ -10,6 +10,7 @@ block entrypointVar block append meta meta(name="ol-subscription" data-type="json" content=personalSubscription) meta(name="ol-postCheckoutRedirect" content=postCheckoutRedirect) + meta(name="ol-user" data-type="json" content=user) block content main.content.content-alt#subscription-success-root diff --git a/services/web/app/views/subscriptions/team/group-invites.pug b/services/web/app/views/subscriptions/team/group-invites.pug index c9da04d293..2bfc74040b 100644 --- a/services/web/app/views/subscriptions/team/group-invites.pug +++ b/services/web/app/views/subscriptions/team/group-invites.pug @@ -1,4 +1,4 @@ -extends ../../layout-marketing +extends ../../layout-react block vars - bootstrap5PageStatus = 'enabled' // One of 'disabled', 'enabled', and 'queryStringOnly' @@ -9,6 +9,7 @@ block entrypointVar block append meta meta(name="ol-teamInvites" data-type="json" content=teamInvites) + meta(name="ol-user" data-type="json" content=user) block content main.content.content-alt.team-invite#group-invites-root diff --git a/services/web/app/views/subscriptions/team/invite-managed.pug b/services/web/app/views/subscriptions/team/invite-managed.pug index 8260db2562..9d20d09b23 100644 --- a/services/web/app/views/subscriptions/team/invite-managed.pug +++ b/services/web/app/views/subscriptions/team/invite-managed.pug @@ -1,4 +1,4 @@ -extends ../../layout-marketing +extends ../../layout-react block vars - bootstrap5PageStatus = 'enabled' // One of 'disabled', 'enabled', and 'queryStringOnly' @@ -16,6 +16,7 @@ block append meta meta(name="ol-currentManagedUserAdminEmail" data-type="string" content=currentManagedUserAdminEmail) meta(name="ol-groupSSOActive" data-type="boolean" content=groupSSOActive) meta(name="ol-subscriptionId" data-type="string" content=subscriptionId) + meta(name="ol-user" data-type="json" content=user) block content main.content.content-alt.team-invite#invite-managed-root diff --git a/services/web/app/views/subscriptions/team/invite.pug b/services/web/app/views/subscriptions/team/invite.pug index c5ff57528b..f68f3d5306 100644 --- a/services/web/app/views/subscriptions/team/invite.pug +++ b/services/web/app/views/subscriptions/team/invite.pug @@ -1,4 +1,4 @@ -extends ../../layout-marketing +extends ../../layout-react block vars - bootstrap5PageStatus = 'enabled' // One of 'disabled', 'enabled', and 'queryStringOnly' @@ -9,12 +9,13 @@ block entrypointVar block append meta meta(name="ol-hasIndividualRecurlySubscription" data-type="boolean" content=hasIndividualRecurlySubscription) - meta(name="ol-inviterName" date-type="string" content=inviterName) + meta(name="ol-inviterName" data-type="string" content=inviterName) meta(name="ol-inviteToken" data-type="string" content=inviteToken) meta(name="ol-currentManagedUserAdminEmail" data-type="string" content=currentManagedUserAdminEmail) meta(name="ol-expired" data-type="boolean" content=expired) meta(name="ol-groupSSOActive" data-type="boolean" content=groupSSOActive) meta(name="ol-subscriptionId" data-type="string" content=subscriptionId) + meta(name="ol-user" data-type="json" content=user) block content main.content.content-alt#invite-root diff --git a/services/web/app/views/subscriptions/team/invite_logged_out.pug b/services/web/app/views/subscriptions/team/invite_logged_out.pug index cac4cc37cd..61be2196ce 100644 --- a/services/web/app/views/subscriptions/team/invite_logged_out.pug +++ b/services/web/app/views/subscriptions/team/invite_logged_out.pug @@ -1,9 +1,12 @@ -extends ../../layout-marketing +extends ../../layout-react block vars - bootstrap5PageStatus = 'enabled' // One of 'disabled', 'enabled', and 'queryStringOnly' - bootstrap5PageSplitTest = 'bootstrap-5-subscription' +block append meta + meta(name="ol-user" data-type="json" content=user) + block content - var colClass = bootstrapVersion === 5 ? 'col-lg-8 m-auto' : 'col-md-8 col-md-offset-2' diff --git a/services/web/frontend/js/pages/user/subscription/base.js b/services/web/frontend/js/pages/user/subscription/base.js index b3085bad99..fb28e97f95 100644 --- a/services/web/frontend/js/pages/user/subscription/base.js +++ b/services/web/frontend/js/pages/user/subscription/base.js @@ -5,3 +5,4 @@ import './../../../i18n' import '../../../features/event-tracking' import '../../../features/cookie-banner' import '../../../features/link-helpers/slow-link' +import '../../../features/header-footer-react' diff --git a/services/web/frontend/js/shared/context/user-context.tsx b/services/web/frontend/js/shared/context/user-context.tsx index 9ea7e8daa8..598455a5a9 100644 --- a/services/web/frontend/js/shared/context/user-context.tsx +++ b/services/web/frontend/js/shared/context/user-context.tsx @@ -1,8 +1,10 @@ import { createContext, FC, useContext, useMemo } from 'react' import getMeta from '../../utils/meta' -import { User } from '../../../../types/user' +import { LoggedOutUser, User } from '../../../../types/user' -export const UserContext = createContext(undefined) +export const UserContext = createContext( + undefined +) export const UserProvider: FC = ({ children }) => { const user = useMemo(() => getMeta('ol-user'), []) diff --git a/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js b/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js index 10ade4d33b..89416370a0 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js @@ -1017,6 +1017,7 @@ describe('SubscriptionController', function () { title: 'thank_you', personalSubscription: 'foo', postCheckoutRedirect: undefined, + user: this.user, }) done() } diff --git a/services/web/types/user.ts b/services/web/types/user.ts index c8714f8a24..5cb6459a83 100644 --- a/services/web/types/user.ts +++ b/services/web/types/user.ts @@ -33,7 +33,7 @@ export type FeatureUsage = { } export type User = { - id: UserId | null + id: UserId isAdmin?: boolean email: string allowedFreeTrial?: boolean @@ -54,4 +54,20 @@ export type User = { featureUsage?: FeatureUsage } +export type LoggedOutUser = { + id: null + email?: undefined + first_name?: undefined + last_name?: undefined + signUpDate?: undefined + labsProgram?: undefined + alphaProgram?: undefined + betaProgram?: undefined + allowedFreeTrial?: undefined + features?: undefined + refProviders?: undefined + writefull?: undefined + isAdmin?: undefined +} + export type MongoUser = Pick> & { _id: string }