diff --git a/src/boot/login.ts b/src/boot/login.ts index a4571eb..553db5b 100644 --- a/src/boot/login.ts +++ b/src/boot/login.ts @@ -5,16 +5,8 @@ import { Store } from 'vuex'; export default boot>(({ router, store }) => { router.beforeEach((to, from, next) => { - const user = store.state.user.currentUser; const session = store.state.session.currentSession; - let permissions: string[] = []; - if (user) { - user.roles.forEach(role => { - permissions = permissions.concat(role.permissions); - }); - } - if (to.name != 'login') { if (!session || session.expires <= new Date()) { store.dispatch('session/logout').catch(error => { @@ -32,7 +24,7 @@ export default boot>(({ router, store }) => { return (<{ permissions: FG.Permission[] }>( record.meta )).permissions.every((permission: string) => { - return permissions.includes(permission); + return store.state.user.currentPermissions.includes(permission); }); } } diff --git a/src/components/navigation/EssentialLink.vue b/src/components/navigation/EssentialLink.vue index 5e13044..f5fcf12 100644 --- a/src/components/navigation/EssentialLink.vue +++ b/src/components/navigation/EssentialLink.vue @@ -23,6 +23,7 @@ import { computed, defineComponent } from '@vue/composition-api'; import { Store } from 'vuex'; import { StateInterface } from 'src/store'; +import { hasPermissions } from 'src/components/permission'; export default defineComponent({ name: 'EssentialLink', @@ -65,17 +66,9 @@ export default defineComponent({ return props.title; }); - const hasPermissions = computed(() => { - let permissions = props.permissions; - if (permissions) { - return (permissions).every(permission => { - return (<{ 'user/permissions': string[] }>( - (>root.$store).getters - ))['user/permissions'].includes(permission); - }); - } - return true; - }); + const isGranted = computed(() => + hasPermissions(props.permissions || [], root.$store) + ); return { realTitle: title, hasPermissions }; } diff --git a/src/components/navigation/ShortCutLink.vue b/src/components/navigation/ShortCutLink.vue index 85e7807..8f26424 100644 --- a/src/components/navigation/ShortCutLink.vue +++ b/src/components/navigation/ShortCutLink.vue @@ -1,11 +1,12 @@ diff --git a/src/components/permission.ts b/src/components/permission.ts new file mode 100644 index 0000000..f005ab7 --- /dev/null +++ b/src/components/permission.ts @@ -0,0 +1,14 @@ +import { Store } from 'vuex'; +import { StateInterface } from 'src/store'; + +export function hasPermission( + permission: string, + store: Store +) { + return store.state.user.currentPermissions.includes(permission); +} + +export function hasPermissions(needed: string[], store: Store) { + const permissions = store.state.user.currentPermissions; + return needed.every(value => permissions.includes(value)); +} diff --git a/src/plugins/user/components/UserSelector.vue b/src/plugins/user/components/UserSelector.vue new file mode 100644 index 0000000..109d508 --- /dev/null +++ b/src/plugins/user/components/UserSelector.vue @@ -0,0 +1,41 @@ + + + diff --git a/src/plugins/user/components/settings/Main.vue b/src/plugins/user/components/settings/Main.vue deleted file mode 100644 index 607aa00..0000000 --- a/src/plugins/user/components/settings/Main.vue +++ /dev/null @@ -1,191 +0,0 @@ - - - diff --git a/src/plugins/user/components/settings/MainUserSettings.vue b/src/plugins/user/components/settings/MainUserSettings.vue new file mode 100644 index 0000000..218dad3 --- /dev/null +++ b/src/plugins/user/components/settings/MainUserSettings.vue @@ -0,0 +1,194 @@ + + + diff --git a/src/plugins/user/pages/AdminSettings.vue b/src/plugins/user/pages/AdminSettings.vue new file mode 100644 index 0000000..95461f2 --- /dev/null +++ b/src/plugins/user/pages/AdminSettings.vue @@ -0,0 +1,55 @@ + + + diff --git a/src/plugins/user/pages/Settings.vue b/src/plugins/user/pages/Settings.vue index 6fc4106..68f9ce2 100644 --- a/src/plugins/user/pages/Settings.vue +++ b/src/plugins/user/pages/Settings.vue @@ -4,41 +4,41 @@ padding class="fit row justify-center content-center items-center q-gutter-sm" > -
- -
- Allgemeine Einstellungen: -
-
-
- Aktive Sessions: -
- -
-
- -
+ + + +
Benutzereinstellungen
+
+ +
+
Aktive Sessions:
+