feat(notifications): send product notifications with a rights check right before each send

This commit is contained in:
shira committed 2026-10-09 20:38:39 +03:00
1 parent a856066316
commit 623d41b969
59 files changed
+4125 -1126

No files matched your search

@@ -99,6 +99,15 @@ type Querier interface {
// now is the application clock. Unknown deliveries without a scheduled retry
// and quota waits with an unknown reset wait for an operator.
ClaimDueDelivery(ctx context.Context, arg ClaimDueDeliveryParams) (ClaimDueDeliveryRow, error)
// Claims the most overdue product notification, under the same rules as
// ClaimDueDelivery: a lease in the database clock, the configured provider
// account or a rebind of a delivery before its first attempt, and no live
// lease. It reads deliveries_product_due_idx, whose predicate repeats the
// literal kind below, so the backlog of service mail never enters the scan.
// A notification is claimed here whatever its subject; the sending worker
// checks the subject's rights after the claim and cancels a notice whose
// basis no longer holds.
ClaimDueProductDelivery(ctx context.Context, arg ClaimDueProductDeliveryParams) (ClaimDueProductDeliveryRow, error)
// Claims up to batch_limit jobs of the listed kinds in one statement: jobs
// whose available_at has passed, and running jobs whose lease expired
// because their worker stopped without finishing them. Rows that another
@@ -343,6 +352,16 @@ type Querier interface {
GetInvitationAcceptResult(ctx context.Context, scopeHash []byte) (GetInvitationAcceptResultRow, error)
GetInvitationCreationResult(ctx context.Context, scopeHash []byte) (string, error)
GetInvitationDeclineResult(ctx context.Context, scopeHash []byte) (GetInvitationDeclineResultRow, error)
// Reads the standing of an invitation notice in one statement, for the rights
// check before the send. The recipient is matched by ID; the invitation must
// be addressed to that recipient and belong to the organization of the
// subject, otherwise it is not found. It reads no address and no contact:
// the recipient address is returned only as its comparison key. The hiding
// is the candidate's own current state. The publication is read through the
// effective view, so a publication whose C2 consent was revoked does not count
// as current. A missing account or invitation gives false flags and NULL
// columns.
GetInvitationNoticeStanding(ctx context.Context, arg GetInvitationNoticeStandingParams) (GetInvitationNoticeStandingRow, error)
GetInvitationSendResult(ctx context.Context, scopeHash []byte) (GetInvitationSendResultRow, error)
// The caller holds the attempt row lock, so the last mark is stable.
GetLastAssessmentOriginMark(ctx context.Context, attemptID pgtype.UUID) (AssessmentAttemptOriginMark, error)
@@ -864,7 +883,7 @@ type Querier interface {
// finds the row deleted. The account cleanup and the cascade from users take
// the same row lock, so a request is never converted for an account whose
// deletion is in progress without one of the two transactions waiting.
LockMailRequest(ctx context.Context, id pgtype.UUID) (MailRequest, error)
LockMailRequest(ctx context.Context, id pgtype.UUID) (LockMailRequestRow, error)
// Locks the next relay batch. For each aggregate only its earliest unpublished
// event (lowest aggregate_version, then position) qualifies, so a relay never
// holds a later version while an earlier one is still pending, whether that