mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 05:00:19 -05:00
Made extension method.
This commit is contained in:
parent
c987966eee
commit
eb17fc29fc
@ -18,7 +18,6 @@ using Bit.Core.Tools.Enums;
|
|||||||
using Bit.Core.Tools.Models.Business;
|
using Bit.Core.Tools.Models.Business;
|
||||||
using Bit.Core.Tools.Services;
|
using Bit.Core.Tools.Services;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using static Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models.CreateOrganizationUser;
|
|
||||||
using OrganizationUserInvite = Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models.OrganizationUserInvite;
|
using OrganizationUserInvite = Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models.OrganizationUserInvite;
|
||||||
|
|
||||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers;
|
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers;
|
||||||
@ -100,7 +99,7 @@ public class InviteOrganizationUsersCommand(IEventService eventService,
|
|||||||
var validatedRequest = validationResult as Valid<InviteUserOrganizationValidationRequest>;
|
var validatedRequest = validationResult as Valid<InviteUserOrganizationValidationRequest>;
|
||||||
|
|
||||||
var organizationUserToInviteEntities = invitesToSend
|
var organizationUserToInviteEntities = invitesToSend
|
||||||
.Select(MapToDataModel(request.PerformedAt, validatedRequest!.Value.InviteOrganization))
|
.Select(x => x.MapToDataModel(request.PerformedAt, validatedRequest!.Value.InviteOrganization))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
var organization = await organizationRepository.GetByIdAsync(validatedRequest.Value.InviteOrganization.OrganizationId);
|
var organization = await organizationRepository.GetByIdAsync(validatedRequest.Value.InviteOrganization.OrganizationId);
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
using Bit.Core.AdminConsole.Models.Business;
|
using Bit.Core.Entities;
|
||||||
using Bit.Core.Entities;
|
|
||||||
using Bit.Core.Enums;
|
|
||||||
using Bit.Core.Models.Data;
|
using Bit.Core.Models.Data;
|
||||||
using Bit.Core.Utilities;
|
|
||||||
|
|
||||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
|
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
|
||||||
|
|
||||||
@ -15,24 +12,4 @@ public class CreateOrganizationUser
|
|||||||
public OrganizationUser OrganizationUser { get; set; }
|
public OrganizationUser OrganizationUser { get; set; }
|
||||||
public CollectionAccessSelection[] Collections { get; set; } = [];
|
public CollectionAccessSelection[] Collections { get; set; } = [];
|
||||||
public Guid[] Groups { get; set; } = [];
|
public Guid[] Groups { get; set; } = [];
|
||||||
|
|
||||||
public static Func<OrganizationUserInvite, CreateOrganizationUser> 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
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
};
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user