|
|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|