Spaces:
Running

axeronis commited on
Commit
fc0d9c2
·
1 Parent(s): a69f086

fix(frontend): resolve variable conflict in sidebar role check

Browse files
frontend/app/dashboard/page.tsx CHANGED
@@ -91,6 +91,8 @@ interface DashboardData {
91
 
92
  const COLORS = ['#6366f1', '#8b5cf6', '#ec4899', '#f43f5e', '#10b981', '#06b6d4', '#3b82f6', '#818cf8'];
93
 
 
 
94
  export default function DashboardPage() {
95
  const { user, isLoading: authLoading } = useAuth()
96
  const router = useRouter()
@@ -99,8 +101,9 @@ export default function DashboardPage() {
99
  // Redirect managers to chats (they don't have access to analytics)
100
  useEffect(() => {
101
  if (!authLoading && user) {
102
- const isOwner = user.role?.toUpperCase() === 'OWNER' || user.role?.toUpperCase() === 'ADMIN' || user.is_superuser
103
- if (!isOwner) {
 
104
  router.replace('/chats')
105
  }
106
  }
 
91
 
92
  const COLORS = ['#6366f1', '#8b5cf6', '#ec4899', '#f43f5e', '#10b981', '#06b6d4', '#3b82f6', '#818cf8'];
93
 
94
+ import { isOwner } from '@/lib/permissions'
95
+
96
  export default function DashboardPage() {
97
  const { user, isLoading: authLoading } = useAuth()
98
  const router = useRouter()
 
101
  // Redirect managers to chats (they don't have access to analytics)
102
  useEffect(() => {
103
  if (!authLoading && user) {
104
+ // Use helper for consistent check
105
+ const hasAccess = isOwner(user.role) || user.is_superuser
106
+ if (!hasAccess) {
107
  router.replace('/chats')
108
  }
109
  }
frontend/components/Sidebar.tsx CHANGED
@@ -27,6 +27,7 @@ import { NavItem } from './Sidebar/NavItem'
27
  import { api } from '@/lib/api'
28
  import { cn } from '@/lib/utils'
29
  import { useTranslation } from '@/lib/i18n'
 
30
 
31
  // ============================================================================
32
  // Animation Variants
@@ -125,12 +126,12 @@ export function Sidebar() {
125
 
126
  const isActive = (path: string) => pathname === path || pathname.startsWith(path + '/')
127
  const isAdmin = user?.is_superuser || user?.role?.toUpperCase() === 'ADMIN'
128
- const isOwner = user?.role?.toUpperCase() === 'OWNER' || user?.role?.toUpperCase() === 'ADMIN' || user?.is_superuser
129
 
130
  // Filter items based on role
131
- const visibleMainItems = mainNavItems.filter(item => isOwner || !item.ownerOnly)
132
- const visibleIntegrationItems = integrationItems.filter(item => isOwner || !item.ownerOnly)
133
- const visibleSettingsItems = settingsItems.filter(item => isOwner || !item.ownerOnly)
134
 
135
  // Trial banner logic
136
  const isTrial = usageStats?.plan === 'trial'
@@ -259,7 +260,7 @@ export function Sidebar() {
259
  </motion.div>
260
  )}
261
  {/* Trial/Subscription Banner */}
262
- {usageStats && isOwner && (
263
  <motion.div
264
  initial={{ opacity: 0 }}
265
  animate={{ opacity: 1 }}
 
27
  import { api } from '@/lib/api'
28
  import { cn } from '@/lib/utils'
29
  import { useTranslation } from '@/lib/i18n'
30
+ import { isOwner } from '@/lib/permissions'
31
 
32
  // ============================================================================
33
  // Animation Variants
 
126
 
127
  const isActive = (path: string) => pathname === path || pathname.startsWith(path + '/')
128
  const isAdmin = user?.is_superuser || user?.role?.toUpperCase() === 'ADMIN'
129
+ const isOwnerUser = isOwner(user?.role) || isAdmin
130
 
131
  // Filter items based on role
132
+ const visibleMainItems = mainNavItems.filter(item => isOwnerUser || !item.ownerOnly)
133
+ const visibleIntegrationItems = integrationItems.filter(item => isOwnerUser || !item.ownerOnly)
134
+ const visibleSettingsItems = settingsItems.filter(item => isOwnerUser || !item.ownerOnly)
135
 
136
  // Trial banner logic
137
  const isTrial = usageStats?.plan === 'trial'
 
260
  </motion.div>
261
  )}
262
  {/* Trial/Subscription Banner */}
263
+ {usageStats && isOwnerUser && (
264
  <motion.div
265
  initial={{ opacity: 0 }}
266
  animate={{ opacity: 1 }}
frontend/lib/permissions.ts CHANGED
@@ -4,7 +4,7 @@
4
  * Проверка прав доступа для разных ролей
5
  */
6
 
7
- export type UserRole = 'OWNER' | 'MANAGER'
8
 
9
  /**
10
  * Проверяет, имеет ли пользователь доступ к определённому разделу
@@ -31,8 +31,10 @@ export function hasAccess(userRole: UserRole | undefined, section: string): bool
31
  /**
32
  * Проверяет, является ли пользователь владельцем
33
  */
34
- export function isOwner(userRole: UserRole | undefined): boolean {
35
- return userRole === 'OWNER'
 
 
36
  }
37
 
38
  /**
 
4
  * Проверка прав доступа для разных ролей
5
  */
6
 
7
+ export type UserRole = 'OWNER' | 'MANAGER' | 'ADMIN' | 'admin' | string
8
 
9
  /**
10
  * Проверяет, имеет ли пользователь доступ к определённому разделу
 
31
  /**
32
  * Проверяет, является ли пользователь владельцем
33
  */
34
+ export function isOwner(userRole: string | undefined): boolean {
35
+ if (!userRole) return false
36
+ const role = userRole.toUpperCase()
37
+ return role === 'OWNER' || role === 'ADMIN'
38
  }
39
 
40
  /**