1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-23 17:07:42 +01:00

manage user type

This commit is contained in:
Kyle Spearrin 2017-03-13 23:31:17 -04:00
parent c8d6a26ec3
commit 7112496ff4
4 changed files with 14 additions and 5 deletions

View File

@ -58,7 +58,7 @@ namespace Bit.Api.Controllers
public async Task Invite(string orgId, [FromBody]OrganizationUserInviteRequestModel model)
{
var user = await _userService.GetUserByPrincipalAsync(User);
var result = await _organizationService.InviteUserAsync(new Guid(orgId), model.Email,
var result = await _organizationService.InviteUserAsync(new Guid(orgId), model.Email, model.Type,
model.Subvaults?.Select(s => s.ToSubvaultUser()));
}
@ -87,7 +87,8 @@ namespace Bit.Api.Controllers
throw new NotFoundException();
}
await _organizationService.SaveUserAsync(organizationUser, model.Subvaults?.Select(s => s.ToSubvaultUser()));
await _organizationService.SaveUserAsync(model.ToOrganizationUser(organizationUser),
model.Subvaults?.Select(s => s.ToSubvaultUser()));
}
[HttpDelete("{id}")]

View File

@ -7,6 +7,7 @@ namespace Bit.Core.Models.Api
public class OrganizationUserInviteRequestModel
{
public string Email { get; set; }
public Enums.OrganizationUserType Type { get; set; }
public IEnumerable<OrganizationUserSubvaultRequestModel> Subvaults { get; set; }
}
@ -24,6 +25,12 @@ namespace Bit.Core.Models.Api
{
public Enums.OrganizationUserType Type { get; set; }
public IEnumerable<OrganizationUserSubvaultRequestModel> Subvaults { get; set; }
public OrganizationUser ToOrganizationUser(OrganizationUser existingUser)
{
existingUser.Type = Type;
return existingUser;
}
}
public class OrganizationUserSubvaultRequestModel

View File

@ -9,7 +9,8 @@ namespace Bit.Core.Services
public interface IOrganizationService
{
Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup organizationSignup);
Task<OrganizationUser> InviteUserAsync(Guid organizationId, string email, IEnumerable<SubvaultUser> subvaults);
Task<OrganizationUser> InviteUserAsync(Guid organizationId, string email, Enums.OrganizationUserType type,
IEnumerable<SubvaultUser> subvaults);
Task<OrganizationUser> AcceptUserAsync(Guid organizationUserId, User user, string token);
Task<OrganizationUser> ConfirmUserAsync(Guid organizationUserId, string key);
Task SaveUserAsync(OrganizationUser user, IEnumerable<SubvaultUser> subvaults);

View File

@ -90,7 +90,7 @@ namespace Bit.Core.Services
}
}
public async Task<OrganizationUser> InviteUserAsync(Guid organizationId, string email,
public async Task<OrganizationUser> InviteUserAsync(Guid organizationId, string email, Enums.OrganizationUserType type,
IEnumerable<SubvaultUser> subvaults)
{
var orgUser = new OrganizationUser
@ -99,7 +99,7 @@ namespace Bit.Core.Services
UserId = null,
Email = email,
Key = null,
Type = Enums.OrganizationUserType.User,
Type = type,
Status = Enums.OrganizationUserStatusType.Invited,
CreationDate = DateTime.UtcNow,
RevisionDate = DateTime.UtcNow