WIP: wire up share-modal frontend to invite system

This commit is contained in:
Shane Kilkelly 2016-07-25 15:07:14 +01:00
parent b3add65de1
commit 16dcbe2cd4
5 changed files with 25 additions and 27 deletions

View file

@ -25,7 +25,7 @@ module.exports = CollaboratorsInviteController =
return next(error) if error?
if !allowed
logger.log {projectId, email, sendingUserId}, "not allowed to invite more users to project"
return res.json {inviteId: null}
return res.json {invite: null}
{email, privileges} = req.body
email = mimelib.parseAddresses(email or "")[0]?.address?.toLowerCase()
if !email? or email == ""
@ -36,7 +36,7 @@ module.exports = CollaboratorsInviteController =
logger.err {projectId, email, sendingUserId}, "error creating project invite"
return next(err)
logger.log {projectId, email, sendingUserId}, "invite created"
return res.json {inviteId: invite._id}
return res.json {invite: invite}
revokeInvite: (req, res, next) ->
projectId = req.params.Project_id

View file

@ -9,13 +9,19 @@ ObjectId = Schema.ObjectId
THIRTY_DAYS_IN_SECONDS = 60 * 60 * 24 * 30
ProjectInviteSchema = new Schema
email: String
token: String
sendingUserId: ObjectId
projectId: ObjectId
privileges: String
createdAt: {type: Date, default: Date.now, index: {expiresAfterSeconds: THIRTY_DAYS_IN_SECONDS}}
ProjectInviteSchema = new Schema(
{
email: String
token: String
sendingUserId: ObjectId
projectId: ObjectId
privileges: String
createdAt: {type: Date, default: Date.now, index: {expiresAfterSeconds: THIRTY_DAYS_IN_SECONDS}}
},
{
collection: 'projectInvites'
}
)
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: Settings.mongo.poolSize || 10)

View file

@ -48,7 +48,6 @@ define [
projectInvites.getInvites().then(
(response) ->
$scope.state.invites = response?.data?.invites
$scope.state.invites = [{_id: "wat", email: "user@example.com"}]
, (response) ->
console.error response
)
@ -86,8 +85,9 @@ define [
return addNextMember()
# TODO: double-check if member.type == 'user' needs to be an invite
console.log ">> inviting", member
if member.type == "user"
request = projectMembers.addMember(member.email, $scope.inputs.privileges)
request = projectInvites.sendInvite(member.email, $scope.inputs.privileges)
else if member.type == "group"
request = projectMembers.addGroup(member.id, $scope.inputs.privileges)
else # Not an auto-complete object, so email == display
@ -95,14 +95,9 @@ define [
request
.success (data) ->
if data.users?
users = data.users
else if data.user?
users = [data.user]
else
users = []
$scope.project.members.push users...
if data.invite
invite = data.invite
$scope.state.invites.push invite
setTimeout () ->
# Give $scope a chance to update $scope.canAddCollaborators
# with new collaborator information.

View file

@ -17,13 +17,12 @@ define [
privileges: privileges
_csrf: window.csrfToken
})
addGroup: (group_id, privileges) ->
$http.post("/project/#{ide.project_id}/group", {
group_id: group_id
privileges: privileges
_csrf: window.csrfToken
})
}
]
]

View file

@ -65,8 +65,6 @@ describe "CollaboratorsInviteController", ->
@next.callCount.should.equal 1
@next.firstCall.args[0].should.be.instanceof Error
# # # #
describe 'inviteToProject', ->
beforeEach ->
@ -101,7 +99,7 @@ describe "CollaboratorsInviteController", ->
it 'should produce json response', ->
@res.json.callCount.should.equal 1
({inviteId: @invite._id}).should.deep.equal(@res.json.firstCall.args[0])
({invite: @invite}).should.deep.equal(@res.json.firstCall.args[0])
it 'should have called canAddXCollaborators', ->
@LimitationsManager.canAddXCollaborators.callCount.should.equal 1
@ -117,9 +115,9 @@ describe "CollaboratorsInviteController", ->
@LimitationsManager.canAddXCollaborators = sinon.stub().callsArgWith(2, null, false)
@CollaboratorsInviteController.inviteToProject @req, @res, @next
it 'should produce json response without inviteId', ->
it 'should produce json response without an invite', ->
@res.json.callCount.should.equal 1
({inviteId: null}).should.deep.equal(@res.json.firstCall.args[0])
({invite: null}).should.deep.equal(@res.json.firstCall.args[0])
it 'should not have called inviteToProject', ->
@CollaboratorsInviteHandler.inviteToProject.callCount.should.equal 0