feat(audit-log): implement full audit log for media assets, including visibility, copyright, metadata, and lifecycle changes; add correction declaration functionality
Deploy Development / deploy (push) Failing after 18s
Test Suite / pytest-backend (push) Successful in 32s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Failing after 3s
Test Suite / playwright-tests (push) Successful in 55s

This commit is contained in:
Lars committed 2026-05-11 10:26:50 +02:00
1 parent 56e952f084
commit b2b7bd423d
8 files changed
+677 -25

No files matched your search

+292 -6
View File
@@ -232,6 +232,42 @@ function MediaTypeGlyph({ mimeType, compact }) {
)
}
function actionTypeLabel(at) {
const MAP = {
upload: 'Erstupload',
promote_club: 'Promotion → Verein',
promote_official: 'Promotion → Offiziell',
re_declaration: 'Nachdeklaration',
legacy_re_declaration: 'Altbestand nachdeklariert',
correction: 'Korrektur',
}
return MAP[at] || at
}
function eventTypeLabel(et) {
const MAP = {
visibility_change: 'Sichtbarkeit geändert',
copyright_change: 'Copyright geändert',
metadata_change: 'Metadaten geändert',
lifecycle_change: 'Lifecycle geändert',
}
return MAP[et] || et
}
function visLabel(v) {
if (v === 'private') return 'Privat'
if (v === 'club') return 'Verein'
if (v === 'official') return 'Offiziell'
return v || '—'
}
function lcLabel(lc) {
if (lc === 'active') return 'Aktiv'
if (lc === 'trash_soft') return 'Papierkorb'
if (lc === 'trash_hidden') return 'Ausgeblendet'
return lc || '—'
}
function JournalBoolField({ label, val, context }) {
if (val === null || val === undefined) return null
return (
@@ -292,6 +328,9 @@ export default function MediaLibraryPage() {
const [pendingPatchBody, setPendingPatchBody] = useState(null)
const [journalModal, setJournalModal] = useState(null)
const [journalLoading, setJournalLoading] = useState(false)
const [journalCorrectionOpen, setJournalCorrectionOpen] = useState(false)
const [journalCorrectionDraft, setJournalCorrectionDraft] = useState(null)
const [journalCorrectionBusy, setJournalCorrectionBusy] = useState(false)
const mediaListFetchSeqRef = useRef(0)
const gridTopAnchorRef = useRef(null)
@@ -1432,7 +1471,7 @@ export default function MediaLibraryPage() {
<button
type="button"
className="media-library__icon-btn"
onClick={() => setJournalModal(null)}
onClick={() => { setJournalModal(null); setJournalCorrectionOpen(false) }}
aria-label="Schließen"
>
<X size={22} />
@@ -1456,17 +1495,66 @@ export default function MediaLibraryPage() {
) : null}
</div>
{journalModal.declarations.length === 0 ? (
<p className="media-library__hint">Noch keine Einwilligungserklärungen für dieses Medium erfasst.</p>
{/* Chronologische Event-Timeline */}
{(journalModal.events || journalModal.declarations || []).length === 0 ? (
<p className="media-library__hint">Noch keine Einträge für dieses Medium.</p>
) : (
<div className="media-library__journal-list">
{journalModal.declarations.map((d) => {
{(journalModal.events || journalModal.declarations || []).map((evt, idx) => {
if (evt.kind === 'audit') {
const byLabel = evt.acting_name || evt.acting_email
|| (evt.acting_profile_id ? `Profil #${evt.acting_profile_id}` : '—')
const old = evt.old_values || {}
const nw = evt.new_values || {}
return (
<div key={`a-${idx}`} className="media-library__journal-entry media-library__journal-entry--audit">
<div className="media-library__journal-entry-head">
<span className="media-library__journal-action media-library__journal-action--audit">
{eventTypeLabel(evt.event_type)}
</span>
<span className="media-library__journal-date">
{new Date(evt.occurred_at).toLocaleString('de-DE')}
</span>
</div>
<div className="media-library__journal-entry-by">{byLabel}</div>
<div className="media-library__journal-audit-vals">
{evt.event_type === 'visibility_change' ? (
<span>{visLabel(old.visibility)} → {visLabel(nw.visibility)}</span>
) : evt.event_type === 'lifecycle_change' ? (
<span>{lcLabel(old.lifecycle_state)} → {lcLabel(nw.lifecycle_state)}</span>
) : evt.event_type === 'copyright_change' ? (
<>
<div className="media-library__journal-audit-row">
<span className="media-library__journal-audit-label">Alt:</span>
<span>{old.copyright_notice || '—'}</span>
</div>
<div className="media-library__journal-audit-row">
<span className="media-library__journal-audit-label">Neu:</span>
<span>{nw.copyright_notice || '—'}</span>
</div>
</>
) : (
Object.keys(nw).map((k) => (
<div key={k} className="media-library__journal-audit-row">
<span className="media-library__journal-audit-label">{k}:</span>
<span>{String(old[k] ?? '—')} → {String(nw[k] ?? '—')}</span>
</div>
))
)}
</div>
</div>
)
}
// kind === 'declaration' (or legacy array format)
const d = evt
const byLabel = d.declared_by_name || d.declared_by_email
|| (d.declared_by_profile_id ? `Profil #${d.declared_by_profile_id}` : '—')
return (
<div key={d.id} className="media-library__journal-entry">
<div key={`d-${idx}`} className={`media-library__journal-entry${d.action_type === 'correction' ? ' media-library__journal-entry--correction' : ''}`}>
<div className="media-library__journal-entry-head">
<span className="media-library__journal-action">{d.action_type}</span>
<span className={`media-library__journal-action${d.action_type === 'correction' ? ' media-library__journal-action--correction' : ''}`}>
{actionTypeLabel(d.action_type)}
</span>
<span className="media-library__journal-arrow">→</span>
<span className="media-library__journal-vis">{visibilityUiLabel(d.target_visibility)}</span>
<span className="media-library__journal-date">
@@ -1477,6 +1565,11 @@ export default function MediaLibraryPage() {
{byLabel}
<span className="media-library__journal-version"> · {d.declaration_version}</span>
</div>
{d.correction_note ? (
<div className="media-library__journal-correction-note">
<strong>Korrekturgrund:</strong> {d.correction_note}
</div>
) : null}
<div className="media-library__journal-fields">
<JournalBoolField label="Rechteinhaber bestätigt" val={d.rights_holder_confirmed} />
<JournalBoolField label="Erkennbare Personen" val={d.contains_identifiable_persons} />
@@ -1517,6 +1610,199 @@ export default function MediaLibraryPage() {
})}
</div>
)}
{/* Korrektur-Formular */}
{journalModal.can_correct && !journalCorrectionOpen ? (
<div style={{ marginTop: 16 }}>
<button
className="btn btn-secondary"
onClick={() => {
setJournalCorrectionDraft({
target_visibility: journalModal.asset.visibility || 'private',
rights_holder_confirmed: false,
contains_identifiable_persons: false,
person_consent_confirmed: null,
contains_minors: false,
parental_consent_confirmed: null,
contains_music: false,
music_rights_confirmed: null,
contains_third_party_content: false,
third_party_rights_confirmed: null,
correction_note: '',
})
setJournalCorrectionOpen(true)
}}
>
Korrektur erfassen
</button>
</div>
) : null}
{journalCorrectionOpen && journalCorrectionDraft ? (
<div className="media-library__journal-correction-form">
<h3 className="media-library__journal-correction-title">Korrektur der Einwilligungserklärung</h3>
<p className="media-library__hint" style={{ marginBottom: 12 }}>
Die Korrektur wird als neuer Eintrag im Journal gespeichert (append-only). Die ursprünglichen Einträge bleiben erhalten.
</p>
<div className="form-row">
<label className="form-label">Ziel-Sichtbarkeit</label>
<select
className="form-input"
value={journalCorrectionDraft.target_visibility}
onChange={(e) => setJournalCorrectionDraft((d) => ({ ...d, target_visibility: e.target.value }))}
>
<option value="private">Privat</option>
<option value="club">Verein</option>
<option value="official">Offiziell</option>
</select>
</div>
<div className="form-row">
<label className="form-label">
<input
type="checkbox"
checked={!!journalCorrectionDraft.rights_holder_confirmed}
onChange={(e) => setJournalCorrectionDraft((d) => ({ ...d, rights_holder_confirmed: e.target.checked }))}
style={{ marginRight: 8 }}
/>
Ich bestätige, dass ich die erforderlichen Rechte an diesem Medium besitze *
</label>
</div>
<div className="form-row">
<label className="form-label">
<input
type="checkbox"
checked={!!journalCorrectionDraft.contains_identifiable_persons}
onChange={(e) => setJournalCorrectionDraft((d) => ({ ...d, contains_identifiable_persons: e.target.checked, person_consent_confirmed: e.target.checked ? d.person_consent_confirmed : null }))}
style={{ marginRight: 8 }}
/>
Erkennbare Personen abgebildet *
</label>
</div>
{journalCorrectionDraft.contains_identifiable_persons ? (
<div className="form-row" style={{ paddingLeft: 24 }}>
<label className="form-label">
<input
type="checkbox"
checked={!!journalCorrectionDraft.person_consent_confirmed}
onChange={(e) => setJournalCorrectionDraft((d) => ({ ...d, person_consent_confirmed: e.target.checked }))}
style={{ marginRight: 8 }}
/>
Einwilligung aller erkennbaren Personen liegt vor *
</label>
</div>
) : null}
<div className="form-row">
<label className="form-label">
<input
type="checkbox"
checked={!!journalCorrectionDraft.contains_minors}
onChange={(e) => setJournalCorrectionDraft((d) => ({ ...d, contains_minors: e.target.checked, parental_consent_confirmed: e.target.checked ? d.parental_consent_confirmed : null }))}
style={{ marginRight: 8 }}
/>
Minderjährige abgebildet *
</label>
</div>
{journalCorrectionDraft.contains_minors ? (
<div className="form-row" style={{ paddingLeft: 24 }}>
<label className="form-label">
<input
type="checkbox"
checked={!!journalCorrectionDraft.parental_consent_confirmed}
onChange={(e) => setJournalCorrectionDraft((d) => ({ ...d, parental_consent_confirmed: e.target.checked }))}
style={{ marginRight: 8 }}
/>
Einwilligung der Erziehungsberechtigten liegt vor *
</label>
</div>
) : null}
<div className="form-row">
<label className="form-label">
<input
type="checkbox"
checked={!!journalCorrectionDraft.contains_music}
onChange={(e) => setJournalCorrectionDraft((d) => ({ ...d, contains_music: e.target.checked, music_rights_confirmed: e.target.checked ? d.music_rights_confirmed : null }))}
style={{ marginRight: 8 }}
/>
Musik enthalten *
</label>
</div>
{journalCorrectionDraft.contains_music ? (
<div className="form-row" style={{ paddingLeft: 24 }}>
<label className="form-label">
<input
type="checkbox"
checked={!!journalCorrectionDraft.music_rights_confirmed}
onChange={(e) => setJournalCorrectionDraft((d) => ({ ...d, music_rights_confirmed: e.target.checked }))}
style={{ marginRight: 8 }}
/>
Musikrechte liegen vor *
</label>
</div>
) : null}
<div className="form-row">
<label className="form-label">
<input
type="checkbox"
checked={!!journalCorrectionDraft.contains_third_party_content}
onChange={(e) => setJournalCorrectionDraft((d) => ({ ...d, contains_third_party_content: e.target.checked, third_party_rights_confirmed: e.target.checked ? d.third_party_rights_confirmed : null }))}
style={{ marginRight: 8 }}
/>
Fremdinhalte (Logos, Grafiken etc.) enthalten *
</label>
</div>
{journalCorrectionDraft.contains_third_party_content ? (
<div className="form-row" style={{ paddingLeft: 24 }}>
<label className="form-label">
<input
type="checkbox"
checked={!!journalCorrectionDraft.third_party_rights_confirmed}
onChange={(e) => setJournalCorrectionDraft((d) => ({ ...d, third_party_rights_confirmed: e.target.checked }))}
style={{ marginRight: 8 }}
/>
Rechte an Fremdinhalten liegen vor *
</label>
</div>
) : null}
<div className="form-row">
<label className="form-label">Korrekturgrund (empfohlen)</label>
<textarea
className="form-input"
rows={2}
value={journalCorrectionDraft.correction_note || ''}
onChange={(e) => setJournalCorrectionDraft((d) => ({ ...d, correction_note: e.target.value }))}
placeholder="Warum wird die Erklärung korrigiert?"
/>
</div>
<div style={{ display: 'flex', gap: 8, marginTop: 8 }}>
<button
className="btn btn-primary"
disabled={journalCorrectionBusy}
onClick={async () => {
setJournalCorrectionBusy(true)
try {
await api.addMediaAssetDeclarationCorrection(journalModal.asset.id, journalCorrectionDraft)
setJournalCorrectionOpen(false)
const fresh = await api.getMediaAssetJournal(journalModal.asset.id)
setJournalModal(fresh)
} catch (e) {
alert(e.message || String(e))
} finally {
setJournalCorrectionBusy(false)
}
}}
>
{journalCorrectionBusy ? 'Speichern…' : 'Korrektur speichern'}
</button>
<button
className="btn btn-secondary"
disabled={journalCorrectionBusy}
onClick={() => setJournalCorrectionOpen(false)}
>
Abbrechen
</button>
</div>
</div>
) : null}
</div>
</div>
</div>