feat: terms of service and versioned consent; data rights for every account
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 9m21s
ci / test (pull_request) Successful in 13m53s
ci / build (pull_request) Successful in 11m22s
ci / image (pull_request) Successful in 4m36s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 9m21s
ci / test (pull_request) Successful in 13m53s
ci / build (pull_request) Successful in 11m22s
ci / image (pull_request) Successful in 4m36s
Terms of service join the legal notice and privacy policy, for the platform only. Every account accepts the platform's privacy policy and terms: on sign-up (also through an invitation) by ticking a box for the versions shown, and after a sign-in through a provider right away. When an admin saves a material change with "everyone has to accept again", the document gets a new version and each account is asked at its next request; corrections ask nobody. Acceptances are kept per version with their time, as proof, and are part of the data export. Until an account accepted, and while it is suspended, it can read the documents, export its data, delete itself and sign out, nothing else: pages lead to /consent or /account/suspended, other API calls answer 403 consent_required or account_suspended. Suspended accounts therefore sign in again, by password or provider; their API tokens stay blocked. Deleting an account deletes the organizations it owns, monitors and all, also when they have other members (each organization has one owner); it no longer refuses. The account settings name those organizations first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
61fdfa830a
commit
8d7c1f856c
38 files changed
+2033
-354
No files matched your search
+120
-6
@@ -7,10 +7,56 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const acceptLegal = `-- name: AcceptLegal :exec
|
||||
INSERT INTO legal_acceptances (user_id, kind, version) VALUES ($1, $2, $3)
|
||||
ON CONFLICT DO NOTHING
|
||||
`
|
||||
|
||||
type AcceptLegalParams struct {
|
||||
UserID uuid.UUID
|
||||
Kind string
|
||||
Version int64
|
||||
}
|
||||
|
||||
func (q *Queries) AcceptLegal(ctx context.Context, arg AcceptLegalParams) error {
|
||||
_, err := q.db.Exec(ctx, acceptLegal, arg.UserID, arg.Kind, arg.Version)
|
||||
return err
|
||||
}
|
||||
|
||||
const acceptedLegalVersions = `-- name: AcceptedLegalVersions :many
|
||||
SELECT kind, version FROM legal_acceptances WHERE user_id = $1
|
||||
`
|
||||
|
||||
type AcceptedLegalVersionsRow struct {
|
||||
Kind string
|
||||
Version int64
|
||||
}
|
||||
|
||||
func (q *Queries) AcceptedLegalVersions(ctx context.Context, userID uuid.UUID) ([]AcceptedLegalVersionsRow, error) {
|
||||
rows, err := q.db.Query(ctx, acceptedLegalVersions, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []AcceptedLegalVersionsRow{}
|
||||
for rows.Next() {
|
||||
var i AcceptedLegalVersionsRow
|
||||
if err := rows.Scan(&i.Kind, &i.Version); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const deleteLegalDocument = `-- name: DeleteLegalDocument :exec
|
||||
DELETE FROM legal_documents WHERE org_id IS NOT DISTINCT FROM $1 AND kind = $2
|
||||
`
|
||||
@@ -25,8 +71,38 @@ func (q *Queries) DeleteLegalDocument(ctx context.Context, arg DeleteLegalDocume
|
||||
return err
|
||||
}
|
||||
|
||||
const legalAcceptances = `-- name: LegalAcceptances :many
|
||||
SELECT kind, version, accepted_at FROM legal_acceptances WHERE user_id = $1 ORDER BY accepted_at, kind
|
||||
`
|
||||
|
||||
type LegalAcceptancesRow struct {
|
||||
Kind string
|
||||
Version int64
|
||||
AcceptedAt time.Time
|
||||
}
|
||||
|
||||
func (q *Queries) LegalAcceptances(ctx context.Context, userID uuid.UUID) ([]LegalAcceptancesRow, error) {
|
||||
rows, err := q.db.Query(ctx, legalAcceptances, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []LegalAcceptancesRow{}
|
||||
for rows.Next() {
|
||||
var i LegalAcceptancesRow
|
||||
if err := rows.Scan(&i.Kind, &i.Version, &i.AcceptedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const legalDocuments = `-- name: LegalDocuments :many
|
||||
SELECT org_id, kind, url, markdown, updated_at FROM legal_documents
|
||||
SELECT org_id, kind, url, markdown, updated_at, version FROM legal_documents
|
||||
WHERE org_id IS NULL OR org_id = $1
|
||||
ORDER BY org_id NULLS LAST, kind
|
||||
`
|
||||
@@ -47,6 +123,7 @@ func (q *Queries) LegalDocuments(ctx context.Context, orgID *uuid.UUID) ([]Legal
|
||||
&i.Url,
|
||||
&i.Markdown,
|
||||
&i.UpdatedAt,
|
||||
&i.Version,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -58,25 +135,62 @@ func (q *Queries) LegalDocuments(ctx context.Context, orgID *uuid.UUID) ([]Legal
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const requiredLegalVersions = `-- name: RequiredLegalVersions :many
|
||||
SELECT kind, version FROM legal_documents
|
||||
WHERE org_id IS NULL AND kind IN ('privacy', 'terms') AND (url <> '' OR markdown <> '')
|
||||
ORDER BY kind
|
||||
`
|
||||
|
||||
type RequiredLegalVersionsRow struct {
|
||||
Kind string
|
||||
Version int64
|
||||
}
|
||||
|
||||
// The platform documents accounts have to accept, in their current version.
|
||||
func (q *Queries) RequiredLegalVersions(ctx context.Context) ([]RequiredLegalVersionsRow, error) {
|
||||
rows, err := q.db.Query(ctx, requiredLegalVersions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []RequiredLegalVersionsRow{}
|
||||
for rows.Next() {
|
||||
var i RequiredLegalVersionsRow
|
||||
if err := rows.Scan(&i.Kind, &i.Version); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const upsertLegalDocument = `-- name: UpsertLegalDocument :exec
|
||||
INSERT INTO legal_documents (org_id, kind, url, markdown)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (org_id, kind) DO UPDATE SET url = EXCLUDED.url, markdown = EXCLUDED.markdown, updated_at = now()
|
||||
ON CONFLICT (org_id, kind) DO UPDATE SET url = EXCLUDED.url, markdown = EXCLUDED.markdown, updated_at = now(),
|
||||
version = CASE WHEN $5::boolean THEN nextval('legal_document_versions') ELSE legal_documents.version END
|
||||
`
|
||||
|
||||
type UpsertLegalDocumentParams struct {
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Url string
|
||||
Markdown string
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Url string
|
||||
Markdown string
|
||||
NewVersion bool
|
||||
}
|
||||
|
||||
// A new version starts when the document is created or when the edit asks
|
||||
// everyone to accept it again.
|
||||
func (q *Queries) UpsertLegalDocument(ctx context.Context, arg UpsertLegalDocumentParams) error {
|
||||
_, err := q.db.Exec(ctx, upsertLegalDocument,
|
||||
arg.OrgID,
|
||||
arg.Kind,
|
||||
arg.Url,
|
||||
arg.Markdown,
|
||||
arg.NewVersion,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user