mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-26 18:51:50 +02:00
adding a function to trim the staffAccess for subscription page (#29640)
GitOrigin-RevId: ee030df2fb7df19a1b719311772b454983c2394f
This commit is contained in:
@@ -172,6 +172,39 @@ function formatGroupPlansDataForDash() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim the staffAccess object to only include allowed fields
|
||||
* @param {Object} user - The user object with mongoose object fields
|
||||
* @returns {Object} - User object with trimmed staffAccess
|
||||
*/
|
||||
function _trimStaffAccess(user) {
|
||||
if (!user || !user.staffAccess) return user
|
||||
|
||||
const allowedFields = [
|
||||
'publisherMetrics',
|
||||
'publisherManagement',
|
||||
'institutionMetrics',
|
||||
'institutionManagement',
|
||||
'groupMetrics',
|
||||
'groupManagement',
|
||||
'adminMetrics',
|
||||
'splitTestMetrics',
|
||||
'splitTestManagement',
|
||||
]
|
||||
|
||||
const trimmedStaffAccess = allowedFields.reduce((acc, key) => {
|
||||
if (key in user.staffAccess) {
|
||||
acc[key] = user.staffAccess[key]
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
return {
|
||||
...user,
|
||||
staffAccess: trimmedStaffAccess,
|
||||
}
|
||||
}
|
||||
|
||||
async function userSubscriptionPage(req, res) {
|
||||
const user = SessionManager.getSessionUser(req.session)
|
||||
await SplitTestHandler.promises.getAssignment(req, res, 'pause-subscription')
|
||||
@@ -304,7 +337,7 @@ async function userSubscriptionPage(req, res) {
|
||||
title: 'your_subscriptions',
|
||||
plans: plansData?.plans,
|
||||
planCodesChangingAtTermEnd: plansData?.planCodesChangingAtTermEnd,
|
||||
user,
|
||||
user: _trimStaffAccess(user),
|
||||
hasSubscription,
|
||||
fromPlansPage,
|
||||
redirectedPaymentErrorCode,
|
||||
|
||||
Reference in New Issue
Block a user