Skip to content

Commit

Permalink
it's fine
Browse files Browse the repository at this point in the history
  • Loading branch information
Zio-4 committed Apr 3, 2024
1 parent 37b1a23 commit 0dd8c77
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/components/CreateAdministration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ const submit = async () => {
await roarfirekit.value.createAdministration(args).then(() => {
toast.add({ severity: 'success', summary: 'Success', detail: 'Administration created', life: 3000 });
// Used to rerender component. However, this does not invalidate the query. Deprecate?
administrationQueryKeyIndex.value += 1;
// invalidate the query
// Can be further specified if many other queries use this key
queryClient.invalidateQueries({ queryKey: ['administrations'] });
// TODO: Invalidate for administrations query.
// This does not work in prod for some reason.
// queryClient.invalidateQueries({ queryKey: ['administrations'] })
router.push({ name: 'Home' });
});
Expand Down
31 changes: 23 additions & 8 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ const router = createRouter({
});

router.beforeEach(async (to, from, next) => {
const isLevante = import.meta.env.MODE === 'LEVANTE';
// Don't allow routing to LEVANTE pages if not in LEVANTE instance
if (import.meta.env.MODE !== 'LEVANTE' && to.meta?.project === 'LEVANTE') {
if (!isLevante && to.meta?.project === 'LEVANTE') {
next({ name: 'Home' });
// next function can only be called once per route
return;
Expand Down Expand Up @@ -367,18 +368,32 @@ router.beforeEach(async (to, from, next) => {
// 3. Super Admin: false, Admin: false (Allowed routes for all users)
// (Also exists because requiresAdmin/requiresSuperAdmin is not defined on every route)

if (requiresAdmin || requiresSuperAdmin) {
if (isUserSuperAdmin || isUserAdmin) {
// Currently no difference between admin and super admin
if (isUserSuperAdmin) {
next();
return;
} else if (isUserAdmin) {
// LEVANTE dashboard has opened some pages to administrators before the ROAR dashboard
// So if isLevante, then allow regular admins to access any route with requireAdmin = true.
// and if ROAR, then prohibit regular admins from accessing any route with requireSuperAdmin = true.
if (isLevante && requiresAdmin) {
next();
} else {
// Block routing if user lacks permissions
return;
} else if (requiresSuperAdmin) {
next({ name: 'Home' });
return;
}
} else {
// Allow all users to access the route
next();
return;
}

// If we get here, the user is a regular user
if (requiresSuperAdmin || requiresAdmin) {
next({ name: 'Home' });
return;
}

next();
return;
});

export default router;
4 changes: 4 additions & 0 deletions src/router/sidebarActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export const getSidebarActions = ({ isSuperAdmin = false, isAdmin = false, inclu
if (import.meta.env.MODE === 'LEVANTE') {
return sidebarActionOptions.filter((action) => {
if (action.project === 'LEVANTE' || action.project === 'ALL') {
// If the action requires admin and the user is an admin, or if the action
// requires super admin and the user is a super admin,
// or if the action does not require admin or super admin,
// the action will be in the dropdown
if (
(action.requiresAdmin && isAdmin) ||
(action.requiresSuperAdmin && isSuperAdmin) ||
Expand Down

0 comments on commit 0dd8c77

Please sign in to comment.