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

@@ -62,6 +62,8 @@ type testState struct {
// and notified the delivered invitations that were notified.
charged []uuid.UUID
notified []uuid.UUID
// jobs holds the scheduled jobs by kind and key.
jobs map[string]domain.ScheduledJob
}
func newTestState() testState {
@@ -80,6 +82,7 @@ func newTestState() testState {
profiles: map[uuid.UUID]domain.CandidateProfile{},
publications: map[uuid.UUID]domain.Publication{},
hidden: map[[2]uuid.UUID]bool{},
jobs: map[string]domain.ScheduledJob{},
}
}
@@ -136,6 +139,9 @@ func (state testState) clone() testState {
}
cloned.charged = slices.Clone(state.charged)
cloned.notified = slices.Clone(state.notified)
for key, job := range state.jobs {
cloned.jobs[key] = job
}
return cloned
}
@@ -193,6 +199,26 @@ func (unit *testUnit) InvitationSendResults() outbound.InvitationSendResultRepos
func (unit *testUnit) InvitationDeclineResults() outbound.InvitationDeclineResultRepository {
return testInvitations{state: unit.state}
}
func (unit *testUnit) ScheduledJobs() outbound.JobScheduler { return testJobs{state: unit.state} }
// testJobs keeps the scheduled jobs of one transaction: the first schedule of a
// kind and key wins, as in the database.
type testJobs struct {
state *testState
}
func (jobs testJobs) Schedule(_ context.Context, job domain.ScheduledJob) (bool, error) {
key := job.Kind() + "\x00" + job.Key()
if _, exists := jobs.state.jobs[key]; exists {
return false, nil
}
jobs.state.jobs[key] = job
return true, nil
}
func (jobs testJobs) Cancel(context.Context, string, string) (bool, error) {
return false, errors.New("testJobs.Cancel - not used by the invitation usecases")
}
type testUsers struct {
outbound.UserRepository
@@ -542,7 +568,7 @@ func TestCreateStoresADraftForAVisibleCandidateWithTheDefaultPeriod(t *testing.T
}
if view.State != domain.InvitationDraft || view.Version != 1 || view.TermsVersion != 1 || view.ResponsePeriodDays != 7 ||
view.CandidateHandle != handle || view.SalaryFit != domain.InvitationSalaryNotAvailable ||
view.ContactAccess != domain.InvitationContactAccessNone || view.ResponseDeadlineAt != nil {
view.ContactAccess.Status != domain.InvitationContactAccessNone || len(view.ContactAccess.Fields) != 0 || view.ResponseDeadlineAt != nil {
t.Fatalf("created view = %+v, want an unsent version 1 with the default period for the card handle", view.InvitationSnapshot)
}
state := test.transactor.snapshot()