feat(store): store legal notices and privacy policies
Refs #67 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
44537a1c11
commit
4134af4aef
5 files changed
+132
No files matched your search
@@ -0,0 +1,25 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- Legal notice and privacy policy, either as Markdown served by us or as a
|
||||||
|
-- link to a page elsewhere; a link wins when both are set. Rows without an
|
||||||
|
-- organization belong to the platform: the console and status pages of
|
||||||
|
-- organizations without their own.
|
||||||
|
CREATE TABLE legal_documents (
|
||||||
|
org_id uuid REFERENCES orgs (id) ON DELETE CASCADE,
|
||||||
|
kind text NOT NULL CHECK (kind IN ('imprint', 'privacy')),
|
||||||
|
url text NOT NULL DEFAULT '' CHECK (length(url) <= 2000),
|
||||||
|
markdown text NOT NULL DEFAULT '' CHECK (length(markdown) <= 100000),
|
||||||
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
UNIQUE NULLS NOT DISTINCT (org_id, kind)
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE legal_documents ENABLE ROW LEVEL SECURITY;
|
||||||
|
ALTER TABLE legal_documents FORCE ROW LEVEL SECURITY;
|
||||||
|
-- Platform documents are public.
|
||||||
|
CREATE POLICY legal_documents_read ON legal_documents FOR SELECT
|
||||||
|
USING (app_scope_system() OR org_id IS NULL OR org_id = app_org_id());
|
||||||
|
CREATE POLICY legal_documents_write ON legal_documents FOR ALL
|
||||||
|
USING (app_scope_system() OR org_id = app_org_id())
|
||||||
|
WITH CHECK (app_scope_system() OR org_id = app_org_id());
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
DROP TABLE legal_documents;
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.31.1
|
||||||
|
// source: legal.sql
|
||||||
|
|
||||||
|
package store
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const deleteLegalDocument = `-- name: DeleteLegalDocument :exec
|
||||||
|
DELETE FROM legal_documents WHERE org_id IS NOT DISTINCT FROM $1 AND kind = $2
|
||||||
|
`
|
||||||
|
|
||||||
|
type DeleteLegalDocumentParams struct {
|
||||||
|
OrgID *uuid.UUID
|
||||||
|
Kind string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) DeleteLegalDocument(ctx context.Context, arg DeleteLegalDocumentParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, deleteLegalDocument, arg.OrgID, arg.Kind)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const legalDocuments = `-- name: LegalDocuments :many
|
||||||
|
SELECT org_id, kind, url, markdown, updated_at FROM legal_documents
|
||||||
|
WHERE org_id IS NULL OR org_id = $1
|
||||||
|
ORDER BY org_id NULLS LAST, kind
|
||||||
|
`
|
||||||
|
|
||||||
|
// The organization's documents and the platform's, organization first.
|
||||||
|
func (q *Queries) LegalDocuments(ctx context.Context, orgID *uuid.UUID) ([]LegalDocument, error) {
|
||||||
|
rows, err := q.db.Query(ctx, legalDocuments, orgID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
items := []LegalDocument{}
|
||||||
|
for rows.Next() {
|
||||||
|
var i LegalDocument
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.OrgID,
|
||||||
|
&i.Kind,
|
||||||
|
&i.Url,
|
||||||
|
&i.Markdown,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
); 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()
|
||||||
|
`
|
||||||
|
|
||||||
|
type UpsertLegalDocumentParams struct {
|
||||||
|
OrgID *uuid.UUID
|
||||||
|
Kind string
|
||||||
|
Url string
|
||||||
|
Markdown string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) UpsertLegalDocument(ctx context.Context, arg UpsertLegalDocumentParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, upsertLegalDocument,
|
||||||
|
arg.OrgID,
|
||||||
|
arg.Kind,
|
||||||
|
arg.Url,
|
||||||
|
arg.Markdown,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
@@ -115,6 +115,14 @@ type Invitation struct {
|
|||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LegalDocument struct {
|
||||||
|
OrgID *uuid.UUID
|
||||||
|
Kind string
|
||||||
|
Url string
|
||||||
|
Markdown string
|
||||||
|
UpdatedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
type Membership struct {
|
type Membership struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
UserID uuid.UUID
|
UserID uuid.UUID
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ type Querier interface {
|
|||||||
DeleteGroup(ctx context.Context, id uuid.UUID) (int64, error)
|
DeleteGroup(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
DeleteInvitation(ctx context.Context, id uuid.UUID) (int64, error)
|
DeleteInvitation(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
DeleteInvitationsForEmail(ctx context.Context, email string) error
|
DeleteInvitationsForEmail(ctx context.Context, email string) error
|
||||||
|
DeleteLegalDocument(ctx context.Context, arg DeleteLegalDocumentParams) error
|
||||||
DeleteMonitor(ctx context.Context, id uuid.UUID) (int64, error)
|
DeleteMonitor(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
DeleteMonitorRegions(ctx context.Context, monitorID uuid.UUID) error
|
DeleteMonitorRegions(ctx context.Context, monitorID uuid.UUID) error
|
||||||
DeleteOrg(ctx context.Context, id uuid.UUID) (int64, error)
|
DeleteOrg(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
@@ -112,6 +113,8 @@ type Querier interface {
|
|||||||
// Newest result per monitor and region in the org.
|
// Newest result per monitor and region in the org.
|
||||||
LatestResults(ctx context.Context, orgID uuid.UUID) ([]LatestResultsRow, error)
|
LatestResults(ctx context.Context, orgID uuid.UUID) ([]LatestResultsRow, error)
|
||||||
LatestResultsForMonitor(ctx context.Context, arg LatestResultsForMonitorParams) ([]LatestResultsForMonitorRow, error)
|
LatestResultsForMonitor(ctx context.Context, arg LatestResultsForMonitorParams) ([]LatestResultsForMonitorRow, error)
|
||||||
|
// The organization's documents and the platform's, organization first.
|
||||||
|
LegalDocuments(ctx context.Context, orgID *uuid.UUID) ([]LegalDocument, error)
|
||||||
ListAPITokens(ctx context.Context, arg ListAPITokensParams) ([]ListAPITokensRow, error)
|
ListAPITokens(ctx context.Context, arg ListAPITokensParams) ([]ListAPITokensRow, error)
|
||||||
// Agents owned by org, or platform agents when org is NULL.
|
// Agents owned by org, or platform agents when org is NULL.
|
||||||
ListAgents(ctx context.Context, orgID *uuid.UUID) ([]ListAgentsRow, error)
|
ListAgents(ctx context.Context, orgID *uuid.UUID) ([]ListAgentsRow, error)
|
||||||
@@ -214,6 +217,7 @@ type Querier interface {
|
|||||||
UpdateRole(ctx context.Context, arg UpdateRoleParams) (Role, error)
|
UpdateRole(ctx context.Context, arg UpdateRoleParams) (Role, error)
|
||||||
UpdateSSOProvider(ctx context.Context, arg UpdateSSOProviderParams) (SsoProvider, error)
|
UpdateSSOProvider(ctx context.Context, arg UpdateSSOProviderParams) (SsoProvider, error)
|
||||||
UpdateStatusPage(ctx context.Context, arg UpdateStatusPageParams) (StatusPage, error)
|
UpdateStatusPage(ctx context.Context, arg UpdateStatusPageParams) (StatusPage, error)
|
||||||
|
UpsertLegalDocument(ctx context.Context, arg UpsertLegalDocumentParams) error
|
||||||
// Uptime per monitor from the hourly aggregate, including the not yet
|
// Uptime per monitor from the hourly aggregate, including the not yet
|
||||||
// materialized most recent hours (real-time aggregation).
|
// materialized most recent hours (real-time aggregation).
|
||||||
UptimeSince(ctx context.Context, arg UptimeSinceParams) ([]UptimeSinceRow, error)
|
UptimeSince(ctx context.Context, arg UptimeSinceParams) ([]UptimeSinceRow, error)
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
-- 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();
|
||||||
|
|
||||||
|
-- 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 FROM legal_documents
|
||||||
|
WHERE org_id IS NULL OR org_id = sqlc.narg(org_id)
|
||||||
|
ORDER BY org_id NULLS LAST, kind;
|
||||||
Reference in new issue
Block a user