diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/ISendOrganizationInvitesCommand.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/ISendOrganizationInvitesCommand.cs
index 12f5ae71c6..090317640f 100644
--- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/ISendOrganizationInvitesCommand.cs
+++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/ISendOrganizationInvitesCommand.cs
@@ -1,13 +1,16 @@
-using Bit.Core.AdminConsole.Entities;
-using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
-using Bit.Core.Entities;
-using Bit.Core.Models.Mail;
+using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers;
+///
+/// This is for sending the invite to an organization user.
+///
public interface ISendOrganizationInvitesCommand
{
+ ///
+ /// This sends emails out to organization users for a given organization.
+ ///
+ ///
+ ///
Task SendInvitesAsync(SendInvitesRequest request);
-
- Task BuildOrganizationInvitesInfoAsync(IEnumerable orgUsers, Organization organization, bool initOrganization = false);
}
diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/SendInvitesRequest.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/SendInvitesRequest.cs
index 4dec4c4f60..2be6430512 100644
--- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/SendInvitesRequest.cs
+++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Models/SendInvitesRequest.cs
@@ -1,15 +1,33 @@
-using Bit.Core.AdminConsole.Entities;
+#nullable enable
+
+using Bit.Core.AdminConsole.Entities;
using Bit.Core.Entities;
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
+///
+/// Represents a request to send invitations to a group of organization users.
+///
public class SendInvitesRequest
{
- public SendInvitesRequest() { }
-
public SendInvitesRequest(IEnumerable users, Organization organization) =>
(Users, Organization) = (users.ToArray(), organization);
+ public SendInvitesRequest(IEnumerable users, Organization organization, bool initOrganization) =>
+ (Users, Organization, InitOrganization) = (users.ToArray(), organization, initOrganization);
+
+ ///
+ /// Organization Users to send emails to.
+ ///
public OrganizationUser[] Users { get; set; } = [];
- public Organization Organization { get; set; } = null!;
+
+ ///
+ /// The organization to invite the users to.
+ ///
+ public Organization Organization { get; init; }
+
+ ///
+ /// This is for when the organization is being created and this is the owners initial invite
+ ///
+ public bool InitOrganization { get; init; }
}
diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/SendOrganizationInvitesCommand.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/SendOrganizationInvitesCommand.cs
index db931146f9..ba85ce1d8a 100644
--- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/SendOrganizationInvitesCommand.cs
+++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/SendOrganizationInvitesCommand.cs
@@ -23,12 +23,12 @@ public class SendOrganizationInvitesCommand(
{
public async Task SendInvitesAsync(SendInvitesRequest request)
{
- var orgInvitesInfo = await BuildOrganizationInvitesInfoAsync(request.Users, request.Organization);
+ var orgInvitesInfo = await BuildOrganizationInvitesInfoAsync(request.Users, request.Organization, request.InitOrganization);
await mailService.SendOrganizationInviteEmailsAsync(orgInvitesInfo);
}
- public async Task BuildOrganizationInvitesInfoAsync(IEnumerable orgUsers,
+ private async Task BuildOrganizationInvitesInfoAsync(IEnumerable orgUsers,
Organization organization, bool initOrganization = false)
{
// Materialize the sequence into a list to avoid multiple enumeration warnings
diff --git a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs
index 264ad31047..cbad176810 100644
--- a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs
+++ b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs
@@ -27,7 +27,6 @@ using Bit.Core.Exceptions;
using Bit.Core.Models.Business;
using Bit.Core.Models.Data;
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
-using Bit.Core.Models.Mail;
using Bit.Core.OrganizationFeatures.OrganizationSubscriptions.Interface;
using Bit.Core.Platform.Push;
using Bit.Core.Repositories;
@@ -1055,20 +1054,11 @@ public class OrganizationService : IOrganizationService
private async Task SendInvitesAsync(IEnumerable orgUsers, Organization organization) =>
await _sendOrganizationInvitesCommand.SendInvitesAsync(new SendInvitesRequest(orgUsers, organization));
- private async Task SendInviteAsync(OrganizationUser orgUser, Organization organization, bool initOrganization)
- {
- // convert single org user into array of 1 org user
- var orgUsers = new[] { orgUser };
-
- var orgInvitesInfo = await BuildOrganizationInvitesInfoAsync(orgUsers, organization, initOrganization);
-
- await _mailService.SendOrganizationInviteEmailsAsync(orgInvitesInfo);
- }
-
- private async Task BuildOrganizationInvitesInfoAsync(
- IEnumerable orgUsers, Organization organization, bool initOrganization = false) =>
- await _sendOrganizationInvitesCommand.BuildOrganizationInvitesInfoAsync(orgUsers, organization,
- initOrganization);
+ private async Task SendInviteAsync(OrganizationUser orgUser, Organization organization, bool initOrganization) =>
+ await _sendOrganizationInvitesCommand.SendInvitesAsync(new SendInvitesRequest(
+ users: [orgUser],
+ organization: organization,
+ initOrganization: initOrganization));
public async Task ConfirmUserAsync(Guid organizationId, Guid organizationUserId, string key,
Guid confirmingUserId)