Преглед изворни кода

fix:修改分组展示菜单权限

韩洋 пре 3 недеља
родитељ
комит
132c8ae80a

+ 21 - 4
default/src/features/keys/components/api-key-group-combobox.tsx

@@ -23,6 +23,12 @@ import { useTranslation } from 'react-i18next'
 import { MultiSelect, type Option } from '@/components/multi-select'
 import { Button } from '@/components/ui/button'
 import { Checkbox } from '@/components/ui/checkbox'
+import {
+  Tooltip,
+  TooltipContent,
+  TooltipProvider,
+  TooltipTrigger,
+} from '@/components/ui/tooltip'
 import { cn } from '@/lib/utils'
 
 // Model type from group API response
@@ -248,7 +254,7 @@ export function ApiKeyGroupCombobox({
                 disabled && 'pointer-events-none opacity-60'
               )}
             >
-              <div className='flex items-start gap-3'>
+              <div className='flex min-w-0 items-start gap-3'>
                 <label className='flex min-w-0 flex-1 cursor-pointer items-start gap-3'>
                   <Checkbox
                     checked={checked}
@@ -261,9 +267,20 @@ export function ApiKeyGroupCombobox({
                       {option.label}
                     </span>
                     {option.desc && (
-                      <span className='text-muted-foreground block truncate text-xs'>
-                        {option.desc}
-                      </span>
+                      <TooltipProvider>
+                        <Tooltip>
+                          <TooltipTrigger
+                            render={
+                              <span className='text-muted-foreground block truncate text-xs'>
+                                {option.desc}
+                              </span>
+                            }
+                          />
+                          <TooltipContent className='max-w-sm whitespace-normal break-words'>
+                            {option.desc}
+                          </TooltipContent>
+                        </Tooltip>
+                      </TooltipProvider>
                     )}
                   </span>
                 </label>

+ 2 - 0
default/src/hooks/use-sidebar-data.ts

@@ -109,11 +109,13 @@ export function useSidebarData(): SidebarData {
             title: t('Model Pricing'),
             url: '/model-pricing',
             icon: Tags,
+            permissionCode: PERMISSION_CODES.PRICING_VIEW,
           },
           {
             title: t('Group Management'),
             url: '/groups',
             icon: Boxes,
+            permissionCode: PERMISSION_CODES.GROUP_VIEW,
           },
         ],
       },

+ 12 - 1
default/src/routes/_authenticated/groups/index.tsx

@@ -17,10 +17,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
 For commercial licensing, please contact support@quantumnous.com
 */
 
-import { createFileRoute } from '@tanstack/react-router'
+import { createFileRoute, redirect } from '@tanstack/react-router'
 import z from 'zod'
 
 import { Groups } from '@/features/groups'
+import { PERMISSION_CODES, hasPermissionCode } from '@/lib/admin-permissions'
+import { useAuthStore } from '@/stores/auth-store'
 
 const groupsSearchSchema = z.object({
   page: z.number().optional().catch(1),
@@ -29,6 +31,15 @@ const groupsSearchSchema = z.object({
 })
 
 export const Route = createFileRoute('/_authenticated/groups/')({
+  beforeLoad: () => {
+    const { auth } = useAuthStore.getState()
+
+    if (!hasPermissionCode(auth.user, PERMISSION_CODES.GROUP_VIEW)) {
+      throw redirect({
+        to: '/403',
+      })
+    }
+  },
   validateSearch: groupsSearchSchema,
   component: Groups,
 })

+ 12 - 1
default/src/routes/_authenticated/model-pricing/index.tsx

@@ -16,10 +16,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
 
 For commercial licensing, please contact support@quantumnous.com
 */
-import { createFileRoute } from '@tanstack/react-router'
+import { createFileRoute, redirect } from '@tanstack/react-router'
 
 import { ModelPricingPage } from '@/features/model-pricing'
+import { PERMISSION_CODES, hasPermissionCode } from '@/lib/admin-permissions'
+import { useAuthStore } from '@/stores/auth-store'
 
 export const Route = createFileRoute('/_authenticated/model-pricing/')({
+  beforeLoad: () => {
+    const { auth } = useAuthStore.getState()
+
+    if (!hasPermissionCode(auth.user, PERMISSION_CODES.PRICING_VIEW)) {
+      throw redirect({
+        to: '/403',
+      })
+    }
+  },
   component: ModelPricingPage,
 })