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
+34
-11
@@ -51,11 +51,20 @@ func (s *Server) platformLegalDocs(ctx context.Context) []agentapi.LegalDoc {
|
||||
return docs
|
||||
}
|
||||
|
||||
func validLegalKind(kind string) bool { return slices.Contains(web.LegalKinds, kind) }
|
||||
// legalKinds are the documents org (nil: the platform) can set.
|
||||
func legalKinds(org *uuid.UUID) []string {
|
||||
if org == nil {
|
||||
return web.LegalKinds
|
||||
}
|
||||
return web.OrgLegalKinds
|
||||
}
|
||||
|
||||
type legalRequest struct {
|
||||
URL string `json:"url" binding:"max=2000"`
|
||||
Markdown string `json:"markdown" binding:"max=100000"`
|
||||
// NewVersion asks every account to accept the platform's privacy
|
||||
// policy or terms again.
|
||||
NewVersion bool `json:"new_version"`
|
||||
}
|
||||
|
||||
// validLegalURL accepts absolute http and https URLs only, so a stored link
|
||||
@@ -69,7 +78,7 @@ func validLegalURL(raw string) bool {
|
||||
// nil for the platform.
|
||||
func (s *Server) saveLegal(c *gin.Context, scope tenant.Scope, org *uuid.UUID) bool {
|
||||
kind := c.Param("kind")
|
||||
if !validLegalKind(kind) {
|
||||
if !slices.Contains(legalKinds(org), kind) {
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
return false
|
||||
}
|
||||
@@ -83,12 +92,16 @@ func (s *Server) saveLegal(c *gin.Context, scope tenant.Scope, org *uuid.UUID) b
|
||||
return false
|
||||
}
|
||||
auditDetail(c, "kind", kind)
|
||||
newVersion := req.NewVersion && org == nil && slices.Contains(web.ConsentKinds, kind)
|
||||
if newVersion {
|
||||
auditDetail(c, "new_version", "true")
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
err := s.db.Tx(ctx, scope, func(q *store.Queries) error {
|
||||
if req.URL == "" && req.Markdown == "" {
|
||||
return q.DeleteLegalDocument(ctx, store.DeleteLegalDocumentParams{OrgID: org, Kind: kind})
|
||||
}
|
||||
return q.UpsertLegalDocument(ctx, store.UpsertLegalDocumentParams{OrgID: org, Kind: kind, Url: req.URL, Markdown: req.Markdown})
|
||||
return q.UpsertLegalDocument(ctx, store.UpsertLegalDocumentParams{OrgID: org, Kind: kind, Url: req.URL, Markdown: req.Markdown, NewVersion: newVersion})
|
||||
})
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
@@ -100,8 +113,11 @@ func (s *Server) saveLegal(c *gin.Context, scope tenant.Scope, org *uuid.UUID) b
|
||||
|
||||
func (s *Server) adminSaveLegal(c *gin.Context) {
|
||||
if s.saveLegal(c, tenant.System(), nil) {
|
||||
if err := s.legal.bump(c.Request.Context(), s.rdb); err != nil {
|
||||
s.log.ErrorContext(c.Request.Context(), "announcing legal document change failed", "error", err)
|
||||
ctx := c.Request.Context()
|
||||
for _, err := range []error{s.legal.bump(ctx, s.rdb), s.consent.bump(ctx, s.rdb)} {
|
||||
if err != nil {
|
||||
s.log.ErrorContext(ctx, "announcing legal document change failed", "error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,6 +131,8 @@ type legalView struct {
|
||||
Kind string `json:"kind"`
|
||||
URL string `json:"url"`
|
||||
Markdown string `json:"markdown"`
|
||||
// Version changes whenever accounts have to accept the document again.
|
||||
Version int64 `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
// ownLegal returns the documents stored for org (nil: the platform),
|
||||
@@ -126,12 +144,15 @@ func (s *Server) ownLegal(ctx context.Context, scope tenant.Scope, org *uuid.UUI
|
||||
rows, err = q.LegalDocuments(ctx, org)
|
||||
return err
|
||||
})
|
||||
out := make([]legalView, 0, len(web.LegalKinds))
|
||||
for _, kind := range web.LegalKinds {
|
||||
out := make([]legalView, 0, len(legalKinds(org)))
|
||||
for _, kind := range legalKinds(org) {
|
||||
v := legalView{Kind: kind}
|
||||
for _, r := range rows {
|
||||
if r.Kind == kind && (r.OrgID == nil) == (org == nil) {
|
||||
v.URL, v.Markdown = r.Url, r.Markdown
|
||||
if org == nil && slices.Contains(web.ConsentKinds, kind) {
|
||||
v.Version = r.Version
|
||||
}
|
||||
}
|
||||
}
|
||||
out = append(out, v)
|
||||
@@ -190,10 +211,12 @@ func (s *Server) legalPage(c *gin.Context) {
|
||||
c.Status(http.StatusNotFound)
|
||||
}
|
||||
|
||||
func toLegalForms(docs []legalView) []web.LegalForm {
|
||||
// toLegalForms prepares the forms; the platform's privacy policy and terms
|
||||
// can ask everyone to accept them again.
|
||||
func toLegalForms(docs []legalView, platform bool) []web.LegalForm {
|
||||
out := make([]web.LegalForm, len(docs))
|
||||
for i, d := range docs {
|
||||
out[i] = web.LegalForm{Kind: d.Kind, URL: d.URL, Markdown: d.Markdown}
|
||||
out[i] = web.LegalForm{Kind: d.Kind, URL: d.URL, Markdown: d.Markdown, Consent: platform && slices.Contains(web.ConsentKinds, d.Kind)}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -203,7 +226,7 @@ func (s *Server) orgLegalView(c *gin.Context, p *principal, page web.Page, me we
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return web.LegalSettingsPage(page, me, "legal.org_title", "legal.org_intro", "/org/legal/", "/settings/legal", toLegalForms(docs)), nil
|
||||
return web.LegalSettingsPage(page, me, "legal.org_title", "legal.org_intro", "/org/legal/", "/settings/legal", toLegalForms(docs, false)), nil
|
||||
}
|
||||
|
||||
func (s *Server) adminLegalPage(c *gin.Context) {
|
||||
@@ -216,5 +239,5 @@ func (s *Server) adminLegalPage(c *gin.Context) {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
web.Render(c, http.StatusOK, web.LegalSettingsPage(s.pageFor(c, "legal.platform_title"), me, "legal.platform_title", "legal.platform_intro", "/admin/legal/", "/admin/legal", toLegalForms(docs)))
|
||||
web.Render(c, http.StatusOK, web.LegalSettingsPage(s.pageFor(c, "legal.platform_title"), me, "legal.platform_title", "legal.platform_intro", "/admin/legal/", "/admin/legal", toLegalForms(docs, true)))
|
||||
}
|
||||
Reference in new issue
Block a user