Commit c1821120 authored by Django Janny's avatar Django Janny
Browse files

UNOTOPLYS-299 - Problème de droits sur onglet de la home

parent e0c34877
......@@ -25,7 +25,7 @@ const store = config.initVueXStore(Vue);
const alertService = new AlertService(store);
const translationService = new TranslationService(store, i18n);
const accountService = new AccountService(store, translationService, router);
const headerService = new HeaderService(store, translationService, i18n);
const headerService = new HeaderService(store, accountService, translationService, i18n);
const frontFormService = new FrontFormService(store, router, alertService, translationService, i18n);
router.beforeEach((to, from, next) => {
......
......@@ -88,4 +88,21 @@ export default class AccountService {
public get token(): any {
return localStorage.getItem('jhi-authenticationToken') || sessionStorage.getItem('jhi-authenticationToken');
}
public hasAuthoritiesForRoute(path: String): boolean {
if (this.router.getRoutes().find(r => r.path === path) && !this.router.getRoutes().find(r => r.path === path).meta.authorities) {
return true;
}
for (let authority of this.userAuthorities) {
if (
this.router
.getRoutes()
.find(r => r.path === path)
?.meta?.authorities?.includes(authority)
) {
return true;
}
}
return false;
}
}
......@@ -2,6 +2,7 @@ import { Store } from 'vuex';
import axios from 'axios';
import VueI18n from 'vue-i18n';
import TranslationService from '@/locale/translation.service';
import AccountService from '@/services/account.service';
const filArianeBaseApiUrl = 'api/filariane';
......@@ -14,10 +15,41 @@ export default class HeaderService {
public static readonly TAB_KEY_FORMS = 'forms';
public static readonly TAB_KEY_USERS = 'users';
constructor(private store: Store<any>, private translationService: TranslationService, private i18n: VueI18n) {
constructor(
private store: Store<any>,
private accountService: AccountService,
private translationService: TranslationService,
private i18n: VueI18n
) {
this.translationService.refreshTranslation(this.store.getters.currentLanguage);
}
public updateTabsForHome(currentKey: string): void {
let tabs = [];
if (this.accountService.hasAuthoritiesForRoute('/admin/forms')) {
tabs.push({
title: this.i18n.t('onglets.forms'),
link: `/admin/forms`,
isCurrent: currentKey === HeaderService.TAB_KEY_FORMS,
});
}
if (this.accountService.hasAuthoritiesForRoute('/admin/workspaces')) {
tabs.push({
title: this.i18n.t('onglets.workspaces'),
link: `/admin/workspaces`,
isCurrent: currentKey === HeaderService.TAB_KEY_WORKSPACES,
});
}
if (this.accountService.hasAuthoritiesForRoute('/admin/user')) {
tabs.push({
title: this.i18n.t('onglets.utilisateurs'),
link: '/admin/user',
isCurrent: currentKey === HeaderService.TAB_KEY_USERS,
});
}
this.store.commit('tabs', tabs);
}
public updateTabsForWorkspaceId(workspaceId: number, currentKey: string): void {
const tabs: any[] = [
{
......@@ -81,25 +113,4 @@ export default class HeaderService {
this.store.commit('filArianeElements', res.data);
});
}
public updateTabsForHome(currentKey: string): void {
let tabs = [
{
title: this.i18n.t('onglets.forms'),
link: `/admin/forms`,
isCurrent: currentKey === HeaderService.TAB_KEY_FORMS,
},
{
title: this.i18n.t('onglets.workspaces'),
link: `/admin/workspaces`,
isCurrent: currentKey === HeaderService.TAB_KEY_WORKSPACES,
},
{
title: this.i18n.t('onglets.utilisateurs'),
link: '/admin/user',
isCurrent: currentKey === HeaderService.TAB_KEY_USERS,
},
];
this.store.commit('tabs', tabs);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment