diff --git a/services/web/app/src/Features/Subscription/FeaturesUpdater.js b/services/web/app/src/Features/Subscription/FeaturesUpdater.js index 91e8ef4e23..1eb948fc86 100644 --- a/services/web/app/src/Features/Subscription/FeaturesUpdater.js +++ b/services/web/app/src/Features/Subscription/FeaturesUpdater.js @@ -96,12 +96,11 @@ async function computeFeatures(userId) { bonusFeatures, featuresOverrides, ]) - const features = _.reduce( + return _.reduce( featureSets, FeaturesHelper.mergeFeatures, Settings.defaultFeatures ) - return features } async function _getIndividualFeatures(userId) { @@ -131,12 +130,7 @@ async function _getFeaturesOverrides(user) { activeFeaturesOverrides.push(featuresOverride.features) } } - const features = _.reduce( - activeFeaturesOverrides, - FeaturesHelper.mergeFeatures, - {} - ) - return features + return _.reduce(activeFeaturesOverrides, FeaturesHelper.mergeFeatures, {}) } async function _getV1Features(user) { diff --git a/services/web/scripts/refresh_features.js b/services/web/scripts/refresh_features.js index acbc8f1c74..3c25846bdb 100644 --- a/services/web/scripts/refresh_features.js +++ b/services/web/scripts/refresh_features.js @@ -5,6 +5,10 @@ const async = require('async') const FeaturesUpdater = require('../app/src/Features/Subscription/FeaturesUpdater') const FeaturesHelper = require('../app/src/Features/Subscription/FeaturesHelper') const UserFeaturesUpdater = require('../app/src/Features/Subscription/UserFeaturesUpdater') +const AnalyticsManager = require('../app/src/Features/Analytics/AnalyticsManager') +const DropboxHandler = require('../modules/dropbox/app/src/DropboxHandler') +const { OError } = require('../app/src/Features/Errors/Errors') +const logger = require('@overleaf/logger') const ScriptLogger = { checkedUsersCount: 0, @@ -76,7 +80,44 @@ const checkAndUpdateUser = (user, callback) => return callback() } - UserFeaturesUpdater.overrideFeatures(user._id, freshFeatures, callback) + const matchedFeatureSet = FeaturesHelper.getMatchedFeatureSet(freshFeatures) + AnalyticsManager.setUserPropertyForUser( + user._id, + 'feature-set', + matchedFeatureSet + ) + + UserFeaturesUpdater.overrideFeatures( + user._id, + freshFeatures, + (error, featuresChanged) => { + if (error) { + return callback(error) + } + if ( + mismatchReasons.dropbox !== undefined && + freshFeatures.dropbox === false + ) { + DropboxHandler.unlinkAccount( + user._id, + { sendEmail: false }, + error => { + if (error) { + return callback( + OError.tag(error, 'error unlinking dropbox', { + userId: user._id, + }) + ) + } + logger.log({ userId: user._id }, 'Unlinked dropbox') + callback(null, featuresChanged) + } + ) + } else { + callback(null, featuresChanged) + } + } + ) }) const checkAndUpdateUsers = (users, callback) =>