mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-04 23:27:13 +00:00
Use TpdsUpdateSender to use CollaboratorsHandler
This commit is contained in:
parent
a50bdaf5cc
commit
5f5445f625
5 changed files with 15 additions and 8 deletions
|
@ -54,7 +54,7 @@ module.exports = CollaboratorsHandler =
|
|||
return callback null, true, member.privilegeLevel
|
||||
return callback null, false, null
|
||||
|
||||
getProjectsUserIsMemberOf: (user_id, fields, callback = (error, readAndWriteProjects, readOnlyProjects) ->) ->
|
||||
getProjectsUserIsCollaboratorOf: (user_id, fields, callback = (error, readAndWriteProjects, readOnlyProjects) ->) ->
|
||||
Project.find {collaberator_refs:user_id}, fields, (err, readAndWriteProjects)=>
|
||||
Project.find {readOnly_refs:user_id}, fields, (err, readOnlyProjects)=>
|
||||
callback(err, readAndWriteProjects, readOnlyProjects)
|
||||
|
|
|
@ -33,6 +33,6 @@ module.exports = ProjectGetter =
|
|||
CollaboratorsHandler = require "../Collaborators/CollaboratorsHandler"
|
||||
Project.find {owner_ref: user_id}, fields, (error, projects) ->
|
||||
return callback(error) if error?
|
||||
CollaboratorsHandler.getProjectsUserIsMemberOf user_id, fields, (error, readAndWriteProjects, readOnlyProjects) ->
|
||||
CollaboratorsHandler.getProjectsUserIsCollaboratorOf user_id, fields, (error, readAndWriteProjects, readOnlyProjects) ->
|
||||
return callback(error) if error?
|
||||
callback null, projects, readAndWriteProjects, readOnlyProjects
|
||||
|
|
|
@ -5,6 +5,7 @@ Project = require('../../models/Project').Project
|
|||
keys = require('../../infrastructure/Keys')
|
||||
metrics = require("../../infrastructure/Metrics")
|
||||
request = require("request")
|
||||
CollaboratorsHandler = require('../Collaborators/CollaboratorsHandler')
|
||||
|
||||
buildPath = (user_id, project_name, filePath)->
|
||||
projectPath = path.join(project_name, "/", filePath)
|
||||
|
@ -116,9 +117,11 @@ module.exports = TpdsUpdateSender =
|
|||
TpdsUpdateSender._enqueue "poll-dropbox:#{user_id}", "standardHttpRequest", options, callback
|
||||
|
||||
getProjectsUsersIds = (project_id, callback = (err, owner_id, allUserIds)->)->
|
||||
Project.findById project_id, "_id owner_ref readOnly_refs collaberator_refs", (err, project)->
|
||||
allUserIds = [].concat(project.collaberator_refs).concat(project.readOnly_refs).concat(project.owner_ref)
|
||||
callback err, project.owner_ref, allUserIds
|
||||
Project.findById project_id, "_id owner_ref", (err, project) ->
|
||||
return callback(err) if err?
|
||||
CollaboratorsHandler.getMemberIds project_id, (err, member_ids) ->
|
||||
return callback(err) if err?
|
||||
callback err, project.owner_ref, member_ids
|
||||
|
||||
mergeProjectNameAndPath = (project_name, path)->
|
||||
if(path.indexOf('/') == 0)
|
||||
|
|
|
@ -112,13 +112,13 @@ describe "CollaboratorsHandler", ->
|
|||
.calledWith(null, false, null)
|
||||
.should.equal true
|
||||
|
||||
describe "getProjectsUserIsMemberOf", ->
|
||||
describe "getProjectsUserIsCollaboratorOf", ->
|
||||
beforeEach ->
|
||||
@fields = "mock fields"
|
||||
@Project.find = sinon.stub()
|
||||
@Project.find.withArgs({collaberator_refs:@user_id}, @fields).yields(null, ["mock-read-write-project-1", "mock-read-write-project-2"])
|
||||
@Project.find.withArgs({readOnly_refs:@user_id}, @fields).yields(null, ["mock-read-only-project-1", "mock-read-only-project-2"])
|
||||
@CollaboratorHandler.getProjectsUserIsMemberOf @user_id, @fields, @callback
|
||||
@CollaboratorHandler.getProjectsUserIsCollaboratorOf @user_id, @fields, @callback
|
||||
|
||||
it "should call the callback with the projects", ->
|
||||
@callback
|
||||
|
|
|
@ -20,7 +20,10 @@ filestoreUrl = "filestore.sharelatex.com"
|
|||
describe 'TpdsUpdateSender', ->
|
||||
beforeEach ->
|
||||
@requestQueuer = (queue, meth, opts, callback)->
|
||||
project = {owner_ref:user_id,readOnly_refs:[read_only_ref_1], collaberator_refs:[collaberator_ref_1]}
|
||||
project = {owner_ref:user_id}
|
||||
member_ids = [collaberator_ref_1, read_only_ref_1, user_id]
|
||||
@CollaboratorsHandler =
|
||||
getMemberIds: sinon.stub().yields(null, member_ids)
|
||||
@Project = findById:sinon.stub().callsArgWith(2, null, project)
|
||||
@docstoreUrl = "docstore.sharelatex.env"
|
||||
@request = sinon.stub().returns(pipe:->)
|
||||
|
@ -38,6 +41,7 @@ describe 'TpdsUpdateSender', ->
|
|||
"logger-sharelatex":{log:->}
|
||||
'../../models/Project': Project:@Project
|
||||
'request':@request
|
||||
'../Collaborators/CollaboratorsHandler': @CollaboratorsHandler
|
||||
|
||||
describe "_enqueue", ->
|
||||
|
||||
|
|
Loading…
Reference in a new issue