From 19d1904a3fe87485756d0fe59cbb039da86aabd6 Mon Sep 17 00:00:00 2001 From: Jimmy Domagala-Tang Date: Wed, 17 Sep 2025 10:30:01 -0400 Subject: [PATCH] feat: move wf trial logic to new function and enable enterprise commons to auto-load (#28134) GitOrigin-RevId: 959d305fa694a6e09a04cb79920af2fc0c14e862 --- .../Features/Project/ProjectController.mjs | 77 +++++++++++++------ 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/services/web/app/src/Features/Project/ProjectController.mjs b/services/web/app/src/Features/Project/ProjectController.mjs index a322eab9da..61e27f4325 100644 --- a/services/web/app/src/Features/Project/ProjectController.mjs +++ b/services/web/app/src/Features/Project/ProjectController.mjs @@ -707,30 +707,13 @@ const _ProjectController = { }) } - let inEnterpriseCommons = false - const affiliations = userValues.affiliations || [] - for (const affiliation of affiliations) { - inEnterpriseCommons = - inEnterpriseCommons || affiliation.institution?.enterpriseCommons - } - - // check if a user has never tried writefull before (writefull.enabled will be null) - // if they previously accepted writefull, or are have been already assigned to a trial, user.writefull will be true, - // if they explicitly disabled it, user.writefull will be false - if ( - aiFeaturesAllowed && - user.writefull?.enabled === null && - !userIsMemberOfGroupSubscription && - !inEnterpriseCommons - ) { - await UserUpdater.promises.updateUser(userId, { - $set: { - writefull: { enabled: true, autoCreatedAccount: true }, - }, - }) - user.writefull.enabled = true - user.writefull.autoCreatedAccount = true - } + await ProjectController._setWritefullTrialState( + user, + userValues, + userId, + aiFeaturesAllowed, + userIsMemberOfGroupSubscription + ) const template = detachRole === 'detached' @@ -1147,6 +1130,51 @@ const _ProjectController = { } return portalTemplates }, + + async _setWritefullTrialState( + user, + userValues, + userId, + aiFeaturesAllowed, + userIsMemberOfGroupSubscription + ) { + let inEnterpriseCommons = false + const affiliations = userValues.affiliations || [] + for (const affiliation of affiliations) { + inEnterpriseCommons = + inEnterpriseCommons || affiliation.institution?.enterpriseCommons + } + + // check if a user has never tried writefull before (writefull.enabled will be null) + // if they previously accepted writefull, or are have been already assigned to a trial, user.writefull will be true, + // if they explicitly disabled it, user.writefull will be false + const shouldPushWritefull = + aiFeaturesAllowed && + user.writefull?.enabled === null && + !userIsMemberOfGroupSubscription + + // we dont have legal approval to push enterprise commons into WF auto-account-create, but we are able to auto-load it into the toolbar + const shouldAutoCreateAccount = shouldPushWritefull && !inEnterpriseCommons + const shouldAutoLoad = shouldPushWritefull && inEnterpriseCommons + + if (shouldAutoCreateAccount) { + await UserUpdater.promises.updateUser(userId, { + $set: { + writefull: { enabled: true, autoCreatedAccount: true }, + }, + }) + user.writefull.enabled = true + user.writefull.autoCreatedAccount = true + } else if (shouldAutoLoad) { + await UserUpdater.promises.updateUser(userId, { + $set: { + writefull: { enabled: true, autoCreatedAccount: false }, + }, + }) + user.writefull.enabled = true + user.writefull.autoCreatedAccount = false + } + }, } const defaultSettingsForAnonymousUser = userId => ({ @@ -1259,6 +1287,7 @@ const ProjectController = { _refreshFeatures: _ProjectController._refreshFeatures, _getPaywallPlansPrices: _ProjectController._getPaywallPlansPrices, _getAddonPrices: _ProjectController._getAddonPrices, + _setWritefullTrialState: _ProjectController._setWritefullTrialState, } export default ProjectController