feat: Löschfristen je Datenklasse, Passwort-Zurücksetzen, DPF-Recherche

- Löschfristen (Migration 0020): pro Mandant einstellbar statt fest im
  Regelwerk, da die DSGVO selbst keine festen Fristen nennt (Art. 5
  Abs. 1 lit. e). Jede Firma wird mit risikogestaffelten Vorschlagswerten
  vorbelegt, loeschfrist_max_tage wird jetzt tatsächlich hart gegen
  Werkzeuge gefiltert (schließt rules/OPEN.md Punkt 4).
- Neues internal/mail-Paket (SMTP-Versand + Test-Doppel) und darauf
  aufbauend Passwort-Zurücksetzen (Migration 0019) - bisher nur als
  Absicht in der Rollentabelle genannt, nie gebaut.
- dpf_zertifiziert für alle 20 Katalogeinträge gegen das offizielle
  DPF-Register recherchiert und in der Produktions-DB aktualisiert
  (12 zertifiziert, 5 recherchiert-nicht-gefunden, 3 nicht anwendbar).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
noroot
2026-09-01 07:38:12 +02:00
parent 690660b655
commit 8a8295dacd
30 changed files with 1120 additions and 63 deletions

View File

@@ -14,6 +14,7 @@ import (
"time"
"github.com/netcell-it/deklarix/internal/auth"
"github.com/netcell-it/deklarix/internal/mail"
"github.com/netcell-it/deklarix/internal/rules"
"github.com/netcell-it/deklarix/internal/store"
"github.com/netcell-it/deklarix/internal/web"
@@ -43,6 +44,8 @@ type fakeStore struct {
nutzerGenehmigerRollen map[string]map[string]bool // userID -> Set von genehmigerRolleID
freigabeRegeln map[string]store.FreigabeRegel
freigabeschritte map[string]store.Freigabeschritt
passwordResetTokens map[string]store.PasswordResetToken
loeschfristen map[string]map[string]int // accountID -> datenklasseID -> maxTage
}
func newFakeStore() *fakeStore {
@@ -62,6 +65,8 @@ func newFakeStore() *fakeStore {
nutzerGenehmigerRollen: map[string]map[string]bool{},
freigabeRegeln: map[string]store.FreigabeRegel{},
freigabeschritte: map[string]store.Freigabeschritt{},
passwordResetTokens: map[string]store.PasswordResetToken{},
loeschfristen: map[string]map[string]int{},
}
}
@@ -181,6 +186,73 @@ func (f *fakeStore) SetUserActive(ctx context.Context, id string, active bool) e
return nil
}
func (f *fakeStore) SetUserPassword(ctx context.Context, id, passwordHash string) error {
f.mu.Lock()
defer f.mu.Unlock()
u, ok := f.users[id]
if !ok {
return store.ErrNotFound
}
u.PasswordHash = passwordHash
f.users[id] = u
return nil
}
func (f *fakeStore) CreatePasswordResetToken(ctx context.Context, userID, token string) (store.PasswordResetToken, error) {
f.mu.Lock()
defer f.mu.Unlock()
t := store.PasswordResetToken{
ID: f.newID(), UserID: userID, Token: token,
ExpiresAt: time.Now().Add(store.PasswordResetTokenDuration), CreatedAt: time.Now(),
}
f.passwordResetTokens[t.ID] = t
return t, nil
}
func (f *fakeStore) GetValidPasswordResetToken(ctx context.Context, token string) (store.PasswordResetToken, error) {
f.mu.Lock()
defer f.mu.Unlock()
for _, t := range f.passwordResetTokens {
if t.Token == token && t.UsedAt == nil && t.ExpiresAt.After(time.Now()) {
return t, nil
}
}
return store.PasswordResetToken{}, store.ErrNotFound
}
func (f *fakeStore) MarkPasswordResetTokenUsed(ctx context.Context, id string) error {
f.mu.Lock()
defer f.mu.Unlock()
t, ok := f.passwordResetTokens[id]
if !ok {
return store.ErrNotFound
}
now := time.Now()
t.UsedAt = &now
f.passwordResetTokens[id] = t
return nil
}
func (f *fakeStore) UpsertLoeschfristEinstellung(ctx context.Context, accountID, datenklasseID string, maxTage int) (store.LoeschfristEinstellung, error) {
f.mu.Lock()
defer f.mu.Unlock()
if f.loeschfristen[accountID] == nil {
f.loeschfristen[accountID] = map[string]int{}
}
f.loeschfristen[accountID][datenklasseID] = maxTage
return store.LoeschfristEinstellung{AccountID: accountID, DatenklasseID: datenklasseID, MaxTage: maxTage, UpdatedAt: time.Now()}, nil
}
func (f *fakeStore) ListLoeschfristEinstellungenForAccount(ctx context.Context, accountID string) ([]store.LoeschfristEinstellung, error) {
f.mu.Lock()
defer f.mu.Unlock()
var out []store.LoeschfristEinstellung
for datenklasseID, maxTage := range f.loeschfristen[accountID] {
out = append(out, store.LoeschfristEinstellung{AccountID: accountID, DatenklasseID: datenklasseID, MaxTage: maxTage})
}
return out, nil
}
func (f *fakeStore) ListUsersForAccount(ctx context.Context, accountID string) ([]store.User, error) {
f.mu.Lock()
defer f.mu.Unlock()
@@ -784,11 +856,18 @@ func loadTestRegelwerk(t *testing.T) web.Regelwerk {
func newServer(t *testing.T, fs *fakeStore) *web.Server {
t.Helper()
s, err := web.NewServer(fs, loadTestRegelwerk(t))
s, _ := newServerWithMailer(t, fs)
return s
}
func newServerWithMailer(t *testing.T, fs *fakeStore) (*web.Server, *mail.FakeMailer) {
t.Helper()
fm := &mail.FakeMailer{}
s, err := web.NewServer(fs, loadTestRegelwerk(t), fm)
if err != nil {
t.Fatalf("NewServer: %v", err)
}
return s
return s, fm
}
// seedAccountWithRole legt direkt im fakeStore (ohne HTTP) einen