fixed permission implementation for ressources

This commit is contained in:
2025-11-21 00:58:34 +01:00
parent 0d17fda341
commit d23bfa0376
6 changed files with 857 additions and 54 deletions

View File

@@ -1,11 +1,13 @@
import { useState, useEffect } from 'react'
import { useParams, useNavigate } from 'react-router-dom'
import { useAuth } from '../contexts/AuthContext'
import { usePermissions } from '../hooks/usePermissions'
const SpaceDetail = () => {
const { id } = useParams()
const navigate = useNavigate()
const { authFetch } = useAuth()
const { canCreateFqdn, canDeleteFqdn, canSignCSR, canUploadCSR, refreshPermissions } = usePermissions()
const [space, setSpace] = useState(null)
const [fqdns, setFqdns] = useState([])
const [showForm, setShowForm] = useState(false)
@@ -123,6 +125,8 @@ const SpaceDetail = () => {
setFqdns([...fqdns, newFqdn])
setFormData({ fqdn: '', description: '' })
setShowForm(false)
// Aktualisiere Berechtigungen nach dem Erstellen eines FQDNs
refreshPermissions()
} else {
let errorMessage = 'Fehler beim Erstellen des FQDN'
try {
@@ -176,6 +180,8 @@ const SpaceDetail = () => {
setShowDeleteModal(false)
setFqdnToDelete(null)
setConfirmChecked(false)
// Aktualisiere Berechtigungen nach dem Löschen eines FQDNs
refreshPermissions()
} else {
const errorData = await response.json().catch(() => ({ error: 'Fehler beim Löschen' }))
alert(errorData.error || 'Fehler beim Löschen des FQDN')
@@ -586,7 +592,13 @@ const SpaceDetail = () => {
</h3>
<button
onClick={() => setShowForm(!showForm)}
className="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg transition-all duration-200"
disabled={!canCreateFqdn(id) && !showForm}
className={`px-4 py-2 font-semibold rounded-lg transition-all duration-200 ${
canCreateFqdn(id) || showForm
? 'bg-blue-600 hover:bg-blue-700 text-white'
: 'bg-slate-600 text-slate-400 cursor-not-allowed opacity-50'
}`}
title={!canCreateFqdn(id) && !showForm ? 'Keine Berechtigung zum Erstellen von FQDNs' : ''}
>
{showForm ? 'Abbrechen' : '+ Neuer FQDN'}
</button>
@@ -630,11 +642,18 @@ const SpaceDetail = () => {
<button
onClick={(e) => {
e.stopPropagation()
handleRequestSigning(fqdn)
if (canSignCSR(id)) {
handleRequestSigning(fqdn)
}
}}
className="p-2 text-purple-400 hover:text-purple-300 hover:bg-purple-500/20 rounded-lg transition-colors"
title="CSR signieren lassen"
aria-label="CSR signieren lassen"
disabled={!canSignCSR(id)}
className={`p-2 rounded-lg transition-colors ${
canSignCSR(id)
? 'text-purple-400 hover:text-purple-300 hover:bg-purple-500/20'
: 'text-slate-500 cursor-not-allowed opacity-50'
}`}
title={canSignCSR(id) ? 'CSR signieren lassen' : 'Keine Berechtigung zum Signieren von CSRs'}
aria-label={canSignCSR(id) ? 'CSR signieren lassen' : 'Keine Berechtigung'}
>
<svg
className="w-5 h-5"
@@ -692,16 +711,23 @@ const SpaceDetail = () => {
}
e.target.value = ''
}}
disabled={uploadingCSR}
disabled={uploadingCSR || !canUploadCSR(id)}
/>
<button
className="p-2 text-blue-400 hover:text-blue-300 hover:bg-blue-500/20 rounded-lg transition-colors"
title="CSR hochladen"
aria-label="CSR hochladen"
disabled={!canUploadCSR(id)}
className={`p-2 rounded-lg transition-colors ${
canUploadCSR(id)
? 'text-blue-400 hover:text-blue-300 hover:bg-blue-500/20'
: 'text-slate-500 cursor-not-allowed opacity-50'
}`}
title={canUploadCSR(id) ? 'CSR hochladen' : 'Keine Berechtigung zum Hochladen von CSRs'}
aria-label={canUploadCSR(id) ? 'CSR hochladen' : 'Keine Berechtigung'}
onClick={(e) => {
e.stopPropagation()
e.preventDefault()
e.currentTarget.parentElement.querySelector('input[type="file"]')?.click()
if (canUploadCSR(id)) {
e.currentTarget.parentElement.querySelector('input[type="file"]')?.click()
}
}}
>
<svg
@@ -806,11 +832,18 @@ const SpaceDetail = () => {
<button
onClick={(e) => {
e.stopPropagation()
handleDelete(fqdn)
if (canDeleteFqdn(id)) {
handleDelete(fqdn)
}
}}
className="p-2 text-red-400 hover:text-red-300 hover:bg-red-500/20 rounded-lg transition-colors"
title="FQDN löschen"
aria-label="FQDN löschen"
disabled={!canDeleteFqdn(id)}
className={`p-2 rounded-lg transition-colors ${
canDeleteFqdn(id)
? 'text-red-400 hover:text-red-300 hover:bg-red-500/20'
: 'text-slate-500 cursor-not-allowed opacity-50'
}`}
title={canDeleteFqdn(id) ? 'FQDN löschen' : 'Keine Berechtigung zum Löschen von FQDNs'}
aria-label={canDeleteFqdn(id) ? 'FQDN löschen' : 'Keine Berechtigung'}
>
<svg
className="w-5 h-5"