Files
uptimesebi/internal/store/queries/legal.sql
T
Sebastian UnterschützandClaude Opus 5.5 8d7c1f856c
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
feat: terms of service and versioned consent; data rights for every account
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
2026-11-23 22:26:20 +01:00

33 lines
1.4 KiB
SQL

-- name: UpsertLegalDocument :exec
-- A new version starts when the document is created or when the edit asks
-- everyone to accept it again.
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(),
version = CASE WHEN sqlc.arg(new_version)::boolean THEN nextval('legal_document_versions') ELSE legal_documents.version END;
-- name: DeleteLegalDocument :exec
DELETE FROM legal_documents WHERE org_id IS NOT DISTINCT FROM $1 AND kind = $2;
-- name: LegalDocuments :many
-- The organization's documents and the platform's, organization first.
SELECT org_id, kind, url, markdown, updated_at, version FROM legal_documents
WHERE org_id IS NULL OR org_id = sqlc.narg(org_id)
ORDER BY org_id NULLS LAST, kind;
-- name: RequiredLegalVersions :many
-- The platform documents accounts have to accept, in their current version.
SELECT kind, version FROM legal_documents
WHERE org_id IS NULL AND kind IN ('privacy', 'terms') AND (url <> '' OR markdown <> '')
ORDER BY kind;
-- name: AcceptedLegalVersions :many
SELECT kind, version FROM legal_acceptances WHERE user_id = $1;
-- name: AcceptLegal :exec
INSERT INTO legal_acceptances (user_id, kind, version) VALUES ($1, $2, $3)
ON CONFLICT DO NOTHING;
-- name: LegalAcceptances :many
SELECT kind, version, accepted_at FROM legal_acceptances WHERE user_id = $1 ORDER BY accepted_at, kind;