Просмотр исходного кода

Merge pull request #17166 from overleaf/ab-fix-group-settings-label

[web] Cleanup managed users env var and fix group settings label

GitOrigin-RevId: 817ed86a6c94c03adb41e8c10115d6404180142e
Jessica Lawshe 2 лет назад
Родитель
Сommit
d5639794c2

+ 10 - 14
services/web/app/src/Features/Subscription/plansFeatures.js

@@ -243,6 +243,16 @@ const groupPlans = [
           organization: true,
           organization: true,
         },
         },
       },
       },
+      {
+        feature: 'managed_users_accounts',
+        info: 'managed_users_accounts_plan_info',
+        value: 'bool',
+        plans: {
+          group_standard: false,
+          group_professional: true,
+          organization: false,
+        },
+      },
       {
       {
         feature: 'sso_integration',
         feature: 'sso_integration',
         info: 'sso_integration_info',
         info: 'sso_integration_info',
@@ -636,20 +646,6 @@ const studentPlans = [
   },
   },
 ]
 ]
 
 
-if (Settings.managedUsers?.enabled) {
-  const row = 2
-  groupPlans[1].items.splice(row, 0, {
-    feature: 'managed_users_accounts',
-    info: 'managed_users_accounts_plan_info',
-    value: 'bool',
-    plans: {
-      group_standard: false,
-      group_professional: true,
-      organization: false,
-    },
-  })
-}
-
 module.exports = {
 module.exports = {
   individual: individualPlans,
   individual: individualPlans,
   group: groupPlans,
   group: groupPlans,

+ 1 - 0
services/web/app/src/infrastructure/ExpressLocals.js

@@ -420,6 +420,7 @@ module.exports = function (webRouter, privateApiRouter, publicApiRouter) {
       cookieDomain: Settings.cookieDomain,
       cookieDomain: Settings.cookieDomain,
       templateLinks: Settings.templateLinks,
       templateLinks: Settings.templateLinks,
       labsEnabled: Settings.labs && Settings.labs.enable,
       labsEnabled: Settings.labs && Settings.labs.enable,
+      groupSSOEnabled: Settings.groupSSO?.enabled,
     }
     }
     next()
     next()
   })
   })

+ 12 - 2
services/web/frontend/js/features/subscription/components/dashboard/group-settings-button.tsx

@@ -1,5 +1,7 @@
 import { RowLink } from '@/features/subscription/components/dashboard/row-link'
 import { RowLink } from '@/features/subscription/components/dashboard/row-link'
+import getMeta from '@/utils/meta'
 import { useTranslation } from 'react-i18next'
 import { useTranslation } from 'react-i18next'
+import { ExposedSettings } from '../../../../../../types/exposed-settings'
 import { ManagedGroupSubscription } from '../../../../../../types/subscription/dashboard/subscription'
 import { ManagedGroupSubscription } from '../../../../../../types/subscription/dashboard/subscription'
 
 
 export default function GroupSettingsButton({
 export default function GroupSettingsButton({
@@ -9,8 +11,16 @@ export default function GroupSettingsButton({
 }) {
 }) {
   const { t } = useTranslation()
   const { t } = useTranslation()
 
 
-  const subscriptionHasGroupSSO = subscription?.features?.groupSSO
-  const subscriptionHasManagedUsers = subscription?.features?.managedUsers
+  const { groupSSOEnabled } = getMeta(
+    'ol-ExposedSettings',
+    {}
+  ) as ExposedSettings
+
+  const subscriptionHasManagedUsers =
+    subscription.features?.managedUsers !== false
+  const subscriptionHasGroupSSO =
+    subscription.features?.groupSSO === true ||
+    (groupSSOEnabled && subscription.features?.groupSSO === null)
 
 
   let groupSettingRowSubText = ''
   let groupSettingRowSubText = ''
   if (subscriptionHasGroupSSO && subscriptionHasManagedUsers) {
   if (subscriptionHasGroupSSO && subscriptionHasManagedUsers) {

+ 208 - 57
services/web/test/frontend/features/subscription/components/dashboard/managed-group-subscriptions.test.tsx

@@ -12,7 +12,10 @@ import {
 } from '../../helpers/render-with-subscription-dash-context'
 } from '../../helpers/render-with-subscription-dash-context'
 import { UserId } from '../../../../../../types/user'
 import { UserId } from '../../../../../../types/user'
 
 
-function getManagedGroupSubscription(groupSSO: boolean, managedUsers: boolean) {
+function getManagedGroupSubscriptions(
+  groupSSO: boolean | null,
+  managedUsers: boolean | null
+): ManagedGroupSubscription[] {
   const subscriptionOne = {
   const subscriptionOne = {
     ...groupActiveSubscription,
     ...groupActiveSubscription,
     userIsGroupMember: true,
     userIsGroupMember: true,
@@ -44,13 +47,15 @@ function getManagedGroupSubscription(groupSSO: boolean, managedUsers: boolean) {
 }
 }
 
 
 const managedGroupSubscriptions: ManagedGroupSubscription[] =
 const managedGroupSubscriptions: ManagedGroupSubscription[] =
-  getManagedGroupSubscription(false, false)
+  getManagedGroupSubscriptions(false, false)
 const managedGroupSubscriptions2: ManagedGroupSubscription[] =
 const managedGroupSubscriptions2: ManagedGroupSubscription[] =
-  getManagedGroupSubscription(true, true)
+  getManagedGroupSubscriptions(true, true)
 const managedGroupSubscriptions3: ManagedGroupSubscription[] =
 const managedGroupSubscriptions3: ManagedGroupSubscription[] =
-  getManagedGroupSubscription(true, false)
+  getManagedGroupSubscriptions(true, false)
 const managedGroupSubscriptions4: ManagedGroupSubscription[] =
 const managedGroupSubscriptions4: ManagedGroupSubscription[] =
-  getManagedGroupSubscription(false, true)
+  getManagedGroupSubscriptions(false, true)
+const managedGroupSubscriptions5: ManagedGroupSubscription[] =
+  getManagedGroupSubscriptions(null, true)
 
 
 describe('<ManagedGroupSubscriptions />', function () {
 describe('<ManagedGroupSubscriptions />', function () {
   afterEach(function () {
   afterEach(function () {
@@ -122,63 +127,209 @@ describe('<ManagedGroupSubscriptions />', function () {
       .be.null
       .be.null
   })
   })
 
 
-  it('renders the Manage group settings row when feature is turned on', async function () {
-    renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
-      metaTags: [
-        {
-          name: 'ol-managedGroupSubscriptions',
-          value: managedGroupSubscriptions2,
-        },
-        {
-          name: 'ol-groupSettingsEnabledFor',
-          value: [managedGroupSubscriptions2[0]._id],
-        },
-      ],
+  describe('with group SSO off by default', function () {
+    beforeEach(function () {
+      window.metaAttributesCache.set('ol-ExposedSettings', {
+        groupSSOEnabled: false,
+      })
     })
     })
-    await screen.findAllByText('Manage group settings')
-    await screen.findAllByText('Configure and manage SSO and Managed Users')
-  })
 
 
-  it('renders the the correct subText for Manage Group settings row', async function () {
-    renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
-      metaTags: [
-        {
-          name: 'ol-managedGroupSubscriptions',
-          value: managedGroupSubscriptions2,
-        },
-        {
-          name: 'ol-groupSettingsEnabledFor',
-          value: [managedGroupSubscriptions2[0]._id],
-        },
-      ],
+    it('renders the Manage group settings row when feature is turned on', async function () {
+      renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
+        metaTags: [
+          {
+            name: 'ol-managedGroupSubscriptions',
+            value: managedGroupSubscriptions2,
+          },
+          {
+            name: 'ol-groupSettingsEnabledFor',
+            value: [managedGroupSubscriptions2[0]._id],
+          },
+        ],
+      })
+      await screen.findAllByText('Manage group settings')
+      await screen.findAllByText('Configure and manage SSO and Managed Users')
     })
     })
-    await screen.findAllByText('Configure and manage SSO and Managed Users')
 
 
-    renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
-      metaTags: [
-        {
-          name: 'ol-managedGroupSubscriptions',
-          value: managedGroupSubscriptions3,
-        },
-        {
-          name: 'ol-groupSettingsEnabledFor',
-          value: [managedGroupSubscriptions3[0]._id],
-        },
-      ],
+    describe('renders the the correct subText for Manage Group settings row', async function () {
+      it('with managedUsers.enabled=true and groupSSO.enabled=true', async function () {
+        renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
+          metaTags: [
+            {
+              name: 'ol-managedGroupSubscriptions',
+              value: managedGroupSubscriptions2,
+            },
+            {
+              name: 'ol-groupSettingsEnabledFor',
+              value: [managedGroupSubscriptions2[0]._id],
+            },
+          ],
+        })
+        await screen.findAllByText('Configure and manage SSO and Managed Users')
+      })
+
+      it('with managedUsers.enabled=false and groupSSO.enabled=true', async function () {
+        renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
+          metaTags: [
+            {
+              name: 'ol-managedGroupSubscriptions',
+              value: managedGroupSubscriptions3,
+            },
+            {
+              name: 'ol-groupSettingsEnabledFor',
+              value: [managedGroupSubscriptions3[0]._id],
+            },
+          ],
+        })
+        await screen.findAllByText('Configure and manage SSO')
+      })
+
+      it('with managedUsers.enabled=true and groupSSO.enabled=false', async function () {
+        renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
+          metaTags: [
+            {
+              name: 'ol-managedGroupSubscriptions',
+              value: managedGroupSubscriptions4,
+            },
+            {
+              name: 'ol-groupSettingsEnabledFor',
+              value: [managedGroupSubscriptions4[0]._id],
+            },
+          ],
+        })
+        await screen.findAllByText('Turn on Managed Users')
+      })
+
+      it('with managedUsers.enabled=true and groupSSO.enabled=null', async function () {
+        renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
+          metaTags: [
+            {
+              name: 'ol-managedGroupSubscriptions',
+              value: managedGroupSubscriptions5,
+            },
+            {
+              name: 'ol-groupSettingsEnabledFor',
+              value: [managedGroupSubscriptions5[0]._id],
+            },
+          ],
+        })
+        await screen.findAllByText('Turn on Managed Users')
+      })
     })
     })
-    await screen.findAllByText('Configure and manage SSO')
-    renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
-      metaTags: [
-        {
-          name: 'ol-managedGroupSubscriptions',
-          value: managedGroupSubscriptions4,
-        },
-        {
-          name: 'ol-groupSettingsEnabledFor',
-          value: [managedGroupSubscriptions4[0]._id],
-        },
-      ],
+  })
+
+  describe('with group SSO on by default', function () {
+    it('renders the Manage group settings row when features are turned on', async function () {
+      renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
+        metaTags: [
+          {
+            name: 'ol-managedGroupSubscriptions',
+            value: managedGroupSubscriptions2,
+          },
+          {
+            name: 'ol-groupSettingsEnabledFor',
+            value: [managedGroupSubscriptions2[0]._id],
+          },
+          {
+            name: 'ol-ExposedSettings',
+            value: {
+              groupSSOEnabled: true,
+            },
+          },
+        ],
+      })
+      await screen.findAllByText('Manage group settings')
+      await screen.findAllByText('Configure and manage SSO and Managed Users')
+    })
+
+    describe('renders the the correct subText for Manage Group settings row', async function () {
+      it('with managedUsers.enabled=true and groupSSO.enabled=true', async function () {
+        renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
+          metaTags: [
+            {
+              name: 'ol-managedGroupSubscriptions',
+              value: managedGroupSubscriptions2,
+            },
+            {
+              name: 'ol-groupSettingsEnabledFor',
+              value: [managedGroupSubscriptions2[0]._id],
+            },
+            {
+              name: 'ol-ExposedSettings',
+              value: {
+                groupSSOEnabled: true,
+              },
+            },
+          ],
+        })
+        await screen.findAllByText('Configure and manage SSO and Managed Users')
+      })
+
+      it('with managedUsers.enabled=false and groupSSO.enabled=true', async function () {
+        renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
+          metaTags: [
+            {
+              name: 'ol-managedGroupSubscriptions',
+              value: managedGroupSubscriptions3,
+            },
+            {
+              name: 'ol-groupSettingsEnabledFor',
+              value: [managedGroupSubscriptions3[0]._id],
+            },
+            {
+              name: 'ol-ExposedSettings',
+              value: {
+                groupSSOEnabled: true,
+              },
+            },
+          ],
+        })
+        await screen.findAllByText('Configure and manage SSO')
+      })
+
+      it('with managedUsers.enabled=true and groupSSO.enabled=false', async function () {
+        renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
+          metaTags: [
+            {
+              name: 'ol-managedGroupSubscriptions',
+              value: managedGroupSubscriptions4,
+            },
+            {
+              name: 'ol-groupSettingsEnabledFor',
+              value: [managedGroupSubscriptions4[0]._id],
+            },
+            {
+              name: 'ol-ExposedSettings',
+              value: {
+                groupSSOEnabled: true,
+              },
+            },
+          ],
+        })
+        await screen.findAllByText('Turn on Managed Users')
+      })
+
+      it('with managedUsers.enabled=true and groupSSO.enabled=null', async function () {
+        renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
+          metaTags: [
+            {
+              name: 'ol-managedGroupSubscriptions',
+              value: managedGroupSubscriptions5,
+            },
+            {
+              name: 'ol-groupSettingsEnabledFor',
+              value: [managedGroupSubscriptions5[0]._id],
+            },
+            {
+              name: 'ol-ExposedSettings',
+              value: {
+                groupSSOEnabled: true,
+              },
+            },
+          ],
+        })
+        await screen.findAllByText('Configure and manage SSO and Managed Users')
+      })
     })
     })
-    await screen.findAllByText('Turn on Managed Users')
   })
   })
 })
 })

+ 2 - 0
services/web/types/exposed-settings.ts

@@ -45,4 +45,6 @@ export type ExposedSettings = {
   fileIgnorePattern: string
   fileIgnorePattern: string
   templateLinks?: TemplateLink[]
   templateLinks?: TemplateLink[]
   labsEnabled: boolean
   labsEnabled: boolean
+  managedUsersEnabled?: boolean
+  groupSSOEnabled?: boolean
 }
 }

+ 2 - 2
services/web/types/subscription/dashboard/subscription.ts

@@ -78,8 +78,8 @@ export type ManagedGroupSubscription = Omit<GroupSubscription, 'admin_id'> & {
   planLevelName: string
   planLevelName: string
   admin_id: User
   admin_id: User
   features: {
   features: {
-    groupSSO: boolean
-    managedUsers: boolean
+    groupSSO: boolean | null
+    managedUsers: boolean | null
   }
   }
 }
 }