mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-29 20:11:32 +02:00
Update project-joined event to include role, mode, ownerId, and source (#23677)
* Update project-joined event to include role, mode, ownerId, and source * fix test GitOrigin-RevId: 67c428a80f5791b69a57b6719ec795399e2a98ef
This commit is contained in:
committed by
Copybot
parent
07ec183565
commit
e80846bace
@@ -359,11 +359,22 @@ async function acceptInvite(req, res) {
|
||||
'project:membership:changed',
|
||||
{ invites: true, members: true }
|
||||
)
|
||||
|
||||
let editMode = 'edit'
|
||||
if (invite.privileges === PrivilegeLevels.REVIEW) {
|
||||
editMode = 'review'
|
||||
} else if (invite.privileges === PrivilegeLevels.READ_ONLY) {
|
||||
editMode = 'view'
|
||||
}
|
||||
AnalyticsManager.recordEventForUserInBackground(
|
||||
currentUser._id,
|
||||
'project-invite-accept',
|
||||
'project-joined',
|
||||
{
|
||||
projectId,
|
||||
ownerId: invite.sendingUserId, // only owner can invite others
|
||||
mode: editMode,
|
||||
role: invite.privileges,
|
||||
source: 'email-invite',
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -347,7 +347,12 @@ async function grantTokenAccessReadAndWrite(req, res, next) {
|
||||
}
|
||||
)
|
||||
AnalyticsManager.recordEventForUserInBackground(userId, 'project-joined', {
|
||||
mode: pendingEditor ? 'read-only' : 'read-write',
|
||||
role: pendingEditor
|
||||
? PrivilegeLevels.READ_ONLY
|
||||
: PrivilegeLevels.READ_AND_WRITE,
|
||||
ownerId: project.owner_ref.toString(),
|
||||
source: 'link-sharing',
|
||||
mode: pendingEditor ? 'view' : 'edit',
|
||||
projectId: project._id.toString(),
|
||||
...(pendingEditor && { pendingEditor: true }),
|
||||
})
|
||||
@@ -450,7 +455,8 @@ async function grantTokenAccessReadOnly(req, res, next) {
|
||||
|
||||
await TokenAccessHandler.promises.addReadOnlyUserToProject(
|
||||
userId,
|
||||
project._id
|
||||
project._id,
|
||||
project.owner_ref
|
||||
)
|
||||
|
||||
return res.json({
|
||||
|
||||
@@ -151,12 +151,15 @@ const TokenAccessHandler = {
|
||||
throw new Error('invalid token type')
|
||||
},
|
||||
|
||||
async addReadOnlyUserToProject(userId, projectId) {
|
||||
async addReadOnlyUserToProject(userId, projectId, ownerId) {
|
||||
userId = new ObjectId(userId.toString())
|
||||
projectId = new ObjectId(projectId.toString())
|
||||
Analytics.recordEventForUserInBackground(userId, 'project-joined', {
|
||||
mode: 'read-only',
|
||||
role: PrivilegeLevels.READ_ONLY,
|
||||
projectId: projectId.toString(),
|
||||
source: 'link-sharing',
|
||||
ownerId: ownerId.toString(),
|
||||
mode: 'view',
|
||||
})
|
||||
|
||||
return await Project.updateOne(
|
||||
|
||||
@@ -18,6 +18,7 @@ describe('TokenAccessController', function () {
|
||||
this.user = { _id: new ObjectId() }
|
||||
this.project = {
|
||||
_id: new ObjectId(),
|
||||
owner_ref: this.user._id,
|
||||
name: 'test',
|
||||
tokenAccessReadAndWrite_refs: [],
|
||||
tokenAccessReadOnly_refs: [],
|
||||
@@ -242,8 +243,11 @@ describe('TokenAccessController', function () {
|
||||
expect(
|
||||
this.AnalyticsManager.recordEventForUserInBackground
|
||||
).to.have.been.calledWith(this.user._id, 'project-joined', {
|
||||
mode: 'read-write',
|
||||
mode: 'edit',
|
||||
projectId: this.project._id.toString(),
|
||||
ownerId: this.project.owner_ref.toString(),
|
||||
role: PrivilegeLevels.READ_AND_WRITE,
|
||||
source: 'link-sharing',
|
||||
})
|
||||
})
|
||||
|
||||
@@ -316,9 +320,12 @@ describe('TokenAccessController', function () {
|
||||
expect(
|
||||
this.AnalyticsManager.recordEventForUserInBackground
|
||||
).to.have.been.calledWith(this.user._id, 'project-joined', {
|
||||
mode: 'read-only',
|
||||
mode: 'view',
|
||||
projectId: this.project._id.toString(),
|
||||
pendingEditor: true,
|
||||
ownerId: this.project.owner_ref.toString(),
|
||||
role: PrivilegeLevels.READ_ONLY,
|
||||
source: 'link-sharing',
|
||||
})
|
||||
})
|
||||
|
||||
@@ -754,7 +761,11 @@ describe('TokenAccessController', function () {
|
||||
it('grants read-only access', function () {
|
||||
expect(
|
||||
this.TokenAccessHandler.promises.addReadOnlyUserToProject
|
||||
).to.have.been.calledWith(this.user._id, this.project._id)
|
||||
).to.have.been.calledWith(
|
||||
this.user._id,
|
||||
this.project._id,
|
||||
this.project.owner_ref
|
||||
)
|
||||
})
|
||||
|
||||
it('writes a project audit log', function () {
|
||||
|
||||
@@ -7,6 +7,7 @@ const modulePath = path.join(
|
||||
)
|
||||
const { expect } = require('chai')
|
||||
const { ObjectId } = require('mongodb-legacy')
|
||||
const PrivilegeLevels = require('../../../../app/src/Features/Authorization/PrivilegeLevels')
|
||||
|
||||
describe('TokenAccessHandler', function () {
|
||||
beforeEach(function () {
|
||||
@@ -115,7 +116,8 @@ describe('TokenAccessHandler', function () {
|
||||
it('should call Project.updateOne', async function () {
|
||||
await this.TokenAccessHandler.promises.addReadOnlyUserToProject(
|
||||
this.userId,
|
||||
this.projectId
|
||||
this.projectId,
|
||||
this.project.owner_ref
|
||||
)
|
||||
expect(this.Project.updateOne.callCount).to.equal(1)
|
||||
expect(
|
||||
@@ -130,7 +132,13 @@ describe('TokenAccessHandler', function () {
|
||||
this.Analytics.recordEventForUserInBackground,
|
||||
this.userId,
|
||||
'project-joined',
|
||||
{ mode: 'read-only', projectId: this.projectId.toString() }
|
||||
{
|
||||
mode: 'view',
|
||||
role: PrivilegeLevels.READ_ONLY,
|
||||
projectId: this.projectId.toString(),
|
||||
ownerId: this.project.owner_ref.toString(),
|
||||
source: 'link-sharing',
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user