|
|
@@ -446,30 +446,6 @@ const _ProjectController = {
|
|
|
usedLatex,
|
|
|
} = userValues
|
|
|
|
|
|
- // check if a user is not in the writefull-oauth-promotion, in which case they may be part of the auto trial group
|
|
|
- if (
|
|
|
- !anonymous &&
|
|
|
- splitTestAssignments['writefull-oauth-promotion']?.variant === 'default'
|
|
|
- ) {
|
|
|
- // since we are auto-enrolling users into writefull if they are part of the group, we only want to
|
|
|
- // auto enroll (set writefull to true) if its the first time they have entered the test
|
|
|
- // this ensures that they can still turn writefull off (otherwise, we would be setting writefull on every time they access their projects)
|
|
|
- const { variant, metadata } =
|
|
|
- await SplitTestHandler.promises.getAssignment(
|
|
|
- req,
|
|
|
- res,
|
|
|
- 'writefull-auto-load'
|
|
|
- )
|
|
|
- if (variant === 'enabled' && metadata?.isFirstNonDefaultAssignment) {
|
|
|
- await UserUpdater.promises.updateUser(userId, {
|
|
|
- $set: {
|
|
|
- writefull: { enabled: true },
|
|
|
- },
|
|
|
- })
|
|
|
- user.writefull.enabled = true
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
const brandVariation = project?.brandVariationId
|
|
|
? await BrandVariationsHandler.promises.getBrandVariationById(
|
|
|
project.brandVariationId
|
|
|
@@ -636,16 +612,15 @@ const _ProjectController = {
|
|
|
!userIsMemberOfGroupSubscription &&
|
|
|
!userHasInstitutionLicence
|
|
|
|
|
|
- let showAiErrorAssistant = false
|
|
|
+ let aiFeaturesAllowed = false
|
|
|
if (userId && Features.hasFeature('saas')) {
|
|
|
try {
|
|
|
// exit early if the user couldnt use ai anyways, since permissions checks are expensive
|
|
|
- const canUseAiOnProject =
|
|
|
- user.features?.aiErrorAssistant &&
|
|
|
- (privilegeLevel === PrivilegeLevels.READ_AND_WRITE ||
|
|
|
- privilegeLevel === PrivilegeLevels.OWNER)
|
|
|
+ const canEditProject =
|
|
|
+ privilegeLevel === PrivilegeLevels.READ_AND_WRITE ||
|
|
|
+ privilegeLevel === PrivilegeLevels.OWNER
|
|
|
|
|
|
- if (canUseAiOnProject) {
|
|
|
+ if (canEditProject) {
|
|
|
// check permissions for user and project owner, to see if they allow AI on the project
|
|
|
const permissionsResults = await Modules.promises.hooks.fire(
|
|
|
'projectAllowsCapability',
|
|
|
@@ -657,11 +632,34 @@ const _ProjectController = {
|
|
|
result => result === true
|
|
|
)
|
|
|
|
|
|
- showAiErrorAssistant = aiAllowed
|
|
|
+ aiFeaturesAllowed = aiAllowed
|
|
|
}
|
|
|
} catch (err) {
|
|
|
// still allow users to access project if we cant get their permissions, but disable AI feature
|
|
|
- showAiErrorAssistant = false
|
|
|
+ aiFeaturesAllowed = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // check if a user has never tried writefull before (writefull.enabled will be null)
|
|
|
+ // if they previously accepted writefull. user.writefull will be true,
|
|
|
+ // if they explicitly disabled it, user.writefull will be false
|
|
|
+ if (aiFeaturesAllowed && user.writefull?.enabled === null) {
|
|
|
+ // since we are auto-enrolling users into writefull if they are part of the group, we only want to
|
|
|
+ // auto enroll (set writefull to true) if its the first time they have entered the test
|
|
|
+ // this ensures that they can still turn writefull off (otherwise, we would be setting writefull on every time they access their projects)
|
|
|
+ const { variant, metadata } =
|
|
|
+ await SplitTestHandler.promises.getAssignment(
|
|
|
+ req,
|
|
|
+ res,
|
|
|
+ 'writefull-auto-load'
|
|
|
+ )
|
|
|
+ if (variant === 'enabled' && metadata?.isFirstNonDefaultAssignment) {
|
|
|
+ await UserUpdater.promises.updateUser(userId, {
|
|
|
+ $set: {
|
|
|
+ writefull: { enabled: true },
|
|
|
+ },
|
|
|
+ })
|
|
|
+ user.writefull.enabled = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -693,7 +691,7 @@ const _ProjectController = {
|
|
|
features: user.features,
|
|
|
refProviders: _.mapValues(user.refProviders, Boolean),
|
|
|
writefull: {
|
|
|
- enabled: Boolean(user.writefull?.enabled),
|
|
|
+ enabled: Boolean(user.writefull?.enabled && aiFeaturesAllowed),
|
|
|
},
|
|
|
alphaProgram: user.alphaProgram,
|
|
|
betaProgram: user.betaProgram,
|
|
|
@@ -741,7 +739,9 @@ const _ProjectController = {
|
|
|
debugPdfDetach,
|
|
|
showSymbolPalette,
|
|
|
symbolPaletteAvailable: Features.hasFeature('symbol-palette'),
|
|
|
- showAiErrorAssistant,
|
|
|
+ userRestrictions: Array.from(req.userRestrictions || []),
|
|
|
+ showAiErrorAssistant:
|
|
|
+ aiFeaturesAllowed && user.features?.aiErrorAssistant,
|
|
|
detachRole,
|
|
|
metadata: { viewport: false },
|
|
|
showUpgradePrompt,
|