Skip to content

Commit

Permalink
Move invite accept to before personal team create
Browse files Browse the repository at this point in the history
fixes #4333
  • Loading branch information
hardillb committed Aug 23, 2024
1 parent 782c37a commit d32508f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions forge/lib/userTeam.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ const crypto = require('crypto')
* - accepts any invitations matching the email
*/
async function completeUserSignup (app, user) {
// Process invites first to see if user is in any teams
const pendingInvitations = await app.db.models.Invitation.forExternalEmail(user.email)
for (let i = 0; i < pendingInvitations.length; i++) {
const invite = pendingInvitations[i]
// For now we'll auto-accept any invites for this user
// See https://github.com/FlowFuse/flowfuse/issues/275#issuecomment-1040113991
await app.db.controllers.Invitation.acceptInvitation(invite, user)
// // If we go back to having the user be able to accept invites
// // as a secondary step, the following code will convert the external
// // invite into an internal one.
// invite.external = false
// invite.inviteeId = user.id
// await invite.save()
}

let personalTeam
if (app.settings.get('user:team:auto-create')) {
const teamLimit = app.license.get('teams')
Expand Down Expand Up @@ -43,19 +58,6 @@ async function completeUserSignup (app, user) {
}
}
}
const pendingInvitations = await app.db.models.Invitation.forExternalEmail(user.email)
for (let i = 0; i < pendingInvitations.length; i++) {
const invite = pendingInvitations[i]
// For now we'll auto-accept any invites for this user
// See https://github.com/FlowFuse/flowfuse/issues/275#issuecomment-1040113991
await app.db.controllers.Invitation.acceptInvitation(invite, user)
// // If we go back to having the user be able to accept invites
// // as a secondary step, the following code will convert the external
// // invite into an internal one.
// invite.external = false
// invite.inviteeId = user.id
// await invite.save()
}

// only create a starting instance if the flag is set and this user and their teams have no instances
if (app.settings.get('user:team:auto-create:instanceType') &&
Expand Down

0 comments on commit d32508f

Please sign in to comment.