forked from Yara724/api
fix: harden profile updates and localize public errors in Persian
Preserve actor and user profile fields during partial updates and validate supported personal data. Add Persian HTTP error handling, validation translations, regression tests, and audit documentation.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
# پیامهای خطای فارسی
|
||||
|
||||
خطاهای قابل نمایش به کاربر در API و دو رابط `ui-user` و `ui-expert` در مرز پاسخ یا نمایش فارسی میشوند. پیامهای استعلام، اعتبارسنجی، ورود، امضا، دسترسی و مراحل پرونده، خطاهای شبکه و دسترسی دوربین/میکروفون پوشش داده شدهاند.
|
||||
|
||||
## رفتار و توسعه
|
||||
|
||||
- `PersianErrorFilter` خطاهای HTTP را فارسی میکند؛ وضعیت HTTP، کد خطا، شناسهها و مسیر فیلدها حفظ میشوند. پیامهای آرایهای اعتبارسنجی همچنان آرایه هستند.
|
||||
- `PersianErrorInterceptor` فقط گرههایی را که صریحاً شکست را مشخص میکنند، در پاسخهای موفق پردازش میکند. گزارشها، دادههای پرونده، پاسخهای موفق و فایلها ترجمه نمیشوند.
|
||||
- برای خطای انگلیسی ناشناخته، پیام فارسی متناسب با وضعیت HTTP نمایش داده میشود. پیامهای شناختهشده راهنمای عملی دقیقتری دارند. خطاهای غیرمنتظره سرور در لاگ ثبت میشوند.
|
||||
- رشتههای داخلی سرویسها که بعضی مسیرها برای تصمیمگیری بررسی میکنند تغییر نکردهاند. برای تصمیمگیری جدید از `code` یا وضعیت HTTP استفاده کنید، نه متن پیام.
|
||||
- `getPersianErrorMessage` در رابطها آرایه پیامها و پاسخهای تودرتو را میخواند. تنظیمات Yup پیش از تعریف schema بارگذاری میشوند و پیامهای پیشفرض فارسی هستند. محدودیتهای بومی مرورگر نیز با حفظ اعتبارسنجی فارسی نمایش داده میشوند و با ویرایش فیلد پاک میشوند.
|
||||
- جدول پیامها و عنوان فیلدها در `src/common/errors/persian-errors.ts` است؛ کپی یکسان آن در `src/utils/persianErrors.ts` دو مخزن رابط نگهداری میشود. تغییرات مشترک باید در هر سه کپی اعمال شوند.
|
||||
- برای خطای کسبوکاری جدید، پیام مشخص فارسی و `code` پایدار تعریف کنید؛ اطلاعات حساس یا پاسخ خام سرویس بیرونی را در پیام کاربر نگذارید.
|
||||
|
||||
## بررسیها
|
||||
|
||||
- تست API: `src/common/errors/persian-errors.spec.ts`، `src/common/utils/inquiry-error.spec.ts` و `src/core/api-route-contract.spec.ts`.
|
||||
- تست رابطها: `npm run test:ui`؛ شامل `scripts/test-error-localization.cjs` برای پیامهای استعلام، Yup، مرورگر، آرایه خطا و حفظ کدها.
|
||||
- بررسی نوعها در هر سه مخزن؛ بررسی واقعی Firefox برای پیامهای اجباری، ایمیل، حداقل عدد و رفع خطا پس از ویرایش.
|
||||
|
||||
API و هر دو رابط را برای پوشش کامل با هم منتشر کنید. این تغییر، اعتبارسنجی سراسری جدیدی فعال نمیکند و قرارداد مسیرها یا مجوز نقشها را تغییر نمیدهد.
|
||||
@@ -0,0 +1,44 @@
|
||||
# Profile panel review — 2026-11-04
|
||||
|
||||
Scope: the regular user account pages, the actor profiles reachable through user flows V2–V6, and the expert panel's account page/editor. This is a profile functionality and accessibility review, not an audit of every application workflow.
|
||||
|
||||
## Plate management
|
||||
|
||||
Profile plate management remains retired. Neither panel exposes saved-plate management. `POST /user/profile/plate` and `DELETE /user/profile/plate/:id` remain absent from the API. Existing historical data is retained; accident inquiry plate entry is a separate capability and remains available.
|
||||
|
||||
## Confirmed problems and fixes
|
||||
|
||||
| Problem | Fix |
|
||||
| --- | --- |
|
||||
| User GET responses omitted saved province/address. | Return `state` and `address` in the public user profile. |
|
||||
| User PATCH returned the pre-update document. | Read and return the saved public profile after updating. |
|
||||
| Birthday format differed between the picker, legacy stored data and documented API. | Read legacy Jalali and Gregorian dates in the UI; submit Gregorian date-only strings. The API accepts legacy packed/separated Jalali input and validates before saving. |
|
||||
| Gender labels were submitted in Persian despite the stored `male`/`female` contract. | Normalize gender while preserving Persian UI labels. |
|
||||
| User-panel experts were offered birthday/gender fields unsupported by their profile storage. | Show supported actor name/contact/location fields instead. |
|
||||
| File makers, file reviewers and call-center agents could read profiles but not save their personal details. Field experts could not save their location. | Support personal profile updates for all corresponding actor roles. |
|
||||
| Insurer profile lookup depended on the token username being an email. | Resolve the authenticated insurer account by JWT subject when available. |
|
||||
| Expert editor split names on spaces, discarded later surname words and initialized the landline as empty. | Return explicit first/last names and phone; preserve all existing values. |
|
||||
| Expert location selects did not initialize from the profile and could submit undefined location values. | Bind saved names to form state and load cities for the selected province. Submit only changed fields. |
|
||||
| Province/city lookup failures were silent; stale requests could replace a newer city's options. | Provide recoverable errors and associate requests with the selected province; keep saved values. |
|
||||
| Profile fetch failures looked like empty accounts, and save failures were only logged. | Add loading/error/retry states, retain failed edits, and expose logout even when user profile loading fails. |
|
||||
| The expert edit modal nested buttons around its form and lacked proper dialog focus behavior. | Use the existing Radix dialog, associated input labels and error messages; restore focus to the edit button on close. |
|
||||
| Updating the header name replaced other Redux login properties. | Preserve the existing login state when updating the displayed name. |
|
||||
| Actor PATCH returned the authentication document. | Return the same public profile representation as GET, excluding passwords, OTPs, tokens and internal assignment fields. |
|
||||
|
||||
## Profile API contract
|
||||
|
||||
- `GET/PATCH /user/profile`: authenticated user's personal details only; partial updates supported. Birth dates are Gregorian `YYYY-MM-DD` for new writes. User responses continue to omit saved plates.
|
||||
- `GET/PATCH /actor/profile`: public profile includes explicit `firstName`, `lastName`, `phone`, and `editableFields`. The UI uses `editableFields` to offer only supported controls.
|
||||
- Blame expert, damage expert, field expert, insurer, file maker, file reviewer and call center: name, mobile, landline, province, city and address.
|
||||
- Super admin: first and last names, matching its existing schema.
|
||||
- Legacy registrar: email, matching its existing schema.
|
||||
- Self-profile updates cannot alter role, tenant/branch assignments, national code, password or Fanavaran expert codes. Those management operations retain their separate existing APIs.
|
||||
- Validation is performed in profile services because the application does not enable a global validation pipe. Invalid types, invalid phone numbers/dates and unsupported fields are rejected before writing.
|
||||
|
||||
## Verification
|
||||
|
||||
- Backend regression checks cover each supported actor role, insurer lookup by subject, partial updates, missing accounts, malformed/privileged fields, public responses and user birthday/gender compatibility. Existing authentication-guard and API-route-contract tests are included.
|
||||
- User utility checks cover Gregorian/legacy Jalali dates, Persian digits, multiword names and distinct actor/user PATCH payloads. Existing user UI utility/workflow checks are retained.
|
||||
- Expert profile utility checks cover multiword names, landline preservation, partial changes and role-supported fields.
|
||||
- Local Firefox checks use mocked API data only: regular user save/reopen and failed-save recovery; V2/V3 field expert, V4 file maker, V5 file reviewer and V6 call center profile navigation/save; expert dialog save/reopen/error recovery, mobile overflow, Escape and focus restoration. Desktop and mobile viewport screenshots were inspected.
|
||||
- These checks do not modify production accounts and do not establish that every application page is free of bugs. Physical-device and screen-reader testing remain outside this review.
|
||||
Reference in New Issue
Block a user