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

Merge pull request #23435 from overleaf/ii-flexible-group-licensing-add-seats-links

[web] Add seats links handling

GitOrigin-RevId: d53264277c24ec64b6ff7744b4d7e10a4234ac86
Liangjun Song 1 год назад
Родитель
Сommit
d66c11e786

+ 4 - 0
services/web/app/src/Features/UserMembership/UserMembershipController.mjs

@@ -38,6 +38,9 @@ async function manageGroupMembers(req, res, next) {
   )
 
   const plan = PlansLocator.findLocalPlanInSettings(subscription.planCode)
+  const userId = SessionManager.getLoggedInUserId(req.session)
+  const isAdmin = subscription.admin_id.toString() === userId
+  const canUseAddSeatsFeature = plan?.canUseFlexibleLicensing && isAdmin
 
   res.render('user_membership/group-members-react', {
     name: entityName,
@@ -47,6 +50,7 @@ async function manageGroupMembers(req, res, next) {
     managedUsersActive: subscription.managedUsersEnabled,
     groupSSOActive: ssoConfig?.enabled,
     canUseFlexibleLicensing: plan?.canUseFlexibleLicensing,
+    canUseAddSeatsFeature,
   })
 }
 

+ 1 - 0
services/web/app/views/user_membership/group-members-react.pug

@@ -11,6 +11,7 @@ block append meta
 	meta(name="ol-managedUsersActive", data-type="boolean", content=managedUsersActive)
 	meta(name="ol-groupSSOActive", data-type="boolean", content=groupSSOActive)
 	meta(name="ol-canUseFlexibleLicensing", data-type="boolean", content=canUseFlexibleLicensing)
+	meta(name="ol-canUseAddSeatsFeature", data-type="boolean", content=canUseAddSeatsFeature)
 
 block content
 	main.content.content-alt#subscription-manage-group-root

+ 13 - 7
services/web/frontend/js/features/group-management/components/group-members.tsx

@@ -32,6 +32,7 @@ export default function GroupMembers() {
   const groupName = getMeta('ol-groupName')
   const groupSize = getMeta('ol-groupSize')
   const canUseFlexibleLicensing = getMeta('ol-canUseFlexibleLicensing')
+  const canUseAddSeatsFeature = getMeta('ol-canUseAddSeatsFeature')
   const isFlexibleGroupLicensing =
     canUseFlexibleLicensing && isFlexibleGroupLicensingFeatureFlagEnabled
 
@@ -64,13 +65,18 @@ export default function GroupMembers() {
                   addedUsersSize: users.length,
                   groupSize,
                 })}
-          </strong>{' '}
-          <a
-            href="/user/subscription/group/add-users"
-            rel="noreferrer noopener"
-          >
-            {t('add_more_users')}.
-          </a>
+          </strong>
+          {canUseAddSeatsFeature && (
+            <>
+              {' '}
+              <a
+                href="/user/subscription/group/add-users"
+                rel="noreferrer noopener"
+              >
+                {t('add_more_users')}.
+              </a>
+            </>
+          )}
         </small>
       )
     }

+ 1 - 0
services/web/frontend/js/utils/meta.ts

@@ -62,6 +62,7 @@ export interface Meta {
   'ol-brandVariation': Record<string, any>
 
   // dynamic keys based on permissions
+  'ol-canUseAddSeatsFeature': boolean
   'ol-canUseFlexibleLicensing': boolean
   'ol-canUseFlexibleLicensingForConsolidatedPlans': boolean
   'ol-cannot-add-secondary-email': boolean

+ 21 - 0
services/web/test/frontend/features/group-management/components/group-members.spec.tsx

@@ -488,6 +488,7 @@ describe('GroupMembers', function () {
           'flexible-group-licensing': 'enabled',
         })
         win.metaAttributesCache.set('ol-canUseFlexibleLicensing', true)
+        win.metaAttributesCache.set('ol-canUseAddSeatsFeature', true)
       })
     })
 
@@ -533,5 +534,25 @@ describe('GroupMembers', function () {
         'You have 1 user and your plan supports up to 10. Add more users.'
       )
     })
+
+    it('renders the group members page without "add more users" link when not admin', function () {
+      cy.window().then(win => {
+        win.metaAttributesCache.set('ol-users', [this.JOHN_DOE])
+        win.metaAttributesCache.set('ol-canUseAddSeatsFeature', false)
+      })
+
+      cy.mount(
+        <SplitTestProvider>
+          <GroupMembersProvider>
+            <GroupMembers />
+          </GroupMembersProvider>
+        </SplitTestProvider>
+      )
+
+      cy.findByTestId('group-size-details').within(() => {
+        cy.findByText(/you have \d+ user and your plan supports up to \d+/i)
+        cy.findByText(/add more users/i).should('not.exist')
+      })
+    })
   })
 })

+ 1 - 0
services/web/test/unit/src/UserMembership/UserMembershipControllerTests.mjs

@@ -23,6 +23,7 @@ describe('UserMembershipController', function () {
     this.newUser = { _id: 'mock-new-user-id', email: 'new-user-email@foo.bar' }
     this.subscription = {
       _id: 'mock-subscription-id',
+      admin_id: 'mock-admin-id',
       fetchV1Data: callback => callback(null, this.subscription),
     }
     this.institution = {