mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-14 03:54:48 +00:00
Remove obsolete add-email-to-project workflow
This commit is contained in:
parent
c87df7be79
commit
7919d5342b
5 changed files with 0 additions and 146 deletions
|
@ -9,29 +9,6 @@ logger = require 'logger-sharelatex'
|
|||
|
||||
|
||||
module.exports = CollaboratorsController =
|
||||
addUserToProject: (req, res, next) ->
|
||||
project_id = req.params.Project_id
|
||||
LimitationsManager.canAddXCollaborators project_id, 1, (error, allowed) =>
|
||||
return next(error) if error?
|
||||
|
||||
if !allowed
|
||||
return res.json { user: false }
|
||||
else
|
||||
{email, privileges} = req.body
|
||||
|
||||
email = EmailHelper.parseEmail(email)
|
||||
if !email? or email == ""
|
||||
return res.status(400).send("invalid email address")
|
||||
|
||||
adding_user_id = req.session?.user?._id
|
||||
CollaboratorsHandler.addEmailToProject project_id, adding_user_id, email, privileges, (error, user_id) =>
|
||||
return next(error) if error?
|
||||
UserGetter.getUser user_id, (error, raw_user) ->
|
||||
return next(error) if error?
|
||||
user = ProjectEditorHandler.buildUserModelView(raw_user, privileges)
|
||||
EditorRealTimeController.emitToRoom(project_id, 'userAddedToProject', user, privileges)
|
||||
return res.json { user: user }
|
||||
|
||||
removeUserFromProject: (req, res, next) ->
|
||||
project_id = req.params.Project_id
|
||||
user_id = req.params.user_id
|
||||
|
|
|
@ -110,16 +110,6 @@ module.exports = CollaboratorsHandler =
|
|||
CollaboratorsHandler.removeUserFromProject project._id, user_id, cb
|
||||
async.series jobs, callback
|
||||
|
||||
addEmailToProject: (project_id, adding_user_id, unparsed_email, privilegeLevel, callback = (error, user) ->) ->
|
||||
email = EmailHelper.parseEmail(unparsed_email)
|
||||
if !email? or email == ""
|
||||
return callback(new Error("no valid email provided: '#{unparsed_email}'"))
|
||||
UserCreator.getUserOrCreateHoldingAccount email, (error, user) ->
|
||||
return callback(error) if error?
|
||||
CollaboratorsHandler.addUserIdToProject project_id, adding_user_id, user._id, privilegeLevel, (error) ->
|
||||
return callback(error) if error?
|
||||
return callback null, user._id
|
||||
|
||||
addUserIdToProject: (project_id, adding_user_id, user_id, privilegeLevel, callback = (error) ->)->
|
||||
Project.findOne { _id: project_id }, { collaberator_refs: 1, readOnly_refs: 1 }, (error, project) ->
|
||||
return callback(error) if error?
|
||||
|
|
|
@ -8,7 +8,6 @@ module.exports =
|
|||
apply: (webRouter, apiRouter) ->
|
||||
webRouter.post '/project/:Project_id/leave', AuthenticationController.requireLogin(), CollaboratorsController.removeSelfFromProject
|
||||
|
||||
webRouter.post '/project/:Project_id/users', AuthorizationMiddlewear.ensureUserCanAdminProject, CollaboratorsController.addUserToProject
|
||||
webRouter.delete '/project/:Project_id/users/:user_id', AuthorizationMiddlewear.ensureUserCanAdminProject, CollaboratorsController.removeUserFromProject
|
||||
|
||||
webRouter.get(
|
||||
|
|
|
@ -25,86 +25,6 @@ describe "CollaboratorsController", ->
|
|||
@project_id = "project-id-123"
|
||||
@callback = sinon.stub()
|
||||
|
||||
describe "addUserToProject", ->
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
Project_id: @project_id
|
||||
@req.body =
|
||||
email: @email = "Joe@example.com"
|
||||
privileges: @privileges = "readOnly"
|
||||
@req.session =
|
||||
user: _id: @adding_user_id = "adding-user-id"
|
||||
@res.json = sinon.stub()
|
||||
@user_id = "mock-user-id"
|
||||
@raw_user = {
|
||||
_id: @user_id, email: "joe@example.com", first_name: "Joe", last_name: "Example", unused: "foo"
|
||||
}
|
||||
@user_view = {
|
||||
id: @user_id, first_name: "Joe", last_name: "Example", email: "joe@example.com"
|
||||
}
|
||||
@LimitationsManager.canAddXCollaborators = sinon.stub().callsArgWith(2, null, true)
|
||||
@ProjectEditorHandler.buildUserModelView = sinon.stub().returns(@user_view)
|
||||
@CollaboratorsHandler.addEmailToProject = sinon.stub().callsArgWith(4, null, @user_id)
|
||||
@UserGetter.getUser = sinon.stub().callsArgWith(1, null, @user)
|
||||
@EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
@callback = sinon.stub()
|
||||
|
||||
describe "when the project can accept more collaborators", ->
|
||||
beforeEach ->
|
||||
@CollaboratorsController.addUserToProject @req, @res, @next
|
||||
|
||||
it "should add the user to the project", ->
|
||||
@CollaboratorsHandler.addEmailToProject
|
||||
.calledWith(@project_id, @adding_user_id, @email.toLowerCase(), @privileges)
|
||||
.should.equal true
|
||||
|
||||
it "should emit a userAddedToProject event", ->
|
||||
@EditorRealTimeController.emitToRoom
|
||||
.calledWith(@project_id, "userAddedToProject", @user_view, @privileges)
|
||||
.should.equal true
|
||||
|
||||
it "should send the user as the response body", ->
|
||||
@res.json
|
||||
.calledWith({
|
||||
user: @user_view
|
||||
})
|
||||
.should.equal true
|
||||
|
||||
describe "when the project cannot accept more collaborators", ->
|
||||
beforeEach ->
|
||||
@LimitationsManager.canAddXCollaborators = sinon.stub().callsArgWith(2, null, false)
|
||||
@CollaboratorsController.addUserToProject @req, @res, @next
|
||||
|
||||
it "should not add the user to the project", ->
|
||||
@CollaboratorsHandler.addEmailToProject.called.should.equal false
|
||||
|
||||
it "should not emit a userAddedToProject event", ->
|
||||
@EditorRealTimeController.emitToRoom.called.should.equal false
|
||||
|
||||
it "should send user: false as the response body", ->
|
||||
@res.json
|
||||
.calledWith({
|
||||
user: false
|
||||
})
|
||||
.should.equal true
|
||||
|
||||
describe "when the email is not valid", ->
|
||||
beforeEach ->
|
||||
@req.body.email = "not-valid"
|
||||
@res.status = sinon.stub().returns @res
|
||||
@res.send = sinon.stub()
|
||||
@CollaboratorsController.addUserToProject @req, @res, @next
|
||||
|
||||
it "should not add the user to the project", ->
|
||||
@CollaboratorsHandler.addEmailToProject.called.should.equal false
|
||||
|
||||
it "should not emit a userAddedToProject event", ->
|
||||
@EditorRealTimeController.emitToRoom.called.should.equal false
|
||||
|
||||
it "should return a 400 response", ->
|
||||
@res.status.calledWith(400).should.equal true
|
||||
@res.send.calledWith("invalid email address").should.equal true
|
||||
|
||||
describe "removeUserFromProject", ->
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
|
|
|
@ -238,38 +238,6 @@ describe "CollaboratorsHandler", ->
|
|||
it "should not add the user again", ->
|
||||
@Project.update.called.should.equal false
|
||||
|
||||
describe "addEmailToProject", ->
|
||||
beforeEach ->
|
||||
@UserCreator.getUserOrCreateHoldingAccount = sinon.stub().callsArgWith(1, null, @user = {_id: @user_id})
|
||||
@CollaboratorHandler.addUserIdToProject = sinon.stub().callsArg(4)
|
||||
|
||||
describe "with a valid email", ->
|
||||
beforeEach ->
|
||||
@CollaboratorHandler.addEmailToProject @project_id, @adding_user_id, (@email = "Joe@example.com"), (@privilegeLevel = "readAndWrite"), @callback
|
||||
|
||||
it "should get the user with the lowercased email", ->
|
||||
@UserCreator.getUserOrCreateHoldingAccount
|
||||
.calledWith(@email.toLowerCase())
|
||||
.should.equal true
|
||||
|
||||
it "should add the user to the project by id", ->
|
||||
@CollaboratorHandler.addUserIdToProject
|
||||
.calledWith(@project_id, @adding_user_id, @user_id, @privilegeLevel)
|
||||
.should.equal true
|
||||
|
||||
it "should return the callback with the user_id", ->
|
||||
@callback.calledWith(null, @user_id).should.equal true
|
||||
|
||||
describe "with an invalid email", ->
|
||||
beforeEach ->
|
||||
@CollaboratorHandler.addEmailToProject @project_id, @adding_user_id, "not-and-email", (@privilegeLevel = "readAndWrite"), @callback
|
||||
|
||||
it "should call the callback with an error", ->
|
||||
@callback.calledWith(new Error()).should.equal true
|
||||
|
||||
it "should not add any users to the proejct", ->
|
||||
@CollaboratorHandler.addUserIdToProject.called.should.equal false
|
||||
|
||||
describe "removeUserFromAllProjects", ->
|
||||
beforeEach (done) ->
|
||||
@CollaboratorHandler.getProjectsUserIsCollaboratorOf = sinon.stub()
|
||||
|
|
Loading…
Reference in a new issue