mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Differentiate project members by source, include token members
This commit is contained in:
parent
a06f4b6b28
commit
06966f67db
2 changed files with 21 additions and 11 deletions
|
@ -10,6 +10,9 @@ Errors = require "../Errors/Errors"
|
|||
EmailHelper = require "../Helpers/EmailHelper"
|
||||
ProjectEditorHandler = require "../Project/ProjectEditorHandler"
|
||||
|
||||
Sources =
|
||||
INVITE: 'invite'
|
||||
TOKEN: 'token'
|
||||
|
||||
module.exports = CollaboratorsHandler =
|
||||
|
||||
|
@ -18,11 +21,18 @@ module.exports = CollaboratorsHandler =
|
|||
return callback(error) if error?
|
||||
return callback new Errors.NotFoundError("no project found with id #{project_id}") if !project?
|
||||
members = []
|
||||
# Project owner
|
||||
members.push { id: project.owner_ref.toString(), privilegeLevel: PrivilegeLevels.OWNER }
|
||||
# Invited members
|
||||
for member_id in project.readOnly_refs or []
|
||||
members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_ONLY }
|
||||
members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_ONLY, source: Sources.INVITE }
|
||||
for member_id in project.collaberator_refs or []
|
||||
members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_AND_WRITE }
|
||||
members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_AND_WRITE, source: Sources.INVITE }
|
||||
# Token access
|
||||
for member_id in project.tokenAccessReadOnly_refs or []
|
||||
members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_ONLY, source: Sources.TOKEN }
|
||||
for member_id in project.tokenAccessReadAndWrite_refs or []
|
||||
members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_AND_WRITE, source: Sources.TOKEN }
|
||||
return callback null, members
|
||||
|
||||
getMemberIds: (project_id, callback = (error, member_ids) ->) ->
|
||||
|
|
|
@ -41,10 +41,10 @@ describe "CollaboratorsHandler", ->
|
|||
@callback
|
||||
.calledWith(null, [
|
||||
{ id: "owner-ref", privilegeLevel: "owner" }
|
||||
{ id: "read-only-ref-1", privilegeLevel: "readOnly" }
|
||||
{ id: "read-only-ref-2", privilegeLevel: "readOnly" }
|
||||
{ id: "read-write-ref-1", privilegeLevel: "readAndWrite" }
|
||||
{ id: "read-write-ref-2", privilegeLevel: "readAndWrite" }
|
||||
{ id: "read-only-ref-1", privilegeLevel: "readOnly", source: 'invite'}
|
||||
{ id: "read-only-ref-2", privilegeLevel: "readOnly", source: 'invite'}
|
||||
{ id: "read-write-ref-1", privilegeLevel: "readAndWrite", source: 'invite'}
|
||||
{ id: "read-write-ref-2", privilegeLevel: "readAndWrite", source: 'invite' }
|
||||
])
|
||||
.should.equal true
|
||||
|
||||
|
@ -74,11 +74,11 @@ describe "CollaboratorsHandler", ->
|
|||
beforeEach ->
|
||||
@CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub()
|
||||
@CollaboratorHandler.getMemberIdsWithPrivilegeLevels.withArgs(@project_id).yields(null, [
|
||||
{ id: "read-only-ref-1", privilegeLevel: "readOnly" }
|
||||
{ id: "read-only-ref-2", privilegeLevel: "readOnly" }
|
||||
{ id: "read-write-ref-1", privilegeLevel: "readAndWrite" }
|
||||
{ id: "read-write-ref-2", privilegeLevel: "readAndWrite" }
|
||||
{ id: "doesnt-exist", privilegeLevel: "readAndWrite" }
|
||||
{ id: "read-only-ref-1", privilegeLevel: "readOnly", source: 'invite' }
|
||||
{ id: "read-only-ref-2", privilegeLevel: "readOnly", source: 'invite' }
|
||||
{ id: "read-write-ref-1", privilegeLevel: "readAndWrite", source: 'invite' }
|
||||
{ id: "read-write-ref-2", privilegeLevel: "readAndWrite", source: 'invite' }
|
||||
{ id: "doesnt-exist", privilegeLevel: "readAndWrite", source: 'invite' }
|
||||
])
|
||||
@UserGetter.getUserById = sinon.stub()
|
||||
@UserGetter.getUserById.withArgs("read-only-ref-1").yields(null, { _id: "read-only-ref-1" })
|
||||
|
|
Loading…
Reference in a new issue