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

@@ -94,6 +94,9 @@ func (effects consentRevocationEffects) Apply(
return fmt.Errorf("consentRevocationEffects.Apply - close publication: %w", err)
}
}
if err := effects.closeContactGrants(ctx, revocation, records); err != nil {
return fmt.Errorf("consentRevocationEffects.Apply - close contact grants: %w", err)
}
if err := effects.appendRevocationIntent(ctx, revocation, records); err != nil {
return fmt.Errorf("consentRevocationEffects.Apply - append outbox intent: %w", err)
}
@@ -145,6 +148,42 @@ func (effects consentRevocationEffects) closePublication(
return nil
}
// closeContactGrants closes the grants that the revoked consent gave. A C2
// revocation closes every grant of the candidate, because it closes the
// profile for every organization, whether or not a publication row exists. A
// C4 revocation closes the grants of its organization that name the revoked
// records, so the grants of other organizations and other invitations stay.
func (effects consentRevocationEffects) closeContactGrants(
ctx context.Context,
revocation domain.ConsentRevocation,
records []domain.ConsentRecord,
) error {
const location = "consentRevocationEffects.closeContactGrants"
switch revocation.Purpose() {
case domain.ConsentPurposePublication:
return closeActiveContactGrants(ctx, effects.queries, contactGrantClosure{
candidateID: revocation.SubjectID(), reason: domain.ContactRevocationVisibilityClosed,
at: revocation.RevokedAt(),
})
case domain.ConsentPurposeContactDisclosure:
recordIDs := make([]uuid.UUID, 0, len(records))
for _, record := range records {
recordIDs = append(recordIDs, record.ID())
}
if len(recordIDs) == 0 {
return fmt.Errorf("%s - revoked C4 record IDs are required: %w", location, domain.ErrInvalidConsent)
}
return closeActiveContactGrants(ctx, effects.queries, contactGrantClosure{
candidateID: revocation.SubjectID(), organizationID: revocation.OrganizationID(),
consentRecordIDs: recordIDs, reason: domain.ContactRevocationConsentRevoked, at: revocation.RevokedAt(),
})
case domain.ConsentPurposePersonalData, domain.ConsentPurposeAutoCategorization, domain.ConsentPurposeFSPImport:
// These purposes never gave a contact grant, so their revocation closes none.
return nil
}
return fmt.Errorf("%s - purpose %q has no grant rule: %w", location, revocation.Purpose(), domain.ErrInvalidConsent)
}
type consentRevocationPayload struct {
RevocationID uuid.UUID `json:"revocation_id"`
RecordID uuid.UUID `json:"record_id"`