diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index 0c98a253ce..fa18ac1743 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionController.js @@ -18,8 +18,9 @@ const { expressify } = require('../../util/promises') const OError = require('@overleaf/o-error') const SplitTestHandler = require('../SplitTests/SplitTestHandler') const SubscriptionHelper = require('./SubscriptionHelper') -const Features = require('../../infrastructure/Features') const AuthorizationManager = require('../Authorization/AuthorizationManager') +const Modules = require('../../infrastructure/Modules') +const async = require('async') const groupPlanModalOptions = Settings.groupPlanModalOptions const validGroupPlanModalOptions = { @@ -251,15 +252,30 @@ async function userSubscriptionPage(req, res) { const groupPlansDataForDash = formatGroupPlansDataForDash() // display the Group Settings button only to admins of group subscriptions with the Managed Users feature available - const groupSettingsEnabledFor = (managedGroupSubscriptions || []) - .filter( - subscription => - Features.hasFeature('saas') && - subscription?.features?.managedUsers && - (subscription.admin_id._id || subscription.admin_id).toString() === + let groupSettingsEnabledFor + try { + const managedGroups = await async.filter( + managedGroupSubscriptions || [], + async subscription => { + const results = await Modules.promises.hooks.fire( + 'hasManagedUsersFeature', + subscription + ) + const isGroupAdmin = + (subscription.admin_id._id || subscription.admin_id).toString() === user._id.toString() + return results?.[0] === true && isGroupAdmin + } ) - .map(subscription => subscription._id.toString()) + groupSettingsEnabledFor = managedGroups.map(subscription => + subscription._id.toString() + ) + } catch (error) { + logger.error( + { err: error }, + 'Failed to list groups with group settings enabled' + ) + } const data = { title: 'your_subscription', diff --git a/services/web/app/src/models/Subscription.js b/services/web/app/src/models/Subscription.js index 77e3be8799..510df031d7 100644 --- a/services/web/app/src/models/Subscription.js +++ b/services/web/app/src/models/Subscription.js @@ -32,8 +32,8 @@ const SubscriptionSchema = new Schema( membersLimit: { type: Number, default: 0 }, customAccount: Boolean, features: { - managedUsers: { type: Boolean, default: false }, - groupSSO: { type: Boolean, default: false }, + managedUsers: { type: Boolean, default: null }, + groupSSO: { type: Boolean, default: null }, }, overleaf: { id: { diff --git a/services/web/frontend/js/features/subscription/components/dashboard/managed-group-subscriptions.tsx b/services/web/frontend/js/features/subscription/components/dashboard/managed-group-subscriptions.tsx index de06196d8e..2aa38b4c73 100644 --- a/services/web/frontend/js/features/subscription/components/dashboard/managed-group-subscriptions.tsx +++ b/services/web/frontend/js/features/subscription/components/dashboard/managed-group-subscriptions.tsx @@ -11,7 +11,10 @@ export default function ManagedGroupSubscriptions() { return null } - const groupSettingsEnabledFor = getMeta('ol-groupSettingsEnabledFor', []) + const groupSettingsEnabledFor = getMeta( + 'ol-groupSettingsEnabledFor', + [] + ) as string[] return ( <> @@ -52,7 +55,7 @@ export default function ManagedGroupSubscriptions() { subtext={t('manage_managers_subtext')} icon="manage_accounts" /> - {groupSettingsEnabledFor.includes(subscription._id) && ( + {groupSettingsEnabledFor?.includes(subscription._id) && ( { + const { db } = client + await db.subscriptions.updateMany( + { 'features.managedUsers': { $ne: true } }, + { $set: { 'features.managedUsers': null } } + ) +} + +exports.rollback = async client => { + const { db } = client + await db.subscriptions.updateMany( + { 'features.managedUsers': { $eq: null } }, + { $set: { 'features.managedUsers': false } } + ) +}