feat(accounts): add consent settings and organization management
This commit is contained in:
1 parent
24638d46d2
commit
391af7a1ef
83 files changed
+10198
-613
No files matched your search
@@ -25,6 +25,10 @@ var directPublicationReaders = []string{
|
||||
"UpdateCandidatePublication",
|
||||
}
|
||||
|
||||
var ownerScopedPublicationQueries = []string{
|
||||
"LockCandidatePublicationForConsentRevocation",
|
||||
}
|
||||
|
||||
var (
|
||||
// sqlc accepts both comment forms and tolerates trailing whitespace.
|
||||
queryHeaderPattern = regexp.MustCompile(`(?m)^(?:--|/\*)[ \t]*name:[ \t]+(\w+)[ \t]+:\w+[ \t]*(?:\*/)?[ \t]*$`)
|
||||
@@ -43,6 +47,7 @@ func TestOnlyTheSettingsQueriesReadThePublicationTableDirectly(t *testing.T) {
|
||||
t.Fatalf("list the query files = %v, %v", files, err)
|
||||
}
|
||||
var found []string
|
||||
statements := make(map[string]string)
|
||||
for _, file := range files {
|
||||
content, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
@@ -63,6 +68,7 @@ func TestOnlyTheSettingsQueriesReadThePublicationTableDirectly(t *testing.T) {
|
||||
name := text[header[2]:header[3]]
|
||||
if publicationTableName.MatchString(statement) {
|
||||
found = append(found, name)
|
||||
statements[name] = strings.Join(strings.Fields(statement), " ")
|
||||
}
|
||||
if effectiveViewName.MatchString(statement) && !hiddenTableName.MatchString(statement) {
|
||||
t.Errorf("%s reads candidate_effective_publications without excluding candidate_hidden_organizations", name)
|
||||
@@ -70,12 +76,31 @@ func TestOnlyTheSettingsQueriesReadThePublicationTableDirectly(t *testing.T) {
|
||||
}
|
||||
}
|
||||
slices.Sort(found)
|
||||
want := slices.Clone(directPublicationReaders)
|
||||
want := slices.Concat(slices.Clone(directPublicationReaders), ownerScopedPublicationQueries)
|
||||
slices.Sort(want)
|
||||
if !slices.Equal(found, want) {
|
||||
t.Fatalf("queries that name candidate_publications = %v, want only %v: organization-facing reads use candidate_effective_publications", found, want)
|
||||
t.Fatalf("queries that name candidate_publications = %v, want only settings queries and owner-scoped consent revocation: %v", found, want)
|
||||
}
|
||||
if strings.Contains(strings.Join(found, ","), "Visible") {
|
||||
t.Fatal("the organization-facing read names the table directly")
|
||||
}
|
||||
closeQuery := strings.ToLower(statements["LockCandidatePublicationForConsentRevocation"])
|
||||
for _, required := range []string{
|
||||
"select greatest(candidate_publications.published_at, consent_records.revoked_at)",
|
||||
"inner join consent_records",
|
||||
"candidate_publications.user_id = sqlc.arg(user_id)",
|
||||
"candidate_publications.state = 'published'",
|
||||
"consent_records.id = any(sqlc.arg(consent_record_ids)::uuid [])",
|
||||
"consent_records.subject_id = candidate_publications.user_id",
|
||||
"consent_records.purpose = 'c2'",
|
||||
"consent_records.revoked_at is not null",
|
||||
"for update of candidate_publications",
|
||||
} {
|
||||
if !strings.Contains(closeQuery, required) {
|
||||
t.Errorf("consent revocation query lacks %q: %s", required, closeQuery)
|
||||
}
|
||||
}
|
||||
if strings.Contains(closeQuery, "update candidate_publications") || strings.Contains(closeQuery, "set state = 'closed'") {
|
||||
t.Fatalf("consent revocation query rewrites the stored publication instead of preserving its ledger link: %s", closeQuery)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user