#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Give saas_team_extensions.max_seats one meaning (#7932)
ConnorYohec9c21ae19f2
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/service/UserLicenseSettingsService.java b/app/proprietary/src/main/java/stirling/software/proprietary/service/UserLicenseSettingsService.javaindex 3a3118eed4..bc6ec825fa 100644--- a/app/proprietary/src/main/java/stirling/software/proprietary/service/UserLicenseSettingsService.java+++ b/app/proprietary/src/main/java/stirling/software/proprietary/service/UserLicenseSettingsService.java@@ -45,7 +45,14 @@ import stirling.software.proprietary.security.service.UserService;@RequiredArgsConstructorpublic class UserLicenseSettingsService {- private static final int DEFAULT_USER_LIMIT = 5;+ /**+ * Users an installation gets before it has to buy capacity. The one free-allowance number in+ * Java: the saas seat reader floors on it, and {@code+ * pricing_policy.server_free_user_allowance} is seeded to match so the two editions quote the+ * same figure.+ */+ public static final int DEFAULT_USER_LIMIT = 5;+private static final String SIGNATURE_SEPARATOR = ":";private static final String DEFAULT_INTEGRITY_SECRET = "stirling-pdf-user-license-guard";@@ -302,12 +309,14 @@ public class UserLicenseSettingsService {** <ul>* <li>Grandfathered limit = max(5, existing user count at V1→V2 migration)- * <li>No license: Uses grandfathered limit only+ * <li>No license, not linked: Uses grandfathered limit only+ * <li>No license, linked: max(grandfathered limit, the linked team's allowance)* <li>SERVER license (maxUsers=0): Unlimited users (Integer.MAX_VALUE)* <li>ENTERPRISE license (maxUsers>0): License seats only (NO grandfathering added)* </ul>*- * <p>IMPORTANT: Paid licenses REPLACE the limit, they don't add to grandfathering.+ * <p>IMPORTANT: Paid licenses REPLACE the limit, they don't add to grandfathering. A linked+ * team's allowance does not: linking is monotonic, so it can only raise the ceiling.** @return Maximum number of users allowed (Integer.MAX_VALUE for unlimited)*/@@ -329,8 +338,16 @@ public class UserLicenseSettingsService {if (!hasPaidLicense()) {Integer fromSaas = linkedTeamAllowance();if (fromSaas != null) {- log.debug("No licence; linked team allowance: {} users", fromSaas);- return fromSaas;+ // Floored at the grandfathered limit, so linking can only raise the ceiling.+ // Otherwise a solo cloud account, whose team the instance binds to before any+ // invitation is accepted, hands back its own seat count and refuses every user.+ int allowed = Math.max(grandfatheredLimit, fromSaas);+ log.debug(+ "No licence; linked team allowance {} against grandfathered {}: {} users",+ fromSaas,+ grandfatheredLimit,+ allowed);+ return allowed;}log.debug("No license: using grandfathered limit of {}", grandfatheredLimit);return grandfatheredLimit;diff --git a/app/proprietary/src/test/java/stirling/software/proprietary/service/UserLicenseSettingsServiceMoreTest.java b/app/proprietary/src/test/java/stirling/software/proprietary/service/UserLicenseSettingsServiceMoreTest.javaindex b681740986..420f54e95d 100644--- a/app/proprietary/src/test/java/stirling/software/proprietary/service/UserLicenseSettingsServiceMoreTest.java+++ b/app/proprietary/src/test/java/stirling/software/proprietary/service/UserLicenseSettingsServiceMoreTest.java@@ -159,6 +159,42 @@ class UserLicenseSettingsServiceMoreTest {assertThat(service.calculateMaxAllowedUsers()).isEqualTo(7);}++ /**+ * users.team_id points at the personal team until an invitation is accepted, so a solo+ * cloud account's own team size must not become the instance's ceiling.+ */+ @Test+ @DisplayName("a SaaS allowance below the grandfathered limit does not lower it")+ void lowerAllowanceDoesNotShrinkTheInstance() {+ lockedSettings(7);+ cacheReturns(withAllowance(1));++ assertThat(service.calculateMaxAllowedUsers()).isEqualTo(7);+ }++ @Test+ @DisplayName("a SaaS allowance above the grandfathered limit raises it")+ void higherAllowanceRaisesTheCeiling() {+ lockedSettings(7);+ cacheReturns(withAllowance(100));++ assertThat(service.calculateMaxAllowedUsers()).isEqualTo(100);+ }++ /**+ * The grandfathered count is re-floored at the default on every read, so the floor holds+ * even for an instance that never had more than the free allowance.+ */+ @Test+ @DisplayName("a SaaS allowance below the default never drops the instance under it")+ void neverBelowTheDefault() {+ lockedSettings(UserLicenseSettingsService.DEFAULT_USER_LIMIT);+ cacheReturns(withAllowance(1));++ assertThat(service.calculateMaxAllowedUsers())+ .isEqualTo(UserLicenseSettingsService.DEFAULT_USER_LIMIT);+ }}@Nesteddiff --git a/app/saas/src/main/java/stirling/software/saas/accountlink/InstanceController.java b/app/saas/src/main/java/stirling/software/saas/accountlink/InstanceController.javaindex ecb8d0ecd1..501aad7316 100644--- a/app/saas/src/main/java/stirling/software/saas/accountlink/InstanceController.java+++ b/app/saas/src/main/java/stirling/software/saas/accountlink/InstanceController.java@@ -231,18 +231,13 @@ public class InstanceController {}/**- * Users the team's Team plan covers, or null when it has no user limit.- *- * <p>Read from the seat cap the subscription writes, so the instance and the cloud team enforce- * one number. {@code Integer.MAX_VALUE} is the historic "unlimited" sentinel and becomes null- * here: the wire contract expresses no-limit as absence, so nothing downstream can accidentally- * do arithmetic on it.+ * Users the team's Team plan covers, or null when it has no user limit. Read from the seat cap+ * the subscription writes, so the instance and the cloud team enforce one number.*/private Integer licensedUsers(Long teamId) {return teamExtensionsRepository.findByTeamId(teamId)- .map(SaasTeamExtensions::getMaxSeats)- .filter(max -> max != null && max > 0 && max < Integer.MAX_VALUE)+ .map(SaasTeamExtensions::licensedUsers).orElse(null);}diff --git a/app/saas/src/main/java/stirling/software/saas/model/SaasTeamExtensions.java b/app/saas/src/main/java/stirling/software/saas/model/SaasTeamExtensions.javaindex 1c5c0a08c0..ca6ed81006 100644--- a/app/saas/src/main/java/stirling/software/saas/model/SaasTeamExtensions.java+++ b/app/saas/src/main/java/stirling/software/saas/model/SaasTeamExtensions.java@@ -23,6 +23,7 @@ import lombok.NoArgsConstructor;import lombok.Setter;import stirling.software.proprietary.model.Team;+import stirling.software.proprietary.service.UserLicenseSettingsService;/*** Saas-only sidecar that holds the seat / billing / personal-team metadata for a {@link Team}.@@ -66,13 +67,14 @@ public class SaasTeamExtensions implements Serializable {private Boolean isPersonal = Boolean.FALSE;@Column(name = "seat_count", nullable = false)- private Integer seatCount = 1;+ private Integer seatCount = UserLicenseSettingsService.DEFAULT_USER_LIMIT;@Column(name = "seats_used", nullable = false)private Integer seatsUsed = 0;+ /** Defaults to the free allowance, rows being created before anything is bought. */@Column(name = "max_seats", nullable = false)- private Integer maxSeats = 1;+ private Integer maxSeats = UserLicenseSettingsService.DEFAULT_USER_LIMIT;@Column(name = "created_by_user_id")private Long createdByUserId;@@ -100,8 +102,8 @@ public class SaasTeamExtensions implements Serializable {}/**- * Whether this team has unused seats. Personal teams enforce a 1-seat limit; standard teams are- * unlimited.+ * Whether this team has unused seats. Personal teams are bound by {@code max_seats}; standard+ * teams are unlimited, because cloud capacity is not enforced yet.*/public boolean hasAvailableSeats() {if (isPersonal()) {@@ -111,10 +113,34 @@ public class SaasTeamExtensions implements Serializable {}/**- * Whether this team accepts new invitations. Personal teams (1 seat, owned by one user) never- * do; standard teams always do.+ * Whether this team accepts new invitations. Personal teams (a single user's own team) never+ * do; standard teams always do. The first invitation converts the team rather than being+ * refused — see {@code SaasTeamService.inviteUserToTeam}.*/public boolean canInviteMembers() {return !isPersonal();}++ /**+ * Users this team is allowed, or null when {@code max_seats} holds no purchased allowance. The+ * one place that judgement is made, so the wallet, the linked-instance entitlement and the+ * Users page cannot disagree about what the column is saying.+ *+ * <p>Team sells in blocks of 100 and every team gets {@link+ * UserLicenseSettingsService#DEFAULT_USER_LIMIT} users free, so a value at or below that was+ * never purchased and could restrict nothing if it were. {@link Integer#MAX_VALUE} is the+ * historic unlimited sentinel; returning it would let a caller do arithmetic on it, and+ * no-limit is expressed as absence.+ *+ * <p>Enforcement does not go through here: {@link #hasAvailableSeats()} still compares the raw+ * column while cloud capacity is unenforced for standard teams.+ */+ public Integer licensedUsers() {+ if (maxSeats == null+ || maxSeats <= UserLicenseSettingsService.DEFAULT_USER_LIMIT+ || maxSeats >= Integer.MAX_VALUE) {+ return null;+ }+ return maxSeats;+ }}diff --git a/app/saas/src/main/java/stirling/software/saas/payg/api/PaygWalletController.java b/app/saas/src/main/java/stirling/software/saas/payg/api/PaygWalletController.javaindex 1d87514190..abfd0ee405 100644--- a/app/saas/src/main/java/stirling/software/saas/payg/api/PaygWalletController.java+++ b/app/saas/src/main/java/stirling/software/saas/payg/api/PaygWalletController.java@@ -255,20 +255,15 @@ public class PaygWalletController {}/**- * The team's user-capacity holding.- *- * <p>The cap is written from the Team subscription, so a team holds Team exactly when it- * carries a real one. Integer.MAX_VALUE is the sentinel a team carries before it ever holds a- * Team plan, and it reports as no holding and no limit rather than as a number, so nothing- * downstream does arithmetic on it.+ * The team's user-capacity holding. The cap is written from the Team subscription, so a team+ * holds Team exactly when {@link SaasTeamExtensions#licensedUsers()} states one.*/private WalletSnapshotResponse.TeamHolding teamHolding(Long teamId) {int usersInUse = Math.toIntExact(memberRepo.countByTeamId(teamId));Integer licensed =teamExtensionsRepository.findByTeamId(teamId)- .map(SaasTeamExtensions::getMaxSeats)- .filter(max -> max != null && max > 0 && max < Integer.MAX_VALUE)+ .map(SaasTeamExtensions::licensedUsers).orElse(null);return new WalletSnapshotResponse.TeamHolding(licensed != null, licensed, usersInUse);}diff --git a/app/saas/src/main/java/stirling/software/saas/service/SaasTeamExtensionService.java b/app/saas/src/main/java/stirling/software/saas/service/SaasTeamExtensionService.javaindex b1c098a3dd..3003454e72 100644--- a/app/saas/src/main/java/stirling/software/saas/service/SaasTeamExtensionService.java+++ b/app/saas/src/main/java/stirling/software/saas/service/SaasTeamExtensionService.java@@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor;import lombok.extern.slf4j.Slf4j;import stirling.software.proprietary.model.Team;+import stirling.software.proprietary.service.UserLicenseSettingsService;import stirling.software.saas.model.SaasTeamExtensions;import stirling.software.saas.repository.SaasTeamExtensionsRepository;@@ -58,8 +59,15 @@ public class SaasTeamExtensionService {.orElse(0);}+ /**+ * The raw column; a missing row reads as the free allowance. Callers asking whether a team+ * bought anything want {@link SaasTeamExtensions#licensedUsers()}.+ */public int getMaxSeats(Team team) {- return repository.findByTeamId(team.getId()).map(SaasTeamExtensions::getMaxSeats).orElse(1);+ return repository+ .findByTeamId(team.getId())+ .map(SaasTeamExtensions::getMaxSeats)+ .orElse(UserLicenseSettingsService.DEFAULT_USER_LIMIT);}public Long getCreatedByUserId(Team team) {diff --git a/app/saas/src/main/java/stirling/software/saas/service/SaasTeamService.java b/app/saas/src/main/java/stirling/software/saas/service/SaasTeamService.javaindex d81e0d9ee7..67c8c50608 100644--- a/app/saas/src/main/java/stirling/software/saas/service/SaasTeamService.java+++ b/app/saas/src/main/java/stirling/software/saas/service/SaasTeamService.java@@ -21,6 +21,7 @@ import stirling.software.proprietary.security.database.repository.UserRepositoryimport stirling.software.proprietary.security.model.User;import stirling.software.proprietary.security.repository.TeamMembershipRepository;import stirling.software.proprietary.security.repository.TeamRepository;+import stirling.software.proprietary.service.UserLicenseSettingsService;import stirling.software.saas.accountlink.LinkedInstanceRepository;import stirling.software.saas.billing.repository.BillingSubscriptionRepository;import stirling.software.saas.config.SupabaseConfigurationProperties;@@ -126,7 +127,12 @@ public class SaasTeamService {Team savedTeam = teamRepository.save(team);saasTeamExtensionService.setPersonal(savedTeam, true);- saasTeamExtensionService.setSeats(savedTeam, 1, 1);+ // The free allowance, not 1: a linked instance reads this number as its own ceiling, so+ // a 1 here would refuse every user it tried to create.+ saasTeamExtensionService.setSeats(+ savedTeam,+ UserLicenseSettingsService.DEFAULT_USER_LIMIT,+ UserLicenseSettingsService.DEFAULT_USER_LIMIT);saasTeamExtensionService.setCreatedByUserId(savedTeam, user.getId());saasTeamExtensionsRepository.incrementSeatsUsed(savedTeam.getId());@@ -243,7 +249,10 @@ public class SaasTeamService {team.getName(),inviter.getUsername());saasTeamExtensionService.setPersonal(team, false);- // Unlimited seats once converted to standard+ // Still the unlimited sentinel, which is what a standard team is until it buys: nothing+ // enforces capacity for one. Writing the free allowance here instead would state a+ // ceiling nothing honours, and SaasTeamController's availableSeats would go negative as+ // the team grew past it. The sentinel goes when enforcement arrives.saasTeamExtensionService.setSeats(team, Integer.MAX_VALUE, Integer.MAX_VALUE);}diff --git a/app/saas/src/test/java/stirling/software/saas/accountlink/InstanceControllerTest.java b/app/saas/src/test/java/stirling/software/saas/accountlink/InstanceControllerTest.javaindex 07e8fd76ea..1a227d7ff0 100644--- a/app/saas/src/test/java/stirling/software/saas/accountlink/InstanceControllerTest.java+++ b/app/saas/src/test/java/stirling/software/saas/accountlink/InstanceControllerTest.java@@ -24,7 +24,9 @@ import org.springframework.security.core.Authentication;import org.springframework.security.core.authority.SimpleGrantedAuthority;import stirling.software.proprietary.billing.UnitCalcPolicy;+import stirling.software.proprietary.service.UserLicenseSettingsService;import stirling.software.saas.accountlink.InstanceController.EntitlementResponse;+import stirling.software.saas.model.SaasTeamExtensions;import stirling.software.saas.payg.billing.TeamBillingContext;import stirling.software.saas.payg.billing.TeamBillingService;import stirling.software.saas.payg.entitlement.EntitlementService;@@ -115,6 +117,26 @@ class InstanceControllerTest {assertThat(body.state()).isEqualTo("OK");}+ /** Only a purchased allowance reaches the wire: a solo account's team is not a ceiling. */+ @Test+ void entitlement_reportsOnlyAPurchasedAllowance() {+ Authentication token = new LinkedInstanceAuthenticationToken(4L, 9L);+ when(billingService.forTeam(9L)).thenReturn(freeBilling(500L));+ when(entitlementService.getSnapshot(9L))+ .thenReturn(snapshot(EntitlementState.FULL, 0L, null));+ when(pricingPolicyService.getEffectivePolicy(9L)).thenReturn(policy());++ SaasTeamExtensions free = new SaasTeamExtensions();+ free.setMaxSeats(UserLicenseSettingsService.DEFAULT_USER_LIMIT);+ when(teamExtensionsRepository.findByTeamId(9L)).thenReturn(Optional.of(free));+ assertThat(controller().entitlement(token).getBody().licensedUsers()).isNull();++ SaasTeamExtensions purchased = new SaasTeamExtensions();+ purchased.setMaxSeats(300);+ when(teamExtensionsRepository.findByTeamId(9L)).thenReturn(Optional.of(purchased));+ assertThat(controller().entitlement(token).getBody().licensedUsers()).isEqualTo(300);+ }+@Testvoid entitlement_degradedMapsToOverLimit() {// The instance gate parses OK / OVER_LIMIT, never the SaaS FULL/WARNED/DEGRADED enum.diff --git a/app/saas/src/test/java/stirling/software/saas/model/SaasTeamExtensionsTest.java b/app/saas/src/test/java/stirling/software/saas/model/SaasTeamExtensionsTest.javaindex 571c5f4014..3d7109efdc 100644--- a/app/saas/src/test/java/stirling/software/saas/model/SaasTeamExtensionsTest.java+++ b/app/saas/src/test/java/stirling/software/saas/model/SaasTeamExtensionsTest.java@@ -9,6 +9,7 @@ import org.junit.jupiter.api.Nested;import org.junit.jupiter.api.Test;import stirling.software.proprietary.model.Team;+import stirling.software.proprietary.service.UserLicenseSettingsService;/** Constructor, defaults, accessor, and seat/personal-team branch tests for SaasTeamExtensions. */class SaasTeamExtensionsTest {@@ -19,9 +20,11 @@ class SaasTeamExtensionsTest {SaasTeamExtensions ext = new SaasTeamExtensions();assertThat(ext.getTeamType()).isEqualTo(SaasTeamExtensions.TEAM_TYPE_STANDARD);assertThat(ext.getIsPersonal()).isFalse();- assertThat(ext.getSeatCount()).isEqualTo(1);assertThat(ext.getSeatsUsed()).isZero();- assertThat(ext.getMaxSeats()).isEqualTo(1);+ // A lazily-created row has bought nothing, so licensedUsers() reports no allowance.+ assertThat(ext.getSeatCount()).isEqualTo(UserLicenseSettingsService.DEFAULT_USER_LIMIT);+ assertThat(ext.getMaxSeats()).isEqualTo(UserLicenseSettingsService.DEFAULT_USER_LIMIT);+ assertThat(ext.licensedUsers()).isNull();assertThat(ext.isPersonal()).isFalse();}@@ -134,4 +137,55 @@ class SaasTeamExtensionsTest {assertThat(personal.canInviteMembers()).isFalse();}}++ /** Which values of {@code max_seats} are a purchased allowance, and which are not. */+ @Nested+ @DisplayName("licensedUsers")+ class LicensedUsers {++ private SaasTeamExtensions withMaxSeats(Integer maxSeats) {+ SaasTeamExtensions ext = new SaasTeamExtensions();+ ext.setMaxSeats(maxSeats);+ return ext;+ }++ @Test+ @DisplayName("null column states no allowance")+ void nullIsNoAllowance() {+ assertThat(withMaxSeats(null).licensedUsers()).isNull();+ }++ @Test+ @DisplayName("the personal-team 1 states no allowance")+ void personalTeamSentinel() {+ assertThat(withMaxSeats(1).licensedUsers()).isNull();+ }++ @Test+ @DisplayName("exactly the free allowance states no allowance")+ void freeAllowanceIsNotPurchased() {+ assertThat(withMaxSeats(UserLicenseSettingsService.DEFAULT_USER_LIMIT).licensedUsers())+ .isNull();+ }++ @Test+ @DisplayName("one above the free allowance is a real allowance")+ void justAboveTheFloorCounts() {+ int justAbove = UserLicenseSettingsService.DEFAULT_USER_LIMIT + 1;+ assertThat(withMaxSeats(justAbove).licensedUsers()).isEqualTo(justAbove);+ }++ @Test+ @DisplayName("a purchased block reports its size")+ void purchasedBlock() {+ assertThat(withMaxSeats(300).licensedUsers()).isEqualTo(300);+ }++ /** Returning it would let a caller add to it; no-limit is expressed as absence. */+ @Test+ @DisplayName("the unlimited sentinel states no allowance")+ void unlimitedSentinel() {+ assertThat(withMaxSeats(Integer.MAX_VALUE).licensedUsers()).isNull();+ }+ }}diff --git a/app/saas/src/test/java/stirling/software/saas/payg/api/PaygWalletControllerTest.java b/app/saas/src/test/java/stirling/software/saas/payg/api/PaygWalletControllerTest.javaindex 8f56c253cd..cd9156ef07 100644--- a/app/saas/src/test/java/stirling/software/saas/payg/api/PaygWalletControllerTest.java+++ b/app/saas/src/test/java/stirling/software/saas/payg/api/PaygWalletControllerTest.java@@ -35,6 +35,7 @@ import stirling.software.proprietary.model.TeamMembership;import stirling.software.proprietary.security.database.repository.UserRepository;import stirling.software.proprietary.security.model.User;import stirling.software.proprietary.security.repository.TeamMembershipRepository;+import stirling.software.proprietary.service.UserLicenseSettingsService;import stirling.software.saas.model.SaasTeamExtensions;import stirling.software.saas.payg.api.PaygWalletController.UpdateCapRequest;import stirling.software.saas.payg.api.WalletSnapshotResponse.MemberRow;@@ -203,6 +204,34 @@ class PaygWalletControllerTest {assertThat(body.processor().active()).isFalse();}+ /**+ * An unpurchased row carries the free allowance, which is not a Team holding: reporting it as+ * the meter's denominator would show a ceiling nobody bought.+ */+ @Test+ void getWallet_freeAllowanceRow_holdsNoTeam() {+ User user = userWithId(63L, UUID.randomUUID());+ Team team = teamWithId(63L);+ when(userRepository.findBySupabaseId(any())).thenReturn(Optional.of(user));+ user.setTeam(team);+ when(memberRepo.findByTeamIdAndUserId(team.getId(), 63L))+ .thenReturn(Optional.of(membership(team, user, TeamRole.MEMBER)));+ when(memberRepo.countByTeamId(63L)).thenReturn(2L);+ SaasTeamExtensions ext = new SaasTeamExtensions();+ ext.setMaxSeats(UserLicenseSettingsService.DEFAULT_USER_LIMIT);+ when(teamExtensionsRepository.findByTeamId(63L)).thenReturn(Optional.of(ext));+ when(billingService.forTeam(63L)).thenReturn(freeBilling(500L));+ when(entitlementService.getSnapshot(63L)).thenReturn(snapshot(0L, 500L));+ stubEmptyLedgerReads(63L);++ WalletSnapshotResponse body = controller.getWallet(jwtAuth(user.getSupabaseId())).getBody();++ assertThat(body).isNotNull();+ assertThat(body.team().held()).isFalse();+ assertThat(body.team().licensedUsers()).isNull();+ assertThat(body.team().usersInUse()).isEqualTo(2);+ }+/*** A metered subscription switches Credits on and says nothing about Team: the two axes move* independently, which is the whole point of reporting them separately.diff --git a/app/saas/src/test/java/stirling/software/saas/service/SaasTeamExtensionServiceTest.java b/app/saas/src/test/java/stirling/software/saas/service/SaasTeamExtensionServiceTest.javaindex d65e41902b..4626244762 100644--- a/app/saas/src/test/java/stirling/software/saas/service/SaasTeamExtensionServiceTest.java+++ b/app/saas/src/test/java/stirling/software/saas/service/SaasTeamExtensionServiceTest.java@@ -21,6 +21,7 @@ import org.mockito.junit.jupiter.MockitoSettings;import org.mockito.quality.Strictness;import stirling.software.proprietary.model.Team;+import stirling.software.proprietary.service.UserLicenseSettingsService;import stirling.software.saas.model.SaasTeamExtensions;import stirling.software.saas.repository.SaasTeamExtensionsRepository;@@ -28,10 +29,10 @@ import stirling.software.saas.repository.SaasTeamExtensionsRepository;* Unit tests for {@link SaasTeamExtensionService}.** <p>The service is a thin read/write facade over {@link SaasTeamExtensionsRepository}. Reads- * return safe defaults when no row exists (non-personal, STANDARD type, seatsUsed=0, maxSeats=1,- * createdBy=null, hasAvailableSeats=true, canInviteMembers=true); writes create the row lazily via- * {@code getOrCreate}. Pure delegation + Optional mapping, so everything is mocked at the- * repository boundary.+ * return safe defaults when no row exists (non-personal, STANDARD type, seatsUsed=0, maxSeats=the+ * free allowance, createdBy=null, hasAvailableSeats=true, canInviteMembers=true); writes create the+ * row lazily via {@code getOrCreate}. Pure delegation + Optional mapping, so everything is mocked+ * at the repository boundary.*/@ExtendWith(MockitoExtension.class)@MockitoSettings(strictness = Strictness.LENIENT)@@ -98,7 +99,8 @@ class SaasTeamExtensionServiceTest {assertThat(saved.getTeamType()).isEqualTo(SaasTeamExtensions.TEAM_TYPE_STANDARD);assertThat(saved.isPersonal()).isFalse();assertThat(saved.getSeatsUsed()).isZero();- assertThat(saved.getMaxSeats()).isEqualTo(1);+ assertThat(saved.getMaxSeats())+ .isEqualTo(UserLicenseSettingsService.DEFAULT_USER_LIMIT);assertThat(result).isSameAs(saved);}}@@ -212,12 +214,13 @@ class SaasTeamExtensionServiceTest {class GetMaxSeats {@Test- @DisplayName("no row defaults to 1 (not 0)")- void noRow_one() {+ @DisplayName("no row defaults to the free allowance")+ void noRow_freeAllowance() {Team team = team();when(repository.findByTeamId(TEAM_ID)).thenReturn(Optional.empty());- assertThat(service.getMaxSeats(team)).isEqualTo(1);+ assertThat(service.getMaxSeats(team))+ .isEqualTo(UserLicenseSettingsService.DEFAULT_USER_LIMIT);}@Testdiff --git a/app/saas/src/test/java/stirling/software/saas/service/SaasTeamServiceTest.java b/app/saas/src/test/java/stirling/software/saas/service/SaasTeamServiceTest.javaindex fc1fbcb0ab..a78df6ff8a 100644--- a/app/saas/src/test/java/stirling/software/saas/service/SaasTeamServiceTest.java+++ b/app/saas/src/test/java/stirling/software/saas/service/SaasTeamServiceTest.java@@ -36,6 +36,7 @@ import stirling.software.proprietary.security.model.Authority;import stirling.software.proprietary.security.model.User;import stirling.software.proprietary.security.repository.TeamMembershipRepository;import stirling.software.proprietary.security.repository.TeamRepository;+import stirling.software.proprietary.service.UserLicenseSettingsService;import stirling.software.saas.accountlink.LinkedInstanceRepository;import stirling.software.saas.billing.repository.BillingSubscriptionRepository;import stirling.software.saas.config.SupabaseConfigurationProperties;@@ -170,7 +171,12 @@ class SaasTeamServiceTest {assertThat(result).isSameAs(saved);verify(saasTeamExtensionService).setPersonal(saved, true);- verify(saasTeamExtensionService).setSeats(saved, 1, 1);+ // The free allowance, not 1: a linked instance reads this as its own ceiling.+ verify(saasTeamExtensionService)+ .setSeats(+ saved,+ UserLicenseSettingsService.DEFAULT_USER_LIMIT,+ UserLicenseSettingsService.DEFAULT_USER_LIMIT);verify(saasTeamExtensionService).setCreatedByUserId(saved, 1L);verify(saasTeamExtensionsRepository).incrementSeatsUsed(50L);@@ -285,7 +291,7 @@ class SaasTeamServiceTest {}@Test- @DisplayName("converts a personal team to standard (unlimited seats) on first invitation")+ @DisplayName("converts a personal team to standard on first invitation")void personalTeam_convertedToStandard() {Team t = team(teamId, "My Team");User inviter = user(1L, "[email protected]", "alice");@@ -304,6 +310,9 @@ class SaasTeamServiceTest {service.inviteUserToTeam(teamId, "[email protected]", inviter);verify(saasTeamExtensionService).setPersonal(t, false);+ // Still the sentinel. A standard team has no user limit until it buys one, and nothing+ // enforces capacity for one, so stating the free allowance here would announce a+ // ceiling nothing honours.verify(saasTeamExtensionService).setSeats(t, Integer.MAX_VALUE, Integer.MAX_VALUE);}diff --git a/frontend/editor/src/saas/portal/usersBackend.ts b/frontend/editor/src/saas/portal/usersBackend.tsindex a4fbc03dfb..f71c240ed2 100644--- a/frontend/editor/src/saas/portal/usersBackend.ts+++ b/frontend/editor/src/saas/portal/usersBackend.ts@@ -59,9 +59,16 @@ interface InvitationDTO {/** No last-activity signal on the team endpoints, so the column reads a dash. */const NO_ACTIVITY = "-";-/** 0 / huge sentinel seat values mean "no limit". */+/** Mirrors `UserLicenseSettingsService.DEFAULT_USER_LIMIT`; keep the two in step. */+const FREE_USER_ALLOWANCE = 5;++/**+ * Users the team is allowed, or null when `maxSeats` holds no purchased allowance. Must agree with+ * `SaasTeamExtensions.licensedUsers()`: a team on the free allowance has no limit to show, and the+ * unlimited sentinel is never a number.+ */function normalizeSeatLimit(max: number | undefined): number | null {- if (!max || max <= 0 || max >= 100000) return null;+ if (!max || max <= FREE_USER_ALLOWANCE || max >= 2147483647) return null;return max;}