Fix: wildcard permissions (GM modules visible), Admin link and module card
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -83,6 +83,16 @@ function DashboardContent() {
|
|||||||
href: '/marketing',
|
href: '/marketing',
|
||||||
description: 'الحملات التسويقية والعملاء المحتملين',
|
description: 'الحملات التسويقية والعملاء المحتملين',
|
||||||
permission: 'marketing'
|
permission: 'marketing'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'admin',
|
||||||
|
name: 'لوحة الإدارة',
|
||||||
|
nameEn: 'Admin Panel',
|
||||||
|
icon: Shield,
|
||||||
|
color: 'bg-red-500',
|
||||||
|
href: '/admin',
|
||||||
|
description: 'إدارة المستخدمين والأدوار وسجل العمليات',
|
||||||
|
permission: 'admin'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -118,7 +128,7 @@ function DashboardContent() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Admin Panel Link - Only for admins */}
|
{/* Admin Panel Link - Only for admins */}
|
||||||
{user?.role?.name === 'المدير العام' && (
|
{(hasPermission('admin', 'view') || user?.role?.name === 'المدير العام' || user?.role?.nameEn === 'General Manager') && (
|
||||||
<Link
|
<Link
|
||||||
href="/admin"
|
href="/admin"
|
||||||
className="p-2 hover:bg-red-50 rounded-lg transition-colors relative group"
|
className="p-2 hover:bg-red-50 rounded-lg transition-colors relative group"
|
||||||
|
|||||||
@@ -59,18 +59,26 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Transform backend permissions format to frontend format
|
// Transform backend permissions format to frontend format
|
||||||
|
// Backend uses actions: ['*'] or ['read','create',...] - wildcard grants all
|
||||||
const transformPermissions = (permissions: any[]): Permission[] => {
|
const transformPermissions = (permissions: any[]): Permission[] => {
|
||||||
return permissions.map(p => ({
|
const hasWildcard = (actions: string[] | any) => {
|
||||||
|
const arr = Array.isArray(actions) ? actions : []
|
||||||
|
return arr.includes('*') || arr.includes('all')
|
||||||
|
}
|
||||||
|
return permissions.map(p => {
|
||||||
|
const wildcard = hasWildcard(p.actions)
|
||||||
|
return {
|
||||||
id: p.id,
|
id: p.id,
|
||||||
module: p.module,
|
module: p.module,
|
||||||
actions: p.actions,
|
actions: p.actions,
|
||||||
canView: p.actions?.includes('read') || false,
|
canView: wildcard || p.actions?.includes('read') || false,
|
||||||
canCreate: p.actions?.includes('create') || false,
|
canCreate: wildcard || p.actions?.includes('create') || false,
|
||||||
canEdit: p.actions?.includes('update') || false,
|
canEdit: wildcard || p.actions?.includes('update') || false,
|
||||||
canDelete: p.actions?.includes('delete') || false,
|
canDelete: wildcard || p.actions?.includes('delete') || false,
|
||||||
canExport: p.actions?.includes('export') || false,
|
canExport: wildcard || p.actions?.includes('export') || false,
|
||||||
canApprove: p.actions?.includes('approve') || false,
|
canApprove: wildcard || p.actions?.includes('approve') || false,
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchUserData = async (token: string) => {
|
const fetchUserData = async (token: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user