Files
nexarch/internal/migrationrole/map.go
rootandClaude Sonnet 5 dc65483239
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (pull_request) Canceled after 0s
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (push) Canceled after 0s
CI / Connect Security-Test-Gate (QA-01 AC4, Merge-Gate) (pull_request) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Canceled after 0s
CI / Connect Security-Test-Gate (QA-01 AC4, Merge-Gate) (push) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (pull_request) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (pull_request) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (push) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (pull_request) Canceled after 0s
CI / Web (dms-browser) (pull_request) Canceled after 0s
CI / Web (pdf-viewer) (pull_request) Canceled after 0s
CI / Web (shl) (pull_request) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (pull_request) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Canceled after 0s
CI / Web (dms-browser) (push) Canceled after 0s
CI / Web (pdf-viewer) (push) Canceled after 0s
CI / Web (shl) (push) Canceled after 0s
Core-Schnittstellen-Vertragstests / contract-tests (pull_request) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (push) Canceled after 0s
Core-Pflichttest-Gate / pflichttest-gate (pull_request) Canceled after 0s
RBAC-Rollenhierarchie-Pflichtgate / rbac-policy-invariant (pull_request) Canceled after 0s
Supply-Chain-Scan (npm) / npm-audit (pull_request) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (pull_request) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
COR-03: rollen-rechte-migration (schema + mapping + migrator)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-13 12:03:16 +00:00

65 lines
1.7 KiB
Go

package migrationrole
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
)
// MapEntry ist eine Zeile der role_migration_map, angereichert um die
// Zieldaten aus dem verknuepften user_migration_map-Eintrag.
type MapEntry struct {
ID int64
UserMigrationMapID int64
SourceSystem string
SourceRole string
GrantedBy string
ApprovedBy *string
NexarchTenantID string
NexarchUserID string
}
// MapStore kapselt den lesenden Zugriff auf role_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, verknuepft
// mit dem zugehoerigen user_migration_map-Eintrag fuer Tenant-/User-ID.
func (s *MapStore) Approved(ctx context.Context) ([]MapEntry, error) {
rows, err := s.pool.Query(ctx, `
SELECT r.id, r.user_migration_map_id, r.source_system, r.source_role, r.granted_by, r.approved_by,
u.nexarch_tenant_id, u.nexarch_user_id
FROM role_migration_map r
JOIN user_migration_map u ON u.id = r.user_migration_map_id
WHERE r.approved_at IS NOT NULL
ORDER BY r.id
`)
if err != nil {
return nil, fmt.Errorf("freigegebene role-map lesen: %w", err)
}
defer rows.Close()
var out []MapEntry
for rows.Next() {
var e MapEntry
var grantedBy *string
if err := rows.Scan(&e.ID, &e.UserMigrationMapID, &e.SourceSystem, &e.SourceRole, &grantedBy, &e.ApprovedBy,
&e.NexarchTenantID, &e.NexarchUserID); err != nil {
return nil, fmt.Errorf("role-map-eintrag lesen: %w", err)
}
if grantedBy != nil {
e.GrantedBy = *grantedBy
}
out = append(out, e)
}
return out, rows.Err()
}