diff --git a/backend/src/modules/auth/auth.service.ts b/backend/src/modules/auth/auth.service.ts index 9ca8dec..46382a1 100644 --- a/backend/src/modules/auth/auth.service.ts +++ b/backend/src/modules/auth/auth.service.ts @@ -100,8 +100,9 @@ export class AuthService { * تسجيل دخول */ async login(dto: LoginDto) { + const normalizedEmail = dto.email.trim().toLowerCase(); const user = await this.dataSource.getRepository(User).findOne({ - where: { email: dto.email, is_active: true }, + where: { email: normalizedEmail, is_active: true }, select: ['id', 'email', 'password_hash', 'tenant_id', 'role', 'name'], }); diff --git a/backend/src/modules/users/user.service.ts b/backend/src/modules/users/user.service.ts index 0559e2f..c4f0453 100644 --- a/backend/src/modules/users/user.service.ts +++ b/backend/src/modules/users/user.service.ts @@ -21,8 +21,9 @@ export class UsersService { * إضافة مستخدم لمكتب محاسبة */ async create(tenantId: string, dto: any): Promise { + const normalizedEmail = dto.email?.trim().toLowerCase(); const existing = await this.userRepository.findOne({ - where: { email: dto.email, tenant_id: tenantId }, + where: { email: normalizedEmail, tenant_id: tenantId }, }); if (existing) { @@ -33,6 +34,7 @@ export class UsersService { const user = this.userRepository.create({ ...dto, + email: normalizedEmail, password_hash: passwordHash, tenant_id: tenantId, } as Partial); @@ -85,6 +87,10 @@ export class UsersService { delete dto.password; } + if (dto.email) { + dto.email = dto.email.trim().toLowerCase(); + } + Object.assign(user, dto); try { diff --git a/frontend/src/components/layout/Sidebar.tsx b/frontend/src/components/layout/Sidebar.tsx index b150ef8..16b181d 100644 --- a/frontend/src/components/layout/Sidebar.tsx +++ b/frontend/src/components/layout/Sidebar.tsx @@ -17,19 +17,22 @@ import { } from 'lucide-react'; import { useAuthStore } from '../../store/authStore'; -const getMenuItems = (role: string | undefined) => [ +const getMenuItems = (role: string | undefined) => { + const isAdmin = role && ['admin', 'super_admin'].includes(role.toLowerCase()); + return [ { icon: LayoutDashboard, label: 'الرئيسية', path: '/dashboard' }, - ...(role === 'admin' ? [ + ...(isAdmin ? [ { icon: Crown, label: 'المركز الضريبي الموحد', path: '/elite-dashboard' }, { icon: AlertTriangle, label: 'مراقبة المخاطر', path: '/risk-monitor' } ] : []), { icon: FileText, label: 'الفواتير', path: '/invoices' }, { icon: Building2, label: 'الشركات', path: '/companies' }, - ...(role === 'admin' ? [ + ...(isAdmin ? [ { icon: Users, label: 'الموظفون', path: '/staff' } ] : []), { icon: Settings, label: 'الإعدادات', path: '/settings' }, ]; +}; export const Sidebar = () => { const navigate = useNavigate(); diff --git a/frontend/src/pages/dashboard/MultiEntityDashboard.tsx b/frontend/src/pages/dashboard/MultiEntityDashboard.tsx index d659296..72bdde3 100644 --- a/frontend/src/pages/dashboard/MultiEntityDashboard.tsx +++ b/frontend/src/pages/dashboard/MultiEntityDashboard.tsx @@ -94,6 +94,7 @@ const Cpu = ({ className }: { className?: string }) => ( export const MultiEntityDashboard = () => { const user = useAuthStore((state) => state.user); + const isAdmin = user?.role && ['admin', 'super_admin'].includes(user.role.toLowerCase()); const [companies, setCompanies] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); @@ -190,7 +191,7 @@ export const MultiEntityDashboard = () => { className="card-premium p-6 relative overflow-hidden group" > {/* AI Usage Badge */} - {user?.role === 'admin' && ( + {isAdmin && (
@@ -239,7 +240,7 @@ export const MultiEntityDashboard = () => {

{company.totalInvoices} فاتورة

- {user?.role === 'admin' && company.aiStats?.totalCost > 0 && ( + {isAdmin && company.aiStats?.totalCost > 0 && ( ${company.aiStats.totalCost.toFixed(3)} diff --git a/frontend/src/pages/staff/StaffPage.tsx b/frontend/src/pages/staff/StaffPage.tsx index d59ac52..cd9fe15 100644 --- a/frontend/src/pages/staff/StaffPage.tsx +++ b/frontend/src/pages/staff/StaffPage.tsx @@ -12,6 +12,7 @@ import apiClient from '../../api/client'; export const StaffPage = () => { const user = useAuthStore((state) => state.user); + const isAdmin = user?.role && ['admin', 'super_admin'].includes(user.role.toLowerCase()); const [staff, setStaff] = useState([]); const [isLoading, setIsLoading] = useState(true); const [searchTerm, setSearchTerm] = useState(''); @@ -79,7 +80,7 @@ export const StaffPage = () => {

إدارة الموظفين

إدارة فريق العمل المالي لمكتب المحاسبة الخاص بك.

- {user?.role === 'admin' && ( + {isAdmin && (