Order privileges by highest-to-lowest

This commit is contained in:
Shane Kilkelly 2017-09-22 15:55:38 +01:00
parent 81170d472d
commit ee32648bf4
2 changed files with 8 additions and 9 deletions

View file

@ -28,18 +28,17 @@ 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, source: Sources.OWNER }
# Invited members
for member_id in project.readOnly_refs or []
members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_ONLY, source: Sources.INVITE }
# read-and-write
for member_id in project.collaberator_refs or []
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 }
# read-only
for member_id in project.readOnly_refs or []
members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_ONLY, source: Sources.INVITE }
for member_id in project.tokenAccessReadOnly_refs or []
members.push { id: member_id.toString(), privilegeLevel: PrivilegeLevels.READ_ONLY, source: Sources.TOKEN }
return callback null, members
getMemberIds: (project_id, callback = (error, member_ids) ->) ->

View file

@ -44,10 +44,10 @@ describe "CollaboratorsHandler", ->
@callback
.calledWith(null, [
{ id: "owner-ref", privilegeLevel: "owner", source: 'owner'}
{ 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: "read-only-ref-1", privilegeLevel: "readOnly", source: 'invite'}
{ id: "read-only-ref-2", privilegeLevel: "readOnly", source: 'invite'}
])
.should.equal true