Skip to content

Commit

Permalink
Merge pull request #4397 from FlowFuse/4333-only-create-team-if-no-teams
Browse files Browse the repository at this point in the history
Move invite accept to before personal team create
  • Loading branch information
joepavitt authored Aug 23, 2024
2 parents 33389ca + d32508f commit 87e8be6
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 87e8be6

Please sign in to comment.