Browse Source

Throw error if not enough seats available for a sync (#1241)

* BadRequest if a sync cannot be completed due to seat count

* Comment the reason for the suppressed exception
pull/1244/head
Matt Gibson 5 years ago committed by GitHub
parent
commit
584d3e771c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 47
      src/Core/Services/Implementations/OrganizationService.cs

47
src/Core/Services/Implementations/OrganizationService.cs

@ -1515,32 +1515,35 @@ namespace Bit.Core.Services @@ -1515,32 +1515,35 @@ namespace Bit.Core.Services
enoughSeatsAvailable = seatsAvailable >= usersToAdd.Count;
}
if (enoughSeatsAvailable)
if (!enoughSeatsAvailable)
{
foreach (var user in newUsers)
throw new BadRequestException($"Organization does not have enough seats available. Need {usersToAdd.Count} but {seatsAvailable} available.");
}
foreach (var user in newUsers)
{
if (!usersToAdd.Contains(user.ExternalId) || string.IsNullOrWhiteSpace(user.Email))
{
if (!usersToAdd.Contains(user.ExternalId) || string.IsNullOrWhiteSpace(user.Email))
{
continue;
}
continue;
}
try
{
var invite = new OrganizationUserInvite
{
Emails = new List<string> { user.Email },
Type = OrganizationUserType.User,
AccessAll = false,
Collections = new List<SelectionReadOnly>(),
};
var newUser = await InviteUserAsync(organizationId, importingUserId, user.Email,
OrganizationUserType.User, false, user.ExternalId, new List<SelectionReadOnly>());
existingExternalUsersIdDict.Add(newUser.ExternalId, newUser.Id);
}
catch (BadRequestException)
try
{
var invite = new OrganizationUserInvite
{
continue;
}
Emails = new List<string> { user.Email },
Type = OrganizationUserType.User,
AccessAll = false,
Collections = new List<SelectionReadOnly>(),
};
var newUser = await InviteUserAsync(organizationId, importingUserId, user.Email,
OrganizationUserType.User, false, user.ExternalId, new List<SelectionReadOnly>());
existingExternalUsersIdDict.Add(newUser.ExternalId, newUser.Id);
}
catch (BadRequestException)
{
// Thrown when the user is already invited to the organization
continue;
}
}
}

Loading…
Cancel
Save