From ffe7ed35b136d89fa063db3b4936ea935a16783a Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Tue, 24 Jun 2025 14:33:46 +0200 Subject: [PATCH] Refactor AI assist notification logic in project list page (#26613) GitOrigin-RevId: 849ab62b814f321452e5d6e53d968943cec60417 --- .../Project/ProjectListController.mjs | 66 ++++++++++++++----- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/services/web/app/src/Features/Project/ProjectListController.mjs b/services/web/app/src/Features/Project/ProjectListController.mjs index b12d1c3cc9..24e0ae44e8 100644 --- a/services/web/app/src/Features/Project/ProjectListController.mjs +++ b/services/web/app/src/Features/Project/ProjectListController.mjs @@ -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),