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

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:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-23 22:26:20 +01:00
1 parent 61fdfa830a
commit 8d7c1f856c
38 files changed
+2033 -354

No files matched your search

+29 -25
View File
@@ -31,9 +31,17 @@ type accountExport struct {
Organizations []exportMembership `json:"organizations"`
Identities []exportIdentity `json:"sso_identities"`
Tokens []exportToken `json:"api_tokens"`
Consents []exportConsent `json:"consents"`
Activity []exportActivity `json:"activity"`
}
// exportConsent is an accepted version of the privacy policy or terms.
type exportConsent struct {
Kind string `json:"kind"`
Version int64 `json:"version"`
AcceptedAt time.Time `json:"accepted_at"`
}
type exportAccount struct {
ID uuid.UUID `json:"id"`
Email string `json:"email"`
@@ -133,6 +141,14 @@ func (s *Server) buildAccountExport(ctx context.Context, userID uuid.UUID) (acco
if err != nil {
return err
}
consents, err := q.LegalAcceptances(ctx, u.ID)
if err != nil {
return err
}
x.Consents = []exportConsent{}
for _, r := range consents {
x.Consents = append(x.Consents, exportConsent{Kind: r.Kind, Version: r.Version, AcceptedAt: r.AcceptedAt})
}
x.Tokens = []exportToken{}
for _, t := range toks {
x.Tokens = append(x.Tokens, exportToken{
@@ -586,9 +602,12 @@ func purgeOrg(ctx context.Context, q *store.Queries, org uuid.UUID) error {
return err
}
// deleteAccount erases the signed-in user (Art. 17). Organizations only the
// user belongs to go with the account; an organization shared with others
// must be handed over or deleted first, so nobody loses access to it.
// deleteAccount erases the signed-in user (Art. 17). Organizations the
// user owns go with the account, monitors and all, even when they have
// other members: an organization has exactly one owner, and nobody would be
// left to run it.
// Suspended accounts and those that have not accepted the terms may do
// this too.
func (s *Server) deleteAccount(c *gin.Context) {
var req deletionRequest
if !bind(c, &req) {
@@ -609,17 +628,11 @@ func (s *Server) deleteAccount(c *gin.Context) {
fail(c, http.StatusForbidden, "confirmation_failed")
return
}
shared, orgsDeleted, err := s.eraseAccount(ctx, u)
orgsDeleted, err := s.eraseAccount(ctx, u)
if err != nil {
internalError(c, err)
return
}
if len(shared) > 0 {
c.JSON(http.StatusConflict, gin.H{
"error": "owns_shared_orgs", "message": i18n.T(ctx, "error.owns_shared_orgs"), "organizations": shared,
})
return
}
auth.ClearCookie(c)
// Kept as proof of erasure, without saying whose.
s.writeAudit(c, store.InsertAuditEventParams{Kind: "platform", Action: "account.delete", Status: http.StatusOK},
@@ -627,23 +640,14 @@ func (s *Server) deleteAccount(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "deleted"})
}
// eraseAccount deletes u with the organizations only u belongs to and
// ends u's sessions. If u owns organizations shared with others, nothing
// is deleted and their slugs are returned.
func (s *Server) eraseAccount(ctx context.Context, u store.User) (shared []string, orgsDeleted int, err error) {
// eraseAccount deletes u with the organizations u owns and ends u's
// sessions; u leaves the others.
func (s *Server) eraseAccount(ctx context.Context, u store.User) (orgsDeleted int, err error) {
err = s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
owned, err := q.OwnedOrgs(ctx, u.ID)
if err != nil {
return err
}
for _, o := range owned {
if o.Members > 1 {
shared = append(shared, o.Slug)
}
}
if len(shared) > 0 {
return nil
}
for _, o := range owned {
if err := purgeOrg(ctx, q, o.ID); err != nil {
return err
@@ -663,13 +667,13 @@ func (s *Server) eraseAccount(ctx context.Context, u store.User) (shared []strin
}
return nil
})
if err != nil || len(shared) > 0 {
return shared, 0, err
if err != nil {
return 0, err
}
if err := s.sessions.DeleteAllForUser(ctx, u.ID); err != nil {
s.log.ErrorContext(ctx, "ending sessions of deleted account failed", "error", err)
}
return nil, orgsDeleted, nil
return orgsDeleted, nil
}
type orgDeletionRequest struct {