mirror of
https://github.com/bitwarden/browser
synced 2026-02-21 11:54:02 +00:00
Implement solution and fix tests
This commit is contained in:
@@ -62,7 +62,7 @@ export interface MemberDialogParams {
|
||||
name: string;
|
||||
organizationId: string;
|
||||
organizationUserId: string;
|
||||
activeUserCount: number;
|
||||
activeUserCount?: number;
|
||||
allOrganizationUserEmails: string[];
|
||||
usesKeyConnector: boolean;
|
||||
isOnSecretsManagerStandalone: boolean;
|
||||
@@ -268,8 +268,8 @@ export class MemberDialogComponent implements OnDestroy {
|
||||
orgSeatLimitReachedValidator(
|
||||
organization,
|
||||
this.params.allOrganizationUserEmails,
|
||||
this.params.activeUserCount,
|
||||
this.i18nService.t("subscriptionUpgrade", organization.seats),
|
||||
this.params.activeUserCount,
|
||||
),
|
||||
];
|
||||
|
||||
|
||||
@@ -102,10 +102,14 @@ describe("orgSeatLimitReachedValidator", () => {
|
||||
seats: 2,
|
||||
});
|
||||
const errorMessage = "You cannot invite more than 2 members without upgrading your plan.";
|
||||
|
||||
const activeUserCount = 1;
|
||||
|
||||
validatorFn = orgSeatLimitReachedValidator(
|
||||
organization,
|
||||
allOrganizationUserEmails,
|
||||
"You cannot invite more than 2 members without upgrading your plan.",
|
||||
activeUserCount,
|
||||
);
|
||||
const control = new FormControl("user2@example.com,user3@example.com");
|
||||
|
||||
|
||||
@@ -8,15 +8,15 @@ import { ProductTierType } from "@bitwarden/common/billing/enums";
|
||||
* new users
|
||||
* @param organization An object representing the organization
|
||||
* @param allOrganizationUserEmails An array of strings with existing user email addresses
|
||||
* @param activeUserCount The current count of active users occupying the organization's seats.
|
||||
* @param errorMessage A localized string to display if validation fails
|
||||
* @param activeUserCount The current count of active users occupying the organization's seats.
|
||||
* @returns A function that validates an `AbstractControl` and returns `ValidationErrors` or `null`
|
||||
*/
|
||||
export function orgSeatLimitReachedValidator(
|
||||
organization: Organization,
|
||||
allOrganizationUserEmails: string[],
|
||||
activeUserCount: number,
|
||||
errorMessage: string,
|
||||
activeUserCount?: number,
|
||||
): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationErrors | null => {
|
||||
if (control.value === "" || !control.value) {
|
||||
@@ -28,10 +28,14 @@ export function orgSeatLimitReachedValidator(
|
||||
organization.productTierType !== ProductTierType.Families &&
|
||||
organization.productTierType !== ProductTierType.TeamsStarter;
|
||||
|
||||
const newTotalCount =
|
||||
if (productHasAdditionalSeatsOption || !activeUserCount) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const newTotalUserCount =
|
||||
activeUserCount + getUniqueNewEmailCount(allOrganizationUserEmails, control);
|
||||
|
||||
if (!productHasAdditionalSeatsOption && newTotalCount > organization.seats) {
|
||||
if (newTotalUserCount > organization.seats) {
|
||||
return { seatLimitReached: { message: errorMessage } };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user