Skip to content

Commit

Permalink
add isAdmin test for user
Browse files Browse the repository at this point in the history
  • Loading branch information
YohannParis committed Oct 15, 2024
1 parent 56cd697 commit aba2039
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { computed, ref } from 'vue';
import { exportProjectAsFile } from '@/services/project';
import { AcceptedExtensions } from '@/types/common';
import { MenuItem } from 'primevue/menuitem';
import useAuthStore from '@/stores/auth';
const props = defineProps<{ project: Project | null }>();
Expand Down Expand Up @@ -89,8 +90,8 @@ const projectMenuItems = computed(() => {
items.push(editDetailsMenuItem, shareMenuItem);
}
// Creator of the project
if (props.project?.userPermission === 'creator') {
// Creator of the project, or an admin
if (props.project?.userPermission === 'creator' || useAuthStore().isAdmin) {
items.push(removeMenuItem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ const userMenuItems = ref([
command: () => {
router.push(RoutePath.UserAdmin);
},
visible: auth.user?.roles.some((r) => r.name === 'ADMIN')
visible: auth.isAdmin
},
{
label: 'Logout',
Expand Down
9 changes: 8 additions & 1 deletion packages/client/hmi-client/src/stores/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { User } from '@/types/Types';
import axios, { AxiosHeaders } from 'axios';
import { computed, ref } from 'vue';
import { createOidc, Oidc } from 'oidc-spa';
import { RoleType } from '@/types/Types';

/**
* Main store used for authentication
Expand Down Expand Up @@ -70,6 +71,11 @@ const useAuthStore = defineStore('auth', () => {
await loadUserModel();
};

const isAdmin = computed(() => {
if (!user.value) return false;
return user.value?.roles.some((r) => r.name === RoleType.Admin);
});

return {
login,
logout,
Expand All @@ -78,7 +84,8 @@ const useAuthStore = defineStore('auth', () => {
updateUser,
loadUserModel,
userInitials,
init
init,
isAdmin
};
});

Expand Down

0 comments on commit aba2039

Please sign in to comment.