feat(invitations): add organization invitation drafts with salary range rules

This commit is contained in:
shira committed 2026-10-09 14:28:36 +03:00
1 parent 28337d84cb
commit bd23c839fd
36 files changed
+7018 -83

No files matched your search

+2
View File
@@ -41,6 +41,7 @@ func newAPIHandler(
catalogHandler *v1.CatalogHandler,
organizationHandler *v1.OrganizationHandler,
needHandler *v1.NeedHandler,
invitationHandler *v1.InvitationHandler,
supportHandler *v1.SupportHandler,
assessmentHandler *v1.AssessmentHandler,
assessmentSignalHandler *v1.AssessmentSignalHandler,
@@ -57,6 +58,7 @@ func newAPIHandler(
v1.WithCatalog(catalogHandler),
v1.WithOrganization(organizationHandler),
v1.WithNeed(needHandler),
v1.WithInvitation(invitationHandler),
v1.WithSupport(supportHandler),
v1.WithAssessment(assessmentHandler),
v1.WithAssessmentSignals(assessmentSignalHandler),
+56
View File
@@ -0,0 +1,56 @@
package bootstrap
import (
"context"
"fmt"
"log/slog"
"time"
"lincodex/backend/config"
v1 "lincodex/backend/internal/adapter/primary/http/v1"
"lincodex/backend/internal/adapter/secondary/postgres"
"lincodex/backend/internal/usecase/identity"
"lincodex/backend/internal/usecase/invitation"
)
const invitationPoolMaxConns = 4
// newInvitationHandler builds the invitation draft operations. They resolve a
// card handle through the same visibility service as the card read and the
// search, so the pseudonym key and the cohort rules are the ones of the cards.
func newInvitationHandler(
ctx context.Context,
settings config.Config,
logger *slog.Logger,
keyring *identity.Keyring,
) (*v1.InvitationHandler, func(), error) {
if settings.DatabaseURL == "" {
logger.Warn("invitation operations are not served because DATABASE_URL is not set")
return nil, func() {}, nil
}
if keyring == nil {
return nil, nil, fmt.Errorf("bootstrap.newInvitationHandler - identity keyring must be set")
}
key, err := keyring.CandidateViewPseudonymKey()
if err != nil {
return nil, nil, fmt.Errorf("bootstrap.newInvitationHandler - derive projection key: %w", err)
}
pool, err := postgres.NewSizedPool(ctx, settings.DatabaseURL, invitationPoolMaxConns)
if err != nil {
return nil, nil, fmt.Errorf("bootstrap.newInvitationHandler - create pool: %w", err)
}
transactor := postgres.NewTransactor(pool)
views, err := newCandidateViewService(pool, transactor, key)
if err != nil {
pool.Close()
return nil, nil, fmt.Errorf("bootstrap.newInvitationHandler - create view service: %w", err)
}
service, err := invitation.NewService(invitation.Dependencies{
Transactor: transactor, Keyring: keyring, PseudonymKey: key, Candidates: views.ResolveCandidateHandle, Clock: time.Now,
})
if err != nil {
pool.Close()
return nil, nil, fmt.Errorf("bootstrap.newInvitationHandler - create service: %w", err)
}
return v1.NewInvitationHandler(service), pool.Close, nil
}
+1
View File
@@ -53,6 +53,7 @@ func initialize(
newCatalogHandler,
newOrganizationHandler,
newNeedHandler,
newInvitationHandler,
newSupportHandler,
newAssessmentHandler,
newAssessmentSignalHandler,
+81 -53
View File
@@ -122,7 +122,7 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
supportHandler, cleanup11, err := newSupportHandler(ctx, config2, logger, keyring)
invitationHandler, cleanup11, err := newInvitationHandler(ctx, config2, logger, keyring)
if err != nil {
cleanup10()
cleanup9()
@@ -136,7 +136,7 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
assessmentHandler, cleanup12, err := newAssessmentHandler(ctx, config2, logger, keyring)
supportHandler, cleanup12, err := newSupportHandler(ctx, config2, logger, keyring)
if err != nil {
cleanup11()
cleanup10()
@@ -151,7 +151,7 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
assessmentSignalHandler, cleanup13, err := newAssessmentSignalHandler(ctx, config2, logger, keyring)
assessmentHandler, cleanup13, err := newAssessmentHandler(ctx, config2, logger, keyring)
if err != nil {
cleanup12()
cleanup11()
@@ -167,7 +167,7 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
privacyHandler, cleanup14, err := newPrivacyHandler(ctx, config2, logger, keyring)
assessmentSignalHandler, cleanup14, err := newAssessmentSignalHandler(ctx, config2, logger, keyring)
if err != nil {
cleanup13()
cleanup12()
@@ -184,7 +184,7 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
evidenceHandler, cleanup15, err := newEvidenceHandler(ctx, config2, logger, keyring)
privacyHandler, cleanup15, err := newPrivacyHandler(ctx, config2, logger, keyring)
if err != nil {
cleanup14()
cleanup13()
@@ -202,7 +202,7 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
notificationHandler, cleanup16, err := newNotificationHandler(ctx, config2, logger)
evidenceHandler, cleanup16, err := newEvidenceHandler(ctx, config2, logger, keyring)
if err != nil {
cleanup15()
cleanup14()
@@ -221,7 +221,7 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
matchHandler, cleanup17, err := newMatchHandler(ctx, config2, logger, keyring)
notificationHandler, cleanup17, err := newNotificationHandler(ctx, config2, logger)
if err != nil {
cleanup16()
cleanup15()
@@ -241,52 +241,31 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
handler := newAPIHandler(healthHandler, responder, identityHandler, consentHandler, profileHandler, questionnaireHandler, catalogHandler, organizationHandler, needHandler, supportHandler, assessmentHandler, assessmentSignalHandler, privacyHandler, evidenceHandler, notificationHandler, matchHandler)
matchHandler, cleanup18, err := newMatchHandler(ctx, config2, logger, keyring)
if err != nil {
cleanup17()
cleanup16()
cleanup15()
cleanup14()
cleanup13()
cleanup12()
cleanup11()
cleanup10()
cleanup9()
cleanup8()
cleanup7()
cleanup6()
cleanup5()
cleanup4()
cleanup3()
cleanup2()
cleanup()
return nil, nil, err
}
handler := newAPIHandler(healthHandler, responder, identityHandler, consentHandler, profileHandler, questionnaireHandler, catalogHandler, organizationHandler, needHandler, invitationHandler, supportHandler, assessmentHandler, assessmentSignalHandler, privacyHandler, evidenceHandler, notificationHandler, matchHandler)
sessionSecurity := newSessionSecurity(identityHandler)
v := newTrustedProxies(config2)
httpHandler, err := newRouter(healthHandler, handler, sessionSecurity, responder, metrics, logger, v, organizationHandler)
if err != nil {
cleanup17()
cleanup16()
cleanup15()
cleanup14()
cleanup13()
cleanup12()
cleanup11()
cleanup10()
cleanup9()
cleanup8()
cleanup7()
cleanup6()
cleanup5()
cleanup4()
cleanup3()
cleanup2()
cleanup()
return nil, nil, err
}
relay, cleanup18, err := newOutboxRelay(ctx, config2, logger, metrics)
if err != nil {
cleanup17()
cleanup16()
cleanup15()
cleanup14()
cleanup13()
cleanup12()
cleanup11()
cleanup10()
cleanup9()
cleanup8()
cleanup7()
cleanup6()
cleanup5()
cleanup4()
cleanup3()
cleanup2()
cleanup()
return nil, nil, err
}
bootstrapEventConsumers, cleanup19, err := newEventConsumers(ctx, config2, logger, metrics)
if err != nil {
cleanup18()
cleanup17()
@@ -308,7 +287,29 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
worker, cleanup20, err := newJobWorker(ctx, config2, logger, metrics)
relay, cleanup19, err := newOutboxRelay(ctx, config2, logger, metrics)
if err != nil {
cleanup18()
cleanup17()
cleanup16()
cleanup15()
cleanup14()
cleanup13()
cleanup12()
cleanup11()
cleanup10()
cleanup9()
cleanup8()
cleanup7()
cleanup6()
cleanup5()
cleanup4()
cleanup3()
cleanup2()
cleanup()
return nil, nil, err
}
bootstrapEventConsumers, cleanup20, err := newEventConsumers(ctx, config2, logger, metrics)
if err != nil {
cleanup19()
cleanup18()
@@ -331,7 +332,7 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
mailsenderWorker, cleanup21, err := newMailSenderWorker(ctx, config2, logger, metrics, mailSender)
worker, cleanup21, err := newJobWorker(ctx, config2, logger, metrics)
if err != nil {
cleanup20()
cleanup19()
@@ -355,7 +356,7 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
sampler, cleanup22, err := newDeliveryMetrics(ctx, config2, logger, metrics)
mailsenderWorker, cleanup22, err := newMailSenderWorker(ctx, config2, logger, metrics, mailSender)
if err != nil {
cleanup21()
cleanup20()
@@ -380,8 +381,35 @@ func initialize(ctx context.Context, config2 config.Config, logger *slog.Logger,
cleanup()
return nil, nil, err
}
sampler, cleanup23, err := newDeliveryMetrics(ctx, config2, logger, metrics)
if err != nil {
cleanup22()
cleanup21()
cleanup20()
cleanup19()
cleanup18()
cleanup17()
cleanup16()
cleanup15()
cleanup14()
cleanup13()
cleanup12()
cleanup11()
cleanup10()
cleanup9()
cleanup8()
cleanup7()
cleanup6()
cleanup5()
cleanup4()
cleanup3()
cleanup2()
cleanup()
return nil, nil, err
}
application := NewApplication(config2, httpHandler, metrics, logger, mailSender, relay, bootstrapEventConsumers, worker, mailsenderWorker, sampler)
return application, func() {
cleanup23()
cleanup22()
cleanup21()
cleanup20()