|
@@ -29,7 +29,7 @@ async function getInvite(token) {
|
|
|
return { invite, subscription }
|
|
return { invite, subscription }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async function createInvite(teamManagerId, subscription, email) {
|
|
|
|
|
|
|
+async function createInvite(teamManagerId, subscription, email, auditLog) {
|
|
|
email = EmailHelper.parseEmail(email)
|
|
email = EmailHelper.parseEmail(email)
|
|
|
if (!email) {
|
|
if (!email) {
|
|
|
throw new Error('invalid email')
|
|
throw new Error('invalid email')
|
|
@@ -37,7 +37,7 @@ async function createInvite(teamManagerId, subscription, email) {
|
|
|
const teamManager = await UserGetter.promises.getUser(teamManagerId)
|
|
const teamManager = await UserGetter.promises.getUser(teamManagerId)
|
|
|
|
|
|
|
|
await _removeLegacyInvite(subscription.id, email)
|
|
await _removeLegacyInvite(subscription.id, email)
|
|
|
- return _createInvite(subscription, email, teamManager)
|
|
|
|
|
|
|
+ return _createInvite(subscription, email, teamManager, auditLog)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function importInvite(subscription, inviterName, email, token, sentAt) {
|
|
async function importInvite(subscription, inviterName, email, token, sentAt) {
|
|
@@ -171,7 +171,7 @@ async function createTeamInvitesForLegacyInvitedEmail(email) {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async function _createInvite(subscription, email, inviter) {
|
|
|
|
|
|
|
+async function _createInvite(subscription, email, inviter, auditLog) {
|
|
|
const { possible, reason } = await _checkIfInviteIsPossible(
|
|
const { possible, reason } = await _checkIfInviteIsPossible(
|
|
|
subscription,
|
|
subscription,
|
|
|
email
|
|
email
|
|
@@ -257,6 +257,23 @@ async function _createInvite(subscription, email, inviter) {
|
|
|
await subscription.save()
|
|
await subscription.save()
|
|
|
|
|
|
|
|
if (subscription.managedUsersEnabled) {
|
|
if (subscription.managedUsersEnabled) {
|
|
|
|
|
+ const auditLogData = {
|
|
|
|
|
+ initiatorId: auditLog?.initiatorId,
|
|
|
|
|
+ ipAddress: auditLog?.ipAddress,
|
|
|
|
|
+ groupId: subscription._id,
|
|
|
|
|
+ operation: 'group-invite-sent',
|
|
|
|
|
+ info: { invitedEmail: email },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ await Modules.promises.hooks.fire('addGroupAuditLogEntry', auditLogData)
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ logger.error(
|
|
|
|
|
+ { error, auditLog },
|
|
|
|
|
+ 'Error adding group audit log entry for group-invite-sent'
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
let admin = {}
|
|
let admin = {}
|
|
|
try {
|
|
try {
|
|
|
admin = await SubscriptionLocator.promises.getAdminEmailAndName(
|
|
admin = await SubscriptionLocator.promises.getAdminEmailAndName(
|