mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Refactor LimitationsManager to use CollaboratorsHandler
This commit is contained in:
parent
bedc8a0492
commit
a50bdaf5cc
2 changed files with 4 additions and 19 deletions
|
@ -3,6 +3,7 @@ Project = require("../../models/Project").Project
|
|||
User = require("../../models/User").User
|
||||
SubscriptionLocator = require("./SubscriptionLocator")
|
||||
Settings = require("settings-sharelatex")
|
||||
CollaboratorsHandler = require("../Collaborators/CollaboratorsHandler")
|
||||
|
||||
module.exports =
|
||||
|
||||
|
@ -13,16 +14,11 @@ module.exports =
|
|||
callback null, owner.features.collaborators
|
||||
else
|
||||
callback null, Settings.defaultPlanCode.collaborators
|
||||
|
||||
currentNumberOfCollaboratorsInProject: (project_id, callback) ->
|
||||
Project.findById project_id, 'collaberator_refs readOnly_refs', (error, project) ->
|
||||
return callback(error) if error?
|
||||
callback null, (project.collaberator_refs.length + project.readOnly_refs.length)
|
||||
|
||||
canAddXCollaborators: (project_id, x_collaborators, callback = (error, allowed)->) ->
|
||||
@allowedNumberOfCollaboratorsInProject project_id, (error, allowed_number) =>
|
||||
return callback(error) if error?
|
||||
@currentNumberOfCollaboratorsInProject project_id, (error, current_number) =>
|
||||
CollaboratorsHandler.getCollaboratorCount project_id, (error, current_number) =>
|
||||
return callback(error) if error?
|
||||
if current_number + x_collaborators <= allowed_number or allowed_number < 0
|
||||
callback null, true
|
||||
|
|
|
@ -29,6 +29,7 @@ describe "LimitationsManager", ->
|
|||
'../../models/User' : User: @User
|
||||
'./SubscriptionLocator':@SubscriptionLocator
|
||||
'settings-sharelatex' : @Settings = {}
|
||||
"../Collaborators/CollaboratorsHandler": @CollaboratorsHandler = {}
|
||||
'logger-sharelatex':log:->
|
||||
|
||||
describe "allowedNumberOfCollaboratorsInProject", ->
|
||||
|
@ -51,22 +52,10 @@ describe "LimitationsManager", ->
|
|||
|
||||
it "should return the number of collaborators the user is allowed", ->
|
||||
@callback.calledWith(null, @user.features.collaborators).should.equal true
|
||||
|
||||
describe "currentNumberOfCollaboratorsInProject", ->
|
||||
beforeEach ->
|
||||
@project.collaberator_refs = ["one", "two"]
|
||||
@project.readOnly_refs = ["three"]
|
||||
@callback = sinon.stub()
|
||||
@LimitationsManager.currentNumberOfCollaboratorsInProject(@project_id, @callback)
|
||||
|
||||
it "should return the total number of collaborators", ->
|
||||
@callback.calledWith(null, 3).should.equal true
|
||||
|
||||
describe "canAddXCollaborators", ->
|
||||
beforeEach ->
|
||||
sinon.stub @LimitationsManager,
|
||||
"currentNumberOfCollaboratorsInProject",
|
||||
(project_id, callback) => callback(null, @current_number)
|
||||
@CollaboratorsHandler.getCollaboratorCount = (project_id, callback) => callback(null, @current_number)
|
||||
sinon.stub @LimitationsManager,
|
||||
"allowedNumberOfCollaboratorsInProject",
|
||||
(project_id, callback) => callback(null, @allowed_number)
|
||||
|
|
Loading…
Reference in a new issue