mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Improve logging, add acceptance tests for joinProject json
This commit is contained in:
parent
b68af254ff
commit
da40f54d55
2 changed files with 30 additions and 0 deletions
|
@ -31,6 +31,7 @@ module.exports = EditorHttpController =
|
|||
ProjectDeleter.unmarkAsDeletedByExternalSource project_id
|
||||
|
||||
_buildJoinProjectView: (project_id, user_id, callback = (error, project, privilegeLevel) ->) ->
|
||||
logger.log {project_id, user_id}, "building the joinProject view"
|
||||
ProjectGetter.getProjectWithoutDocLines project_id, (error, project) ->
|
||||
return callback(error) if error?
|
||||
return callback(new Error("not found")) if !project?
|
||||
|
@ -41,9 +42,11 @@ module.exports = EditorHttpController =
|
|||
AuthorizationManager.getPrivilegeLevelForProject user_id, project_id, (error, privilegeLevel) ->
|
||||
return callback(error) if error?
|
||||
if !privilegeLevel? or privilegeLevel == PrivilegeLevels.NONE
|
||||
logger.log {project_id, user_id, privilegeLevel}, "not an acceptable privilege level, returning null"
|
||||
return callback null, null, false
|
||||
CollaboratorsInviteHandler.getAllInvites project_id, (error, invites) ->
|
||||
return callback(error) if error?
|
||||
logger.log {project_id, user_id, privilegeLevel}, "returning project model view"
|
||||
callback(null,
|
||||
ProjectEditorHandler.buildProjectModelView(project, members, invites),
|
||||
privilegeLevel
|
||||
|
|
|
@ -95,6 +95,19 @@ tryGetInviteList = (user, projectId, callback=(err, response, body)->) ->
|
|||
json: true
|
||||
}, callback
|
||||
|
||||
tryJoinProject = (user, projectId, callback=(err, response, body)->) ->
|
||||
user.getCsrfToken (error) =>
|
||||
return callback(error) if error?
|
||||
user.request.post {
|
||||
url: "/project/#{projectId}/join"
|
||||
qs: {user_id: user._id}
|
||||
auth:
|
||||
user: settings.apis.web.user
|
||||
pass: settings.apis.web.pass
|
||||
sendImmediately: true
|
||||
json: true
|
||||
jar: false
|
||||
}, callback
|
||||
|
||||
# Expectations
|
||||
expectProjectAccess = (user, projectId, callback=(err,result)->) ->
|
||||
|
@ -185,6 +198,15 @@ expectInviteListCount = (user, projectId, count, callback=(err)->) ->
|
|||
expect(body.invites.length).to.equal count
|
||||
callback()
|
||||
|
||||
expectInvitesInJoinProjectCount = (user, projectId, count, callback=(err,result)->) ->
|
||||
tryJoinProject user, projectId, (err, response, body) ->
|
||||
expect(err).to.be.oneOf [null, undefined]
|
||||
expect(response.statusCode).to.equal 200
|
||||
expect(body.project).to.contain.keys ['invites']
|
||||
expect(body.project.invites.length).to.equal count
|
||||
callback()
|
||||
|
||||
|
||||
|
||||
describe "ProjectInviteTests", ->
|
||||
before (done) ->
|
||||
|
@ -245,8 +267,12 @@ describe "ProjectInviteTests", ->
|
|||
@invite = invite
|
||||
cb()
|
||||
(cb) => expectInviteListCount @sendingUser, @projectId, 1, cb
|
||||
# check the joinProject view
|
||||
(cb) => expectInvitesInJoinProjectCount @sendingUser, @projectId, 1, cb
|
||||
# revoke invite
|
||||
(cb) => revokeInvite @sendingUser, @projectId, @invite._id, cb
|
||||
(cb) => expectInviteListCount @sendingUser, @projectId, 0, cb
|
||||
(cb) => expectInvitesInJoinProjectCount @sendingUser, @projectId, 0, cb
|
||||
], done
|
||||
|
||||
it 'should allow the project owner to many invites at once', (done) ->
|
||||
|
@ -268,6 +294,7 @@ describe "ProjectInviteTests", ->
|
|||
cb()
|
||||
# should have two
|
||||
(cb) => expectInviteListCount @sendingUser, @projectId, 2, cb
|
||||
(cb) => expectInvitesInJoinProjectCount @sendingUser, @projectId, 2, cb
|
||||
# revoke first
|
||||
(cb) => revokeInvite @sendingUser, @projectId, @inviteOne._id, cb
|
||||
(cb) => expectInviteListCount @sendingUser, @projectId, 1, cb
|
||||
|
|
Loading…
Reference in a new issue