Merge pull request #15090 from overleaf/em-invite-audit-logs-2

Write audit logs when user leaves or is removed from a project

GitOrigin-RevId: 7c9cf025a0266099c1afa34035a8d8db38353193
This commit is contained in:
Eric Mc Sween
2023-10-12 08:03:33 +00:00
committed by Copybot
parent 16cfda28e3
commit cb16d6fb2e
2 changed files with 43 additions and 0 deletions
@@ -54,6 +54,10 @@ describe('CollaboratorsController', function () {
getRequestToken: sinon.stub().returns('access-token'),
}
this.ProjectAuditLogHandler = {
addEntryInBackground: sinon.stub(),
}
this.CollaboratorsController = SandboxedModule.require(MODULE_PATH, {
requires: {
mongodb: { ObjectId },
@@ -65,6 +69,7 @@ describe('CollaboratorsController', function () {
'../Tags/TagsHandler': this.TagsHandler,
'../Authentication/SessionManager': this.SessionManager,
'../TokenAccess/TokenAccessHandler': this.TokenAccessHandler,
'../Project/ProjectAuditLogHandler': this.ProjectAuditLogHandler,
},
})
})
@@ -105,6 +110,16 @@ describe('CollaboratorsController', function () {
'project:membership:changed'
)
})
it('should write a project audit log', function () {
this.ProjectAuditLogHandler.addEntryInBackground.should.have.been.calledWith(
this.projectId,
'remove-collaborator',
this.user._id,
this.req.ip,
{ userId: this.user._id }
)
})
})
describe('removeSelfFromProject', function () {
@@ -139,6 +154,15 @@ describe('CollaboratorsController', function () {
it('should return a success code', function () {
this.res.sendStatus.calledWith(204).should.equal(true)
})
it('should write a project audit log', function () {
this.ProjectAuditLogHandler.addEntryInBackground.should.have.been.calledWith(
this.projectId,
'leave-project',
this.user._id,
this.req.ip
)
})
})
describe('getAllMembers', function () {