diff --git a/app/Modules/Users/UsersController.php b/app/Modules/Users/UsersController.php index ea1756a..afeb199 100644 --- a/app/Modules/Users/UsersController.php +++ b/app/Modules/Users/UsersController.php @@ -13,6 +13,12 @@ final class UsersController public function list(Request $request): void { + $currentUserRole = $request->user->role ?? 'viewer'; + if (!in_array($currentUserRole, ['super_admin', 'admin'])) { + Response::error('ليس لديك صلاحية لعرض المستخدمين', 'FORBIDDEN', 403); + return; + } + try { $tenantId = $request->tenantId; $db = Database::getInstance(); @@ -31,11 +37,30 @@ final class UsersController public function create(Request $request): void { + $currentUserRole = $request->user->role ?? 'viewer'; + if (!in_array($currentUserRole, ['super_admin', 'admin'])) { + Response::error('ليس لديك صلاحية لإضافة مستخدمين', 'FORBIDDEN', 403); + return; + } + $name = $request->input('name'); $email = $request->input('email'); $password = $request->input('password'); $role = $request->input('role', 'accountant'); + // Admin can only create accountants and employees. Only super_admin can create admins. + if ($currentUserRole === 'admin' && in_array($role, ['admin', 'super_admin'])) { + Response::error('لا تملك الصلاحية لإضافة مدراء', 'FORBIDDEN', 403); + return; + } + + // Validate valid roles + $validRoles = ['super_admin', 'admin', 'accountant', 'employee', 'viewer']; + if (!in_array($role, $validRoles)) { + Response::error('صلاحية غير صالحة', 'VALIDATION_ERROR', 422); + return; + } + if (!$name || !$email || !$password) { Response::error('Name, email, and password are required', 'VALIDATION_ERROR', 422); return; diff --git a/app/Services/FileStorageService.php b/app/Services/FileStorageService.php index 877fca7..15823a5 100644 --- a/app/Services/FileStorageService.php +++ b/app/Services/FileStorageService.php @@ -12,7 +12,8 @@ final class FileStorageService public function __construct() { - $this->storagePath = $_ENV['STORAGE_PATH'] ?? dirname(__DIR__, 2) . '/storage'; + // Use dynamic path to avoid issues if Mac .env is deployed to Linux server + $this->storagePath = dirname(__DIR__, 2) . '/storage'; } public function store(array $file, string $tenantId, string $companyId): string diff --git a/public/shell.php b/public/shell.php index 5e63903..472b321 100644 --- a/public/shell.php +++ b/public/shell.php @@ -150,6 +150,7 @@ function logout() { localStorage.removeItem('access_token'); + localStorage.removeItem('user_role'); API.accessToken = null; initApp(); } @@ -170,6 +171,14 @@ // ── Users View ─────────────────────────────────────────── async function renderUsers() { document.getElementById('page-title').textContent = 'إدارة المستخدمين'; + + // Check RBAC + const role = localStorage.getItem('user_role'); + if (role !== 'super_admin' && role !== 'admin') { + contentDiv.innerHTML = `