mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 18:20:09 +02:00
Refactor AI assist notification logic in project list page (#26613)
GitOrigin-RevId: 849ab62b814f321452e5d6e53d968943cec60417
This commit is contained in:
committed by
Copybot
parent
1fe9b486da
commit
ffe7ed35b1
@@ -411,24 +411,17 @@ async function projectListPage(req, res, next) {
|
||||
'papers-notification-banner'
|
||||
)
|
||||
|
||||
await SplitTestHandler.promises.getAssignment(
|
||||
req,
|
||||
res,
|
||||
'ai-assist-notification'
|
||||
)
|
||||
const aiAssistNotificationAssignment =
|
||||
await SplitTestHandler.promises.getAssignment(
|
||||
req,
|
||||
res,
|
||||
'ai-assist-notification'
|
||||
)
|
||||
|
||||
const canUseAi = await PermissionsManager.promises.checkUserPermissions(
|
||||
user,
|
||||
['use-ai']
|
||||
)
|
||||
const assistantDisabled = user.aiErrorAssistant?.enabled === false // the assistant has been manually disabled by the user
|
||||
const subscription =
|
||||
await SubscriptionLocator.promises.getUsersSubscription(userId)
|
||||
const hasManuallyCollectedSubscription =
|
||||
subscription?.collectionMethod === 'manual'
|
||||
const canUseAiAssist =
|
||||
canUseAi && !hasManuallyCollectedSubscription && !assistantDisabled
|
||||
const hasAiAssist = user.features?.aiErrorAssistant
|
||||
let showAiAssistNotification = false
|
||||
if (aiAssistNotificationAssignment.variant !== 'default') {
|
||||
showAiAssistNotification = await _showAiAssistNotification(user)
|
||||
}
|
||||
|
||||
const customerIoEnabled =
|
||||
await SplitTestHandler.promises.hasUserBeenAssignedToVariant(
|
||||
@@ -471,7 +464,7 @@ async function projectListPage(req, res, next) {
|
||||
hasIndividualPaidSubscription,
|
||||
userRestrictions: Array.from(req.userRestrictions || []),
|
||||
customerIoEnabled,
|
||||
showAiAssistNotification: canUseAiAssist && !hasAiAssist,
|
||||
showAiAssistNotification,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -756,6 +749,43 @@ function _hasActiveFilter(filters) {
|
||||
)
|
||||
}
|
||||
|
||||
async function _showAiAssistNotification(user) {
|
||||
// Check if the assistant has been manually disabled by the user
|
||||
if (user.aiErrorAssistant?.enabled === false) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check if the user can use AI features (policy check)
|
||||
const canUseAi = await PermissionsManager.promises.checkUserPermissions(
|
||||
user,
|
||||
['use-ai']
|
||||
)
|
||||
if (!canUseAi) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check if the user has a subscription with manually collected group admins (#22822)
|
||||
const subscription = await SubscriptionLocator.promises.getUsersSubscription(
|
||||
user._id
|
||||
)
|
||||
if (subscription?.collectionMethod === 'manual') {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check if the user already has AI Assist via Overleaf
|
||||
if (user.features?.aiErrorAssistant) {
|
||||
return false
|
||||
}
|
||||
// Check if the user already has AI Assist via Writefull
|
||||
const { isPremium: hasAiAssistViaWritefull } =
|
||||
await UserGetter.promises.getWritefullData(user._id)
|
||||
if (hasAiAssistViaWritefull) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
export default {
|
||||
projectListPage: expressify(projectListPage),
|
||||
getProjectsJson: expressify(getProjectsJson),
|
||||
|
||||
Reference in New Issue
Block a user