1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-07 14:08:13 -05:00

enough seats available

This commit is contained in:
Kyle Spearrin 2017-05-18 08:58:08 -04:00
parent cadc79b900
commit fca12ecda6

View File

@ -947,33 +947,33 @@ namespace Bit.Core.Services
var usersToAdd = newUsersSet.Except(existingUsersSet).ToList(); var usersToAdd = newUsersSet.Except(existingUsersSet).ToList();
var seatsAvailable = int.MaxValue; var seatsAvailable = int.MaxValue;
var enoughSeatsAvailable = true;
if(organization.Seats.HasValue) if(organization.Seats.HasValue)
{ {
var userCount = await _organizationUserRepository.GetCountByOrganizationIdAsync(organizationId); var userCount = await _organizationUserRepository.GetCountByOrganizationIdAsync(organizationId);
seatsAvailable = organization.Seats.Value - userCount; seatsAvailable = organization.Seats.Value - userCount;
if(seatsAvailable < usersToAdd.Count) enoughSeatsAvailable = seatsAvailable >= usersToAdd.Count;
{
// throw exception?
return;
}
} }
foreach(var user in newUsers) if(enoughSeatsAvailable)
{ {
if(!usersToAdd.Contains(user.ExternalId) || string.IsNullOrWhiteSpace(user.Email)) foreach(var user in newUsers)
{ {
continue; if(!usersToAdd.Contains(user.ExternalId) || string.IsNullOrWhiteSpace(user.Email))
} {
continue;
}
try try
{ {
var newUser = await InviteUserAsync(organizationId, importingUserId, user.Email, var newUser = await InviteUserAsync(organizationId, importingUserId, user.Email,
OrganizationUserType.User, false, user.ExternalId, new List<SelectionReadOnly>()); OrganizationUserType.User, false, user.ExternalId, new List<SelectionReadOnly>());
existingUsersIdDict.Add(newUser.ExternalId, newUser.Id); existingUsersIdDict.Add(newUser.ExternalId, newUser.Id);
} }
catch(BadRequestException) catch(BadRequestException)
{ {
continue; continue;
}
} }
} }