feat(privacy): complete the publication, hiding and preview settings screen
This commit is contained in:
1 parent
c2a8d17195
commit
5edff21d2d
28 files changed
+2230
-428
No files matched your search
@@ -26,7 +26,14 @@ const (
|
||||
fixturePassword = "browser consent fixture 2026"
|
||||
firstOwnerEmail = "consent-owner-one@example.test"
|
||||
secondOwnerEmail = "consent-owner-two@example.test"
|
||||
fixtureTimeout = 90 * time.Second
|
||||
|
||||
// The privacy candidate has its own organizations so that the privacy and
|
||||
// consent browser suites can run side by side without sharing any state.
|
||||
privacyEmail = "privacy-browser@example.test"
|
||||
privacyPassword = "browser privacy fixture 2026"
|
||||
privacyFirstOwnerMail = "privacy-owner-one@example.test"
|
||||
privacySecondOwnerMail = "privacy-owner-two@example.test"
|
||||
fixtureTimeout = 90 * time.Second
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -88,6 +95,10 @@ type fixtureUsers struct {
|
||||
candidate domain.User
|
||||
firstOwner domain.User
|
||||
secondOwner domain.User
|
||||
|
||||
privacyCandidate domain.User
|
||||
privacyFirstOwner domain.User
|
||||
privacySecondOwner domain.User
|
||||
}
|
||||
|
||||
func newFixtureUsers(
|
||||
@@ -107,7 +118,22 @@ func newFixtureUsers(
|
||||
if err != nil {
|
||||
return fixtureUsers{}, err
|
||||
}
|
||||
return fixtureUsers{candidate: candidate, firstOwner: firstOwner, secondOwner: secondOwner}, nil
|
||||
privacyCandidate, err := newFixtureUser(ctx, hasher, privacyEmail, privacyPassword, domain.ScenarioCandidate, registeredAt)
|
||||
if err != nil {
|
||||
return fixtureUsers{}, err
|
||||
}
|
||||
privacyFirstOwner, err := newFixtureOwner(ctx, hasher, privacyFirstOwnerMail, registeredAt)
|
||||
if err != nil {
|
||||
return fixtureUsers{}, err
|
||||
}
|
||||
privacySecondOwner, err := newFixtureOwner(ctx, hasher, privacySecondOwnerMail, registeredAt)
|
||||
if err != nil {
|
||||
return fixtureUsers{}, err
|
||||
}
|
||||
return fixtureUsers{
|
||||
candidate: candidate, firstOwner: firstOwner, secondOwner: secondOwner,
|
||||
privacyCandidate: privacyCandidate, privacyFirstOwner: privacyFirstOwner, privacySecondOwner: privacySecondOwner,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newFixtureOwner(
|
||||
@@ -164,7 +190,10 @@ func seedFixture(
|
||||
now time.Time,
|
||||
) error {
|
||||
return transactor.WithinTransaction(ctx, func(ctx context.Context, unit outbound.UnitOfWork) error {
|
||||
for _, user := range []domain.User{users.candidate, users.firstOwner, users.secondOwner} {
|
||||
for _, user := range []domain.User{
|
||||
users.candidate, users.firstOwner, users.secondOwner,
|
||||
users.privacyCandidate, users.privacyFirstOwner, users.privacySecondOwner,
|
||||
} {
|
||||
if err := unit.Users().Create(ctx, user); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -230,10 +259,90 @@ func seedFixture(
|
||||
if err := grantFixtureContactConsent(ctx, service, unit, users.candidate.ID, secondOrganization, c4Text.Version(), domain.ContactFieldPhone); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return seedPrivacyCandidate(ctx, unit, service, users, now)
|
||||
})
|
||||
}
|
||||
|
||||
// seedPrivacyCandidate gives the privacy browser suite a candidate whose
|
||||
// publication consent is active, with one company that holds a contact consent
|
||||
// and read the card and one company that only read the card. The reads are
|
||||
// recorded the way an authorized organization read leaves them, because the
|
||||
// organization read path needs search results that do not exist yet.
|
||||
func seedPrivacyCandidate(
|
||||
ctx context.Context,
|
||||
unit outbound.UnitOfWork,
|
||||
service *consent.Service,
|
||||
users fixtureUsers,
|
||||
now time.Time,
|
||||
) error {
|
||||
firstOrganization, err := createOrganization(ctx, unit, users.privacyFirstOwner.ID, "Приватная компания А", now)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
secondOrganization, err := createOrganization(ctx, unit, users.privacySecondOwner.ID, "Приватная компания Б", now)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c1Text, err := unit.ConsentTexts().Current(ctx, domain.ConsentPurposePersonalData, now)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := service.GrantAtRegistration(
|
||||
ctx, unit, users.privacyCandidate.ID, users.privacyCandidate.RegistrationVersion, c1Text.Version(),
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
c2Text, err := unit.ConsentTexts().Current(ctx, domain.ConsentPurposePublication, now)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := service.GrantInSettings(ctx, unit, consent.SettingsGrantInput{
|
||||
SubjectID: users.privacyCandidate.ID,
|
||||
Purpose: domain.ConsentPurposePublication,
|
||||
TextVersion: c2Text.Version(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
c4Text, err := unit.ConsentTexts().Current(ctx, domain.ConsentPurposeContactDisclosure, now)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := grantFixtureContactConsent(
|
||||
ctx, service, unit, users.privacyCandidate.ID, firstOrganization, c4Text.Version(), domain.ContactFieldEmail,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reads := []domain.CandidateCardAccessInput{
|
||||
{
|
||||
CandidateID: users.privacyCandidate.ID, OrganizationID: firstOrganization.ID(), ActorID: users.privacyFirstOwner.ID,
|
||||
Kind: domain.CandidateCardAccessCardViewed, ProjectionFields: []domain.CardField{domain.CardFieldCategories},
|
||||
OccurredAt: now.Add(-3 * time.Hour),
|
||||
},
|
||||
{
|
||||
CandidateID: users.privacyCandidate.ID, OrganizationID: firstOrganization.ID(), ActorID: users.privacyFirstOwner.ID,
|
||||
Kind: domain.CandidateCardAccessContactRead, ContactFields: []domain.ContactField{domain.ContactFieldEmail},
|
||||
OccurredAt: now.Add(-2 * time.Hour),
|
||||
},
|
||||
{
|
||||
CandidateID: users.privacyCandidate.ID, OrganizationID: secondOrganization.ID(), ActorID: users.privacySecondOwner.ID,
|
||||
Kind: domain.CandidateCardAccessCardViewed, ProjectionFields: []domain.CardField{domain.CardFieldCategories},
|
||||
OccurredAt: now.Add(-1 * time.Hour),
|
||||
},
|
||||
}
|
||||
for _, input := range reads {
|
||||
access, err := domain.NewCandidateCardAccess(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := unit.PrivacyView().RecordCandidateCardAccess(ctx, access); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createOrganization(
|
||||
ctx context.Context,
|
||||
unit outbound.UnitOfWork,
|
||||
|
||||
Reference in new issue
Block a user