From f6cbcc51d881f1a9cca21505c80af593fba28a95 Mon Sep 17 00:00:00 2001 From: Jimmy Domagala-Tang Date: Thu, 28 Nov 2024 10:45:34 -0500 Subject: [PATCH] Merge pull request #22142 from overleaf/jdt-enable-wf-on-commons [Web] Toggle on Writefull commons targeting GitOrigin-RevId: ede7f5397d1f110da006111ffcfd2eebb3626927 --- .../src/Features/Project/ProjectController.js | 18 +++++++++++++++++- .../unit/src/Project/ProjectControllerTests.js | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/services/web/app/src/Features/Project/ProjectController.js b/services/web/app/src/Features/Project/ProjectController.js index 51e1c18fae..1f44051c32 100644 --- a/services/web/app/src/Features/Project/ProjectController.js +++ b/services/web/app/src/Features/Project/ProjectController.js @@ -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, diff --git a/services/web/test/unit/src/Project/ProjectControllerTests.js b/services/web/test/unit/src/Project/ProjectControllerTests.js index 06d475ce3b..ca3801efd9 100644 --- a/services/web/test/unit/src/Project/ProjectControllerTests.js +++ b/services/web/test/unit/src/Project/ProjectControllerTests.js @@ -190,6 +190,11 @@ describe('ProjectController', function () { hasLicence: sinon.stub().resolves(false), }, } + this.InstitutionsGetter = { + promises: { + getCurrentAffiliations: sinon.stub().resolves([]), + }, + } this.SubscriptionViewModelBuilder = { getBestSubscription: sinon.stub().yields(null, { type: 'free' }), } @@ -256,6 +261,7 @@ describe('ProjectController', function () { }, }, '../Institutions/InstitutionsFeatures': this.InstitutionsFeatures, + '../Institutions/InstitutionsGetter': this.InstitutionsGetter, '../Survey/SurveyHandler': this.SurveyHandler, './ProjectAuditLogHandler': this.ProjectAuditLogHandler, '../Tutorial/TutorialHandler': this.TutorialHandler,