MapEntry/MapStore und TenantUserStore um die LDAP-Kopplungsfelder erweitert; MigrateApproved uebernimmt sie in die Tenant-Datenbank. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
// Package migrationuser implementiert COR-02: die Uebernahme
|
|
// zusammengefuehrter Benutzerdatensaetze (inkl. bcrypt-Passwort-Hash) aus
|
|
// der freigegebenen user_migration_map in Core IAM-01.
|
|
package migrationuser
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
// MapEntry ist eine Zeile der user_migration_map.
|
|
type MapEntry struct {
|
|
ID int64
|
|
ArchivmailUserID *int64
|
|
ArchivdmsUserID *int64
|
|
NexarchTenantID string
|
|
NexarchUserID string
|
|
Email string
|
|
Name string
|
|
PasswordHash string
|
|
ApprovedBy *string
|
|
LDAPUID *string
|
|
LDAPSyncedAt *time.Time
|
|
LDAPSource *string
|
|
}
|
|
|
|
// MapStore kapselt den lesenden Zugriff auf user_migration_map in der
|
|
// Registry-Datenbank.
|
|
type MapStore struct {
|
|
pool *pgxpool.Pool
|
|
}
|
|
|
|
func NewMapStore(pool *pgxpool.Pool) *MapStore {
|
|
return &MapStore{pool: pool}
|
|
}
|
|
|
|
// Approved liefert ausschliesslich Zeilen mit gesetztem approved_at
|
|
// (Akzeptanzkriterium 2: kein Benutzer ohne Freigabe wird uebernommen).
|
|
func (s *MapStore) Approved(ctx context.Context) ([]MapEntry, error) {
|
|
rows, err := s.pool.Query(ctx, `
|
|
SELECT id, archivmail_user_id, archivdms_user_id, nexarch_tenant_id, nexarch_user_id,
|
|
email, name, password_hash, approved_by, ldap_uid, ldap_synced_at, ldap_source
|
|
FROM user_migration_map
|
|
WHERE approved_at IS NOT NULL
|
|
ORDER BY id
|
|
`)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("freigegebene user-map lesen: %w", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
var out []MapEntry
|
|
for rows.Next() {
|
|
var e MapEntry
|
|
if err := rows.Scan(&e.ID, &e.ArchivmailUserID, &e.ArchivdmsUserID, &e.NexarchTenantID, &e.NexarchUserID,
|
|
&e.Email, &e.Name, &e.PasswordHash, &e.ApprovedBy, &e.LDAPUID, &e.LDAPSyncedAt, &e.LDAPSource); err != nil {
|
|
return nil, fmt.Errorf("user-map-eintrag lesen: %w", err)
|
|
}
|
|
out = append(out, e)
|
|
}
|
|
return out, rows.Err()
|
|
}
|