1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

check that SingleOrg policy is enabled before saying users cant create new orgs (#1110)

* check that SingleOrg policy is enabled before saying users cant create new orgs

* fixed org user kick check for SingleOrg

* code review cleanup
This commit is contained in:
Addison Beck 2021-01-25 11:19:33 -05:00 committed by GitHub
parent bc4eeff604
commit 445ce33c47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -162,7 +162,7 @@ namespace Bit.Api.Controllers
}
var policies = await _policyRepository.GetManyByUserIdAsync(user.Id);
if (policies.Any(policy => policy.Type == PolicyType.SingleOrg))
if (policies.Any(policy => policy.Enabled && policy.Type == PolicyType.SingleOrg))
{
throw new Exception("You may not create an organization. You belong to an organization " +
"which has a policy that prohibits you from being a member of any other organization.");
@ -190,7 +190,7 @@ namespace Bit.Api.Controllers
}
var policies = await _policyRepository.GetManyByUserIdAsync(user.Id);
if (policies.Any(policy => policy.Type == PolicyType.SingleOrg))
if (policies.Any(policy => policy.Enabled && policy.Type == PolicyType.SingleOrg))
{
throw new Exception("You may not create an organization. You belong to an organization " +
"which has a policy that prohibits you from being a member of any other organization.");

View File

@ -107,11 +107,13 @@ namespace Bit.Core.Services
case Enums.PolicyType.SingleOrg:
var userOrgs = await _organizationUserRepository.GetManyByManyUsersAsync(
removableOrgUsers.Select(ou => ou.UserId.Value));
organization = organization ?? await _organizationRepository.GetByIdAsync(policy.OrganizationId);
foreach (var orgUser in removableOrgUsers)
{
if (userOrgs.Any(ou => ou.UserId == orgUser.UserId && ou.Status != OrganizationUserStatusType.Invited))
if (userOrgs.Any(ou => ou.UserId == orgUser.UserId
&& ou.OrganizationId != organization.Id
&& ou.Status != OrganizationUserStatusType.Invited))
{
organization = organization ?? await _organizationRepository.GetByIdAsync(policy.OrganizationId);
await organizationService.DeleteUserAsync(policy.OrganizationId, orgUser.Id,
savingUserId);
await _mailService.SendOrganizationUserRemovedForPolicySingleOrgEmailAsync(