Enhance user contact data visibility based on role permissions
This commit introduces role-based access control for user contact information in the CMS. It updates the user list display to show email and phone details only to users with the 'vorstand' role, while masking this information for others. Additionally, it modifies the API endpoints to ensure that contact data is only returned for authorized users, improving data privacy and security.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { getUserFromToken, readUsers, hasAnyRole, migrateUserRoles } from '../../../utils/auth.js'
|
||||
import { getUserFromToken, readUsers, hasAnyRole, hasRole, migrateUserRoles } from '../../../utils/auth.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
@@ -13,18 +13,24 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
|
||||
const users = await readUsers()
|
||||
|
||||
// Return users without passwords
|
||||
|
||||
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: u.email,
|
||||
email,
|
||||
name: u.name,
|
||||
roles: roles,
|
||||
role: roles[0] || 'mitglied', // Rückwärtskompatibilität
|
||||
phone: u.phone || '',
|
||||
phone,
|
||||
active: u.active,
|
||||
created: u.created,
|
||||
lastLogin: u.lastLogin
|
||||
|
||||
Reference in New Issue
Block a user