Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 44s
This commit modifies the navigation and CMS user management components to allow access for both 'admin' and 'vorstand' roles. The changes include updating the conditional rendering logic in the Navigation and index.vue files, as well as adjusting the API endpoint to reflect the new role permissions, enhancing the flexibility of user access within the CMS.
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
import { getUserFromToken, readUsers, hasAnyRole, hasRole, migrateUserRoles } from '../../../utils/auth.js'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
const token = getCookie(event, 'auth_token')
|
|
const currentUser = await getUserFromToken(token)
|
|
|
|
// Seite darf von Admin ODER Vorstand genutzt werden
|
|
if (!currentUser || !hasAnyRole(currentUser, 'admin', 'vorstand')) {
|
|
throw createError({
|
|
statusCode: 403,
|
|
message: 'Zugriff verweigert'
|
|
})
|
|
}
|
|
|
|
const users = await readUsers()
|
|
|
|
const isVorstand = hasRole(currentUser, 'vorstand')
|
|
|
|
// Return users without Passwörter; Kontaktdaten nur für Vorstand
|
|
const safeUsers = users.map(u => {
|
|
const migrated = migrateUserRoles({ ...u })
|
|
const roles = Array.isArray(migrated.roles) ? migrated.roles : (migrated.role ? [migrated.role] : ['mitglied'])
|
|
|
|
const email = isVorstand ? u.email : undefined
|
|
const phone = isVorstand ? (u.phone || '') : undefined
|
|
|
|
return {
|
|
id: u.id,
|
|
email,
|
|
name: u.name,
|
|
roles: roles,
|
|
role: roles[0] || 'mitglied', // Rückwärtskompatibilität
|
|
phone,
|
|
active: u.active,
|
|
created: u.created,
|
|
lastLogin: u.lastLogin
|
|
}
|
|
})
|
|
|
|
return {
|
|
users: safeUsers
|
|
}
|
|
} catch (error) {
|
|
console.error('Fehler beim Laden der Benutzer:', error)
|
|
throw error
|
|
}
|
|
})
|
|
|