Expire invitations on SAML sign up and invitation accept
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -303,7 +303,7 @@ func (s *AccountService) AcceptInvitation(
|
||||
// Accept other pending invitations for email in organization
|
||||
invitations := &coredata.Invitations{}
|
||||
onlyPending := coredata.NewInvitationFilter([]coredata.InvitationStatus{coredata.InvitationStatusPending})
|
||||
if err := invitations.AcceptByEmailAndOrganization(
|
||||
if err := invitations.ExpireByEmailAndOrganization(
|
||||
ctx,
|
||||
tx,
|
||||
coredata.NewScopeFromObjectID(invitation.OrganizationID),
|
||||
@@ -311,7 +311,7 @@ func (s *AccountService) AcceptInvitation(
|
||||
invitation.OrganizationID,
|
||||
onlyPending,
|
||||
); err != nil {
|
||||
return fmt.Errorf("cannot accept pending invitations by email: %w", err)
|
||||
return fmt.Errorf("cannot expire pending invitations by email: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -326,10 +326,10 @@ func (s *Service) HandleAssertion(
|
||||
return fmt.Errorf("cannot insert membership profile: %w", err)
|
||||
}
|
||||
|
||||
// Accept all pending invitations for email in organization
|
||||
// Expire all pending invitations for email in organization
|
||||
invitations := &coredata.Invitations{}
|
||||
onlyPending := coredata.NewInvitationFilter([]coredata.InvitationStatus{coredata.InvitationStatusPending})
|
||||
if err := invitations.AcceptByEmailAndOrganization(
|
||||
if err := invitations.ExpireByEmailAndOrganization(
|
||||
ctx,
|
||||
tx,
|
||||
coredata.NewScopeFromObjectID(config.OrganizationID),
|
||||
@@ -337,7 +337,7 @@ func (s *Service) HandleAssertion(
|
||||
config.OrganizationID,
|
||||
onlyPending,
|
||||
); err != nil {
|
||||
return fmt.Errorf("cannot accept pending invitations by email: %w", err)
|
||||
return fmt.Errorf("cannot expire pending invitations by email: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -173,10 +173,10 @@ func (s *Service) CreateUser(
|
||||
return fmt.Errorf("cannot insert membership profile: %w", err)
|
||||
}
|
||||
|
||||
// Accept all pending invitations for email in organization
|
||||
// Expire all pending invitations for email in organization
|
||||
invitations := &coredata.Invitations{}
|
||||
onlyPending := coredata.NewInvitationFilter([]coredata.InvitationStatus{coredata.InvitationStatusPending})
|
||||
err := invitations.AcceptByEmailAndOrganization(
|
||||
err := invitations.ExpireByEmailAndOrganization(
|
||||
ctx,
|
||||
tx,
|
||||
coredata.NewScopeFromObjectID(config.OrganizationID),
|
||||
@@ -186,7 +186,7 @@ func (s *Service) CreateUser(
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot accept pending invitations by email")
|
||||
return fmt.Errorf("cannot expire pending invitations by email")
|
||||
}
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("cannot load membership: %w", err)
|
||||
@@ -375,10 +375,10 @@ func (s *Service) updateUser(
|
||||
membership.Role = coredata.MembershipRoleEmployee
|
||||
needsUpdate = true
|
||||
|
||||
// Accept all pending invitations for email in organization
|
||||
// Expire all pending invitations for email in organization
|
||||
invitations := &coredata.Invitations{}
|
||||
onlyPending := coredata.NewInvitationFilter([]coredata.InvitationStatus{coredata.InvitationStatusPending})
|
||||
if err := invitations.AcceptByEmailAndOrganization(
|
||||
if err := invitations.ExpireByEmailAndOrganization(
|
||||
ctx,
|
||||
tx,
|
||||
coredata.NewScopeFromObjectID(config.OrganizationID),
|
||||
@@ -386,7 +386,7 @@ func (s *Service) updateUser(
|
||||
config.OrganizationID,
|
||||
onlyPending,
|
||||
); err != nil {
|
||||
return fmt.Errorf("cannot accept pending invitations by email: %w", err)
|
||||
return fmt.Errorf("cannot expire pending invitations by email: %w", err)
|
||||
}
|
||||
} else if !*active && membership.State == coredata.MembershipStateActive {
|
||||
membership.State = coredata.MembershipStateInactive
|
||||
|
||||
Reference in New Issue
Block a user