🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 15:51

This commit is contained in:
Hamza-Ayed
2026-05-03 15:51:53 +03:00
parent e182faad1d
commit 81a3e5188e
12 changed files with 415 additions and 6060 deletions

View File

@@ -11,6 +11,9 @@ final class UsersController
public function list(Request $request): void
{
if (!in_array($request->user->role, ['admin', 'super_admin'])) {
throw new \App\Core\Exceptions\HttpException("غير مصرح لك بالوصول", "FORBIDDEN", 403);
}
$tenantId = $request->tenantId;
$users = $this->userModel->findAllByTenant($tenantId);
@@ -22,17 +25,19 @@ final class UsersController
public function create(Request $request): void
{
if (!in_array($request->user->role, ['admin', 'super_admin'])) {
throw new \App\Core\Exceptions\HttpException("غير مصرح لك بالوصول", "FORBIDDEN", 403);
}
$tenantId = $request->tenantId;
$data = $request->getBody();
if (empty($data['email']) || empty($data['password']) || empty($data['name']) || empty($data['role'])) {
Response::error('جميع الحقول مطلوبة', 'VALIDATION_ERROR', 422);
return;
throw new \App\Core\Exceptions\HttpException('جميع الحقول مطلوبة', 'VALIDATION_ERROR', 422);
}
if ($this->userModel->findByEmail($data['email'])) {
Response::error('البريد الإلكتروني مستخدم مسبقاً', 'DUPLICATE_EMAIL', 409);
return;
// Fix: Check email uniqueness WITHIN THE TENANT
if ($this->userModel->findByEmail($data['email'], $tenantId)) {
throw new \App\Core\Exceptions\HttpException('البريد الإلكتروني مستخدم مسبقاً في هذه الشركة', 'DUPLICATE_EMAIL', 409);
}
$userId = Uuid::uuid4()->toString();
@@ -57,11 +62,13 @@ final class UsersController
public function update(Request $request, string $id): void
{
if (!in_array($request->user->role, ['admin', 'super_admin'])) {
throw new \App\Core\Exceptions\HttpException("غير مصرح لك بالوصول", "FORBIDDEN", 403);
}
$tenantId = $request->tenantId;
$user = $this->userModel->findById($id, $tenantId);
if (!$user) {
Response::error('المستخدم غير موجود', 'NOT_FOUND', 404);
return;
throw new \App\Core\Exceptions\HttpException('المستخدم غير موجود', 'NOT_FOUND', 404);
}
$data = $request->getBody();
@@ -86,11 +93,13 @@ final class UsersController
public function destroy(Request $request, string $id): void
{
if (!in_array($request->user->role, ['admin', 'super_admin'])) {
throw new \App\Core\Exceptions\HttpException("غير مصرح لك بالوصول", "FORBIDDEN", 403);
}
$tenantId = $request->tenantId;
$user = $this->userModel->findById($id, $tenantId);
if (!$user) {
Response::error('المستخدم غير موجود', 'NOT_FOUND', 404);
return;
throw new \App\Core\Exceptions\HttpException('المستخدم غير موجود', 'NOT_FOUND', 404);
}
if ($user['id'] === $request->user->user_id) {