From 7112496ff49628d05d355a611e0aafc8a0fb4233 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 13 Mar 2017 23:31:17 -0400 Subject: [PATCH] manage user type --- src/Api/Controllers/OrganizationUsersController.cs | 5 +++-- .../Request/Organizations/OrganizationUserRequestModels.cs | 7 +++++++ src/Core/Services/IOrganizationService.cs | 3 ++- src/Core/Services/Implementations/OrganizationService.cs | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Api/Controllers/OrganizationUsersController.cs b/src/Api/Controllers/OrganizationUsersController.cs index d70d6b3640..7f3eea6b8b 100644 --- a/src/Api/Controllers/OrganizationUsersController.cs +++ b/src/Api/Controllers/OrganizationUsersController.cs @@ -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}")] diff --git a/src/Core/Models/Api/Request/Organizations/OrganizationUserRequestModels.cs b/src/Core/Models/Api/Request/Organizations/OrganizationUserRequestModels.cs index ddae48e3d0..7d9c41f8eb 100644 --- a/src/Core/Models/Api/Request/Organizations/OrganizationUserRequestModels.cs +++ b/src/Core/Models/Api/Request/Organizations/OrganizationUserRequestModels.cs @@ -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 Subvaults { get; set; } } @@ -24,6 +25,12 @@ namespace Bit.Core.Models.Api { public Enums.OrganizationUserType Type { get; set; } public IEnumerable Subvaults { get; set; } + + public OrganizationUser ToOrganizationUser(OrganizationUser existingUser) + { + existingUser.Type = Type; + return existingUser; + } } public class OrganizationUserSubvaultRequestModel diff --git a/src/Core/Services/IOrganizationService.cs b/src/Core/Services/IOrganizationService.cs index 10c9e52640..8ac170a621 100644 --- a/src/Core/Services/IOrganizationService.cs +++ b/src/Core/Services/IOrganizationService.cs @@ -9,7 +9,8 @@ namespace Bit.Core.Services public interface IOrganizationService { Task> SignUpAsync(OrganizationSignup organizationSignup); - Task InviteUserAsync(Guid organizationId, string email, IEnumerable subvaults); + Task InviteUserAsync(Guid organizationId, string email, Enums.OrganizationUserType type, + IEnumerable subvaults); Task AcceptUserAsync(Guid organizationUserId, User user, string token); Task ConfirmUserAsync(Guid organizationUserId, string key); Task SaveUserAsync(OrganizationUser user, IEnumerable subvaults); diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index b9909674df..b193cf7dbd 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -90,7 +90,7 @@ namespace Bit.Core.Services } } - public async Task InviteUserAsync(Guid organizationId, string email, + public async Task InviteUserAsync(Guid organizationId, string email, Enums.OrganizationUserType type, IEnumerable 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