From b4d588d98104a93b1731bbeb4d93348dda93938b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 7 Apr 2017 14:03:36 -0400 Subject: [PATCH] limit org admins to 1 free organization --- .../Implementations/OrganizationService.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index efbe91b1ea..e0f7f3e3e3 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -87,7 +87,16 @@ namespace Bit.Core.Services StripeCustomer customer = null; StripeSubscription subscription = null; - if(plan.Type != Enums.PlanType.Free) + if(plan.Type == Enums.PlanType.Free) + { + var ownerExistingOrgs = await _organizationUserRepository.GetManyByUserAsync(signup.Owner.Id); + if(ownerExistingOrgs.Any(ou => ou.Type == Enums.OrganizationUserType.Owner || + ou.Type == Enums.OrganizationUserType.Admin)) + { + throw new BadRequestException("You can only be an admin of 1 free organization."); + } + } + else { customer = await customerService.CreateAsync(new StripeCustomerCreateOptions { @@ -245,6 +254,12 @@ namespace Bit.Core.Services throw new BadRequestException("Already accepted."); } + var existingOrgs = await _organizationUserRepository.GetManyByUserAsync(user.Id); + if(existingOrgs.Any(ou => ou.Type == Enums.OrganizationUserType.Owner || ou.Type == Enums.OrganizationUserType.Admin)) + { + throw new BadRequestException("You can only be an admin of 1 free organization."); + } + var tokenValidationFailed = true; try {