mirror of
https://github.com/bitwarden/server.git
synced 2025-04-08 14:38:15 -05:00
Import Invite Error (#1121)
* throw error if user is already invited on import * added back the single InviteUser OrgService method
This commit is contained in:
parent
3ba832b440
commit
00853bc250
@ -124,8 +124,8 @@ namespace Bit.Api.Public.Controllers
|
|||||||
AccessAll = model.AccessAll.Value,
|
AccessAll = model.AccessAll.Value,
|
||||||
Collections = associations
|
Collections = associations
|
||||||
};
|
};
|
||||||
var userPromise = await _organizationService.InviteUserAsync(_currentContext.OrganizationId.Value, null, model.ExternalId, invite);
|
var user = await _organizationService.InviteUserAsync(_currentContext.OrganizationId.Value, null,
|
||||||
var user = userPromise.FirstOrDefault();
|
model.Email, model.Type.Value, model.AccessAll.Value, model.ExternalId, associations);
|
||||||
var response = new MemberResponseModel(user, associations);
|
var response = new MemberResponseModel(user, associations);
|
||||||
return new JsonResult(response);
|
return new JsonResult(response);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ namespace Bit.Core.Services
|
|||||||
Task UpdateAsync(Organization organization, bool updateBilling = false);
|
Task UpdateAsync(Organization organization, bool updateBilling = false);
|
||||||
Task UpdateTwoFactorProviderAsync(Organization organization, TwoFactorProviderType type);
|
Task UpdateTwoFactorProviderAsync(Organization organization, TwoFactorProviderType type);
|
||||||
Task DisableTwoFactorProviderAsync(Organization organization, TwoFactorProviderType type);
|
Task DisableTwoFactorProviderAsync(Organization organization, TwoFactorProviderType type);
|
||||||
|
Task<OrganizationUser> InviteUserAsync(Guid organizationId, Guid? invitingUserId, string email,
|
||||||
|
OrganizationUserType type, bool accessAll, string externalId, IEnumerable<SelectionReadOnly> collections);
|
||||||
Task<List<OrganizationUser>> InviteUserAsync(Guid organizationId, Guid? invitingUserId, string externalId, OrganizationUserInvite orgUserInvite);
|
Task<List<OrganizationUser>> InviteUserAsync(Guid organizationId, Guid? invitingUserId, string externalId, OrganizationUserInvite orgUserInvite);
|
||||||
Task ResendInviteAsync(Guid organizationId, Guid? invitingUserId, Guid organizationUserId);
|
Task ResendInviteAsync(Guid organizationId, Guid? invitingUserId, Guid organizationUserId);
|
||||||
Task<OrganizationUser> AcceptUserAsync(Guid organizationUserId, User user, string token,
|
Task<OrganizationUser> AcceptUserAsync(Guid organizationUserId, User user, string token,
|
||||||
|
@ -1388,6 +1388,25 @@ namespace Bit.Core.Services
|
|||||||
return new OrganizationLicense(organization, subInfo, installationId, _licensingService, version);
|
return new OrganizationLicense(organization, subInfo, installationId, _licensingService, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<OrganizationUser> InviteUserAsync(Guid organizationId, Guid? invitingUserId, string email,
|
||||||
|
OrganizationUserType type, bool accessAll, string externalId, IEnumerable<SelectionReadOnly> collections)
|
||||||
|
{
|
||||||
|
var invite = new OrganizationUserInvite()
|
||||||
|
{
|
||||||
|
Emails = new List<string> { email },
|
||||||
|
Type = type,
|
||||||
|
AccessAll = accessAll,
|
||||||
|
Collections = collections,
|
||||||
|
};
|
||||||
|
var results = await InviteUserAsync(organizationId, invitingUserId, externalId, invite);
|
||||||
|
var result = results.FirstOrDefault();
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("This user has already been invited.");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task ImportAsync(Guid organizationId,
|
public async Task ImportAsync(Guid organizationId,
|
||||||
Guid? importingUserId,
|
Guid? importingUserId,
|
||||||
IEnumerable<ImportedGroup> groups,
|
IEnumerable<ImportedGroup> groups,
|
||||||
@ -1499,9 +1518,8 @@ namespace Bit.Core.Services
|
|||||||
AccessAll = false,
|
AccessAll = false,
|
||||||
Collections = new List<SelectionReadOnly>(),
|
Collections = new List<SelectionReadOnly>(),
|
||||||
};
|
};
|
||||||
var newUserPromise = await InviteUserAsync(organizationId, importingUserId, user.ExternalId, invite);
|
var newUser = await InviteUserAsync(organizationId, importingUserId, user.Email,
|
||||||
var newUser = newUserPromise.FirstOrDefault();
|
OrganizationUserType.User, false, user.ExternalId, new List<SelectionReadOnly>());
|
||||||
|
|
||||||
existingExternalUsersIdDict.Add(newUser.ExternalId, newUser.Id);
|
existingExternalUsersIdDict.Add(newUser.ExternalId, newUser.Id);
|
||||||
}
|
}
|
||||||
catch (BadRequestException)
|
catch (BadRequestException)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user