[web] Add User logs to Group Audit Logs view (#29155)

* [web] Add User logs to Group Audit Logs view

GitOrigin-RevId: c455edc5a700ba24e73a16b2a66b50cb92f24176
This commit is contained in:
Miguel Serrano
2025-11-04 09:05:35 +00:00
committed by Copybot
parent 85848b927e
commit 3522923d4e
5 changed files with 113 additions and 21 deletions
@@ -10,6 +10,7 @@ describe('UserAuditLogHandler', function () {
beforeEach(function () {
this.userId = new ObjectId()
this.initiatorId = new ObjectId()
this.subscriptionId = new ObjectId()
this.action = {
operation: 'clear-sessions',
initiatorId: this.initiatorId,
@@ -24,9 +25,16 @@ describe('UserAuditLogHandler', function () {
ip: '0:0:0:0',
}
this.UserAuditLogEntryMock = sinon.mock(UserAuditLogEntry)
this.getUniqueManagedSubscriptionMemberOfMock = sinon.stub().resolves()
this.UserAuditLogHandler = SandboxedModule.require(MODULE_PATH, {
requires: {
'../../models/UserAuditLogEntry': { UserAuditLogEntry },
'../Subscription/SubscriptionLocator': {
promises: {
getUniqueManagedSubscriptionMemberOf:
this.getUniqueManagedSubscriptionMemberOfMock,
},
},
},
})
})
@@ -53,37 +61,33 @@ describe('UserAuditLogHandler', function () {
this.UserAuditLogEntryMock.verify()
})
it('updates the log for password reset operation witout a initiatorId', async function () {
await expect(
this.UserAuditLogHandler.promises.addEntry(
this.userId,
'reset-password',
undefined,
this.action.ip,
this.action.info
)
it('updates the log for password reset operation without a initiatorId', async function () {
await this.UserAuditLogHandler.promises.addEntry(
this.userId,
'reset-password',
undefined,
this.action.ip,
this.action.info
)
this.UserAuditLogEntryMock.verify()
})
it('updates the log for a email removal via script', async function () {
await expect(
this.UserAuditLogHandler.promises.addEntry(
this.userId,
'remove-email',
undefined,
this.action.ip,
{
removedEmail: 'foo',
script: true,
}
)
await this.UserAuditLogHandler.promises.addEntry(
this.userId,
'remove-email',
undefined,
this.action.ip,
{
removedEmail: 'foo',
script: true,
}
)
this.UserAuditLogEntryMock.verify()
})
it('updates the log when no ip address or initiatorId is specified for a group join event', async function () {
this.UserAuditLogHandler.promises.addEntry(
await this.UserAuditLogHandler.promises.addEntry(
this.userId,
'join-group-subscription',
undefined,
@@ -92,6 +96,31 @@ describe('UserAuditLogHandler', function () {
subscriptionId: 'foo',
}
)
this.UserAuditLogEntryMock.verify()
})
it('includes managedSubscriptionId for managed group user events ', async function () {
await this.UserAuditLogHandler.promises.addEntry(
this.userId,
'reset-password',
undefined,
this.action.ip
)
this.UserAuditLogEntryMock.verify()
expect(this.getUniqueManagedSubscriptionMemberOfMock).to.have.been
.called
})
it('does not includes managedSubscriptionId for events not in the managed group event list', async function () {
await this.UserAuditLogHandler.promises.addEntry(
this.userId,
'foo',
this.action.initiatorId,
this.action.ip
)
this.UserAuditLogEntryMock.verify()
expect(this.getUniqueManagedSubscriptionMemberOfMock).not.to.have.been
.called
})
})