feat(invitations): check contact grants on every read, cap pending invitations, and expire them at the deadline

This commit is contained in:
shira committed 2026-10-09 19:06:50 +03:00
1 parent 676b3c6e24
commit 12a7213d4a
67 files changed
+4255 -149

No files matched your search

@@ -268,15 +268,17 @@ func (repository invitationRepository) GetCreationResult(
}
// insertEventPrerequisites checks that the audit event describes the version
// that the caller is about to store.
// that the caller is about to store. Only the server's expiry has no actor.
func (repository invitationRepository) insertEventPrerequisites(
location string,
invitation domain.Invitation,
event domain.InvitationEvent,
version int64,
) error {
actorMissing := event.ActorID == uuid.Nil
if event.ID == uuid.Nil || event.InvitationID != invitation.ID() || event.OrganizationID != invitation.OrganizationID() ||
event.Version != version || event.TermsVersion != invitation.TermsVersion() || event.ActorID == uuid.Nil ||
event.Version != version || event.TermsVersion != invitation.TermsVersion() ||
actorMissing != (event.Kind == domain.InvitationEventExpired) ||
!validStoredInvitationTime(event.OccurredAt) {
return fmt.Errorf("%s - the audit event does not describe the stored version: %w", location, domain.ErrInvalidInvitation)
}
@@ -311,9 +313,14 @@ func (repository invitationRepository) insertEvent(ctx context.Context, location
fields = append(fields, string(field))
}
slices.Sort(fields)
// The expiry is the server's own change, so its event has no actor.
actor := pgtype.UUID{}
if event.ActorID != uuid.Nil {
actor = pgUUID(event.ActorID)
}
if err := repository.queries.InsertInvitationEvent(ctx, sqlc.InsertInvitationEventParams{
ID: pgUUID(event.ID), InvitationID: pgUUID(event.InvitationID), OrganizationID: pgUUID(event.OrganizationID),
Version: event.Version, TermsVersion: event.TermsVersion, Kind: string(event.Kind), ActorID: pgUUID(event.ActorID),
Version: event.Version, TermsVersion: event.TermsVersion, Kind: string(event.Kind), ActorID: actor,
ChangedFields: fields, OccurredAt: pgTime(event.OccurredAt),
}); err != nil {
return fmt.Errorf("%s - record audit event: %w", location, mapInvitationError(err))