mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #15084 from overleaf/ab-managers-users-ga
[web] Managed users general availability prep GitOrigin-RevId: 9ab286a67c15f67e5d7617db506547b6ead8a9cb
This commit is contained in:
parent
23e2d9bf99
commit
7268e0f0aa
4 changed files with 48 additions and 12 deletions
|
@ -18,8 +18,9 @@ const { expressify } = require('../../util/promises')
|
||||||
const OError = require('@overleaf/o-error')
|
const OError = require('@overleaf/o-error')
|
||||||
const SplitTestHandler = require('../SplitTests/SplitTestHandler')
|
const SplitTestHandler = require('../SplitTests/SplitTestHandler')
|
||||||
const SubscriptionHelper = require('./SubscriptionHelper')
|
const SubscriptionHelper = require('./SubscriptionHelper')
|
||||||
const Features = require('../../infrastructure/Features')
|
|
||||||
const AuthorizationManager = require('../Authorization/AuthorizationManager')
|
const AuthorizationManager = require('../Authorization/AuthorizationManager')
|
||||||
|
const Modules = require('../../infrastructure/Modules')
|
||||||
|
const async = require('async')
|
||||||
|
|
||||||
const groupPlanModalOptions = Settings.groupPlanModalOptions
|
const groupPlanModalOptions = Settings.groupPlanModalOptions
|
||||||
const validGroupPlanModalOptions = {
|
const validGroupPlanModalOptions = {
|
||||||
|
@ -251,15 +252,30 @@ async function userSubscriptionPage(req, res) {
|
||||||
const groupPlansDataForDash = formatGroupPlansDataForDash()
|
const groupPlansDataForDash = formatGroupPlansDataForDash()
|
||||||
|
|
||||||
// display the Group Settings button only to admins of group subscriptions with the Managed Users feature available
|
// display the Group Settings button only to admins of group subscriptions with the Managed Users feature available
|
||||||
const groupSettingsEnabledFor = (managedGroupSubscriptions || [])
|
let groupSettingsEnabledFor
|
||||||
.filter(
|
try {
|
||||||
subscription =>
|
const managedGroups = await async.filter(
|
||||||
Features.hasFeature('saas') &&
|
managedGroupSubscriptions || [],
|
||||||
subscription?.features?.managedUsers &&
|
async subscription => {
|
||||||
|
const results = await Modules.promises.hooks.fire(
|
||||||
|
'hasManagedUsersFeature',
|
||||||
|
subscription
|
||||||
|
)
|
||||||
|
const isGroupAdmin =
|
||||||
(subscription.admin_id._id || subscription.admin_id).toString() ===
|
(subscription.admin_id._id || subscription.admin_id).toString() ===
|
||||||
user._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 = {
|
const data = {
|
||||||
title: 'your_subscription',
|
title: 'your_subscription',
|
||||||
|
|
|
@ -32,8 +32,8 @@ const SubscriptionSchema = new Schema(
|
||||||
membersLimit: { type: Number, default: 0 },
|
membersLimit: { type: Number, default: 0 },
|
||||||
customAccount: Boolean,
|
customAccount: Boolean,
|
||||||
features: {
|
features: {
|
||||||
managedUsers: { type: Boolean, default: false },
|
managedUsers: { type: Boolean, default: null },
|
||||||
groupSSO: { type: Boolean, default: false },
|
groupSSO: { type: Boolean, default: null },
|
||||||
},
|
},
|
||||||
overleaf: {
|
overleaf: {
|
||||||
id: {
|
id: {
|
||||||
|
|
|
@ -11,7 +11,10 @@ export default function ManagedGroupSubscriptions() {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const groupSettingsEnabledFor = getMeta('ol-groupSettingsEnabledFor', [])
|
const groupSettingsEnabledFor = getMeta(
|
||||||
|
'ol-groupSettingsEnabledFor',
|
||||||
|
[]
|
||||||
|
) as string[]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -52,7 +55,7 @@ export default function ManagedGroupSubscriptions() {
|
||||||
subtext={t('manage_managers_subtext')}
|
subtext={t('manage_managers_subtext')}
|
||||||
icon="manage_accounts"
|
icon="manage_accounts"
|
||||||
/>
|
/>
|
||||||
{groupSettingsEnabledFor.includes(subscription._id) && (
|
{groupSettingsEnabledFor?.includes(subscription._id) && (
|
||||||
<RowLink
|
<RowLink
|
||||||
href={`/manage/groups/${subscription._id}/settings`}
|
href={`/manage/groups/${subscription._id}/settings`}
|
||||||
heading={t('manage_group_settings')}
|
heading={t('manage_group_settings')}
|
||||||
|
|
|
@ -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 } }
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in a new issue