fix: system admin bypasses workspace filter in sidebar
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { useState, useEffect, useCallback } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { useMyWorkspaces, useWorkspaceContext, type WorkspaceContext } from '@/api/hooks/workspaces';
|
import { useMyWorkspaces, useWorkspaceContext, type WorkspaceContext } from '@/api/hooks/workspaces';
|
||||||
|
import { useAuthStore } from '@/store/authStore';
|
||||||
|
|
||||||
const STORAGE_KEY = 'leocrm-active-workspace';
|
const STORAGE_KEY = 'leocrm-active-workspace';
|
||||||
|
|
||||||
@@ -47,7 +48,10 @@ export function useWorkspace() {
|
|||||||
|
|
||||||
// Check if a module is visible in the current workspace
|
// Check if a module is visible in the current workspace
|
||||||
const isModuleVisible = useCallback((moduleKey: string): boolean => {
|
const isModuleVisible = useCallback((moduleKey: string): boolean => {
|
||||||
// If no workspace context, show all (backward compatible)
|
// System admins see all modules regardless of workspace
|
||||||
|
const user = useAuthStore.getState().user;
|
||||||
|
if (user?.is_system_admin) return true;
|
||||||
|
// If no workspace context, show all (backward compatible)
|
||||||
if (!context?.workspace_id || !context?.modules?.length) return true;
|
if (!context?.workspace_id || !context?.modules?.length) return true;
|
||||||
return visibleModuleKeys.has(moduleKey);
|
return visibleModuleKeys.has(moduleKey);
|
||||||
}, [context, visibleModuleKeys]);
|
}, [context, visibleModuleKeys]);
|
||||||
|
|||||||
Reference in New Issue
Block a user