feat(store): normalize permissions data structure in loadPermissions action

- Updated the loadPermissions action to normalize the permissions data structure, ensuring default values for role, isOwner, and permissions.
- Enhanced resource permission checks by using a fallback for undefined permissions, improving robustness in access control logic.
This commit is contained in:
Torsten Schulz (local)
2026-02-04 12:14:29 +01:00
parent 1f94c273ae
commit 12184c2f72

View File

@@ -165,7 +165,13 @@ const store = createStore({
async loadPermissions({ commit }, clubId) {
try {
const response = await apiClient.get(`/permissions/${clubId}`);
commit('setPermissions', { clubId, permissions: response.data });
const data = response.data || {};
const normalized = {
role: data.role ?? 'member',
isOwner: data.isOwner ?? false,
permissions: data.permissions ?? {}
};
commit('setPermissions', { clubId, permissions: normalized });
} catch (error) {
console.error('Error loading permissions:', error);
// Set default permissions (read-only)
@@ -230,7 +236,8 @@ const store = createStore({
if (!perms) return false;
if (perms.isOwner) return true;
if (resource === 'mytischtennis') return true; // MyTischtennis für alle
const resourcePerms = perms.permissions[resource];
const permissionsMap = perms.permissions || {};
const resourcePerms = permissionsMap[resource];
if (!resourcePerms) return false;
return resourcePerms[action] === true;
},