Merge pull request #22142 from overleaf/jdt-enable-wf-on-commons

[Web] Toggle on Writefull commons targeting

GitOrigin-RevId: ede7f5397d1f110da006111ffcfd2eebb3626927
This commit is contained in:
Jimmy Domagala-Tang
2024-11-28 10:45:34 -05:00
committed by Copybot
parent 349b61257e
commit 4c011f74d9
2 changed files with 23 additions and 1 deletions
@@ -37,6 +37,7 @@ const FeaturesUpdater = require('../Subscription/FeaturesUpdater')
const SpellingHandler = require('../Spelling/SpellingHandler')
const { hasAdminAccess } = require('../Helpers/AdminAuthorizationHelper')
const InstitutionsFeatures = require('../Institutions/InstitutionsFeatures')
const InstitutionsGetter = require('../Institutions/InstitutionsGetter')
const ProjectAuditLogHandler = require('./ProjectAuditLogHandler')
const PublicAccessLevels = require('../Authorization/PublicAccessLevels')
const TagsHandler = require('../Tags/TagsHandler')
@@ -383,6 +384,12 @@ const _ProjectController = {
logger.error({ err, userId }, 'failed to get institution licence')
return false
}),
affiliations: InstitutionsGetter.promises
.getCurrentAffiliations(userId)
.catch(err => {
logger.error({ err, userId }, 'failed to get institution licence')
return false
}),
subscription:
SubscriptionLocator.promises.getUsersSubscription(userId),
isTokenMember: CollaboratorsGetter.promises.userIsTokenMember(
@@ -653,6 +660,7 @@ const _ProjectController = {
aiFeaturesAllowed = false
}
}
const canUseErrorAssistant =
user.features?.aiErrorAssistant ||
splitTestAssignments['ai-add-on']?.variant === 'enabled'
@@ -669,13 +677,21 @@ 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 &&
!userInNonIndividualSub
!userIsMemberOfGroupSubscription &&
!inEnterpriseCommons
) {
const { variant } = await SplitTestHandler.promises.getAssignment(
req,