From eb17fc29fc95b5a27f44ec19634a7f817c8b4ab5 Mon Sep 17 00:00:00 2001 From: jrmccannon Date: Fri, 28 Mar 2025 12:43:33 -0500 Subject: [PATCH] Made extension method. --- .../InviteOrganizationUsersCommand.cs | 3 +- .../Models/CreateOrganizationUser.cs | 25 +--------------- .../CreateOrganizationUserExtensions.cs | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/CreateOrganizationUserExtensions.cs diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUsersCommand.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUsersCommand.cs index d0c3ac9714..0ca9e66f51 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUsersCommand.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUsersCommand.cs @@ -18,7 +18,6 @@ using Bit.Core.Tools.Enums; using Bit.Core.Tools.Models.Business; using Bit.Core.Tools.Services; using Microsoft.Extensions.Logging; -using static Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models.CreateOrganizationUser; using OrganizationUserInvite = Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models.OrganizationUserInvite; namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers; @@ -100,7 +99,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService, var validatedRequest = validationResult as Valid; var organizationUserToInviteEntities = invitesToSend - .Select(MapToDataModel(request.PerformedAt, validatedRequest!.Value.InviteOrganization)) + .Select(x => x.MapToDataModel(request.PerformedAt, validatedRequest!.Value.InviteOrganization)) .ToArray(); var organization = await organizationRepository.GetByIdAsync(validatedRequest.Value.InviteOrganization.OrganizationId); diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/CreateOrganizationUser.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/CreateOrganizationUser.cs index b475470b01..a55db3958a 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/CreateOrganizationUser.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/CreateOrganizationUser.cs @@ -1,8 +1,5 @@ -using Bit.Core.AdminConsole.Models.Business; -using Bit.Core.Entities; -using Bit.Core.Enums; +using Bit.Core.Entities; using Bit.Core.Models.Data; -using Bit.Core.Utilities; namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models; @@ -15,24 +12,4 @@ public class CreateOrganizationUser public OrganizationUser OrganizationUser { get; set; } public CollectionAccessSelection[] Collections { get; set; } = []; public Guid[] Groups { get; set; } = []; - - public static Func MapToDataModel(DateTimeOffset performedAt, - InviteOrganization organization) => - o => new CreateOrganizationUser - { - OrganizationUser = new OrganizationUser - { - Id = CoreHelpers.GenerateComb(), - OrganizationId = organization.OrganizationId, - Email = o.Email.ToLowerInvariant(), - Type = o.Type, - Status = OrganizationUserStatusType.Invited, - AccessSecretsManager = o.AccessSecretsManager, - ExternalId = string.IsNullOrWhiteSpace(o.ExternalId) ? null : o.ExternalId, - CreationDate = performedAt.UtcDateTime, - RevisionDate = performedAt.UtcDateTime - }, - Collections = o.AssignedCollections, - Groups = o.Groups - }; } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/CreateOrganizationUserExtensions.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/CreateOrganizationUserExtensions.cs new file mode 100644 index 0000000000..23c38a51cb --- /dev/null +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/CreateOrganizationUserExtensions.cs @@ -0,0 +1,30 @@ +using Bit.Core.AdminConsole.Models.Business; +using Bit.Core.Entities; +using Bit.Core.Enums; +using Bit.Core.Utilities; + +namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models; + +public static class CreateOrganizationUserExtensions +{ + public static CreateOrganizationUser MapToDataModel(this OrganizationUserInvite organizationUserInvite, + DateTimeOffset performedAt, + InviteOrganization organization) => + new() + { + OrganizationUser = new OrganizationUser + { + Id = CoreHelpers.GenerateComb(), + OrganizationId = organization.OrganizationId, + Email = organizationUserInvite.Email.ToLowerInvariant(), + Type = organizationUserInvite.Type, + Status = OrganizationUserStatusType.Invited, + AccessSecretsManager = organizationUserInvite.AccessSecretsManager, + ExternalId = string.IsNullOrWhiteSpace(organizationUserInvite.ExternalId) ? null : organizationUserInvite.ExternalId, + CreationDate = performedAt.UtcDateTime, + RevisionDate = performedAt.UtcDateTime + }, + Collections = organizationUserInvite.AssignedCollections, + Groups = organizationUserInvite.Groups + }; +}