Merge pull request #15084 from overleaf/ab-managers-users-ga

[web] Managed users general availability prep

GitOrigin-RevId: 9ab286a67c15f67e5d7617db506547b6ead8a9cb
This commit is contained in:
Alexandre Bourdin 2023-10-06 10:59:37 +02:00 committed by Copybot
parent 23e2d9bf99
commit 7268e0f0aa
4 changed files with 48 additions and 12 deletions

View file

@ -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 &&
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',

View file

@ -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: {

View file

@ -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) && (
<RowLink
href={`/manage/groups/${subscription._id}/settings`}
heading={t('manage_group_settings')}

View file

@ -0,0 +1,17 @@
exports.tags = ['saas']
exports.migrate = async client => {
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 } }
)
}