diff --git a/.adminjs/.entry.js b/.adminjs/.entry.js new file mode 100644 index 0000000..c9edeb9 --- /dev/null +++ b/.adminjs/.entry.js @@ -0,0 +1 @@ +AdminJS.UserComponents = {} diff --git a/src/migrations/1793536838991-QuestionTestId.ts b/src/migrations/1793536838991-QuestionTestId.ts new file mode 100644 index 0000000..fa934f5 --- /dev/null +++ b/src/migrations/1793536838991-QuestionTestId.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class QuestionTestId1793536838991 implements MigrationInterface { + name = 'QuestionTestId1793536838991' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "question" DROP CONSTRAINT "FK_2c8f911efa2fb5b0fe1abe92020"`); + await queryRunner.query(`DROP INDEX "public"."UNQ_TEST_ORDER_IDX"`); + await queryRunner.query(`ALTER TABLE "question" ALTER COLUMN "testId" SET NOT NULL`); + await queryRunner.query(`CREATE UNIQUE INDEX "UNQ_TEST_ORDER_IDX" ON "question" ("testId", "order") `); + await queryRunner.query(`ALTER TABLE "question" ADD CONSTRAINT "FK_2c8f911efa2fb5b0fe1abe92020" FOREIGN KEY ("testId") REFERENCES "test"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "question" DROP CONSTRAINT "FK_2c8f911efa2fb5b0fe1abe92020"`); + await queryRunner.query(`DROP INDEX "public"."UNQ_TEST_ORDER_IDX"`); + await queryRunner.query(`ALTER TABLE "question" ALTER COLUMN "testId" DROP NOT NULL`); + await queryRunner.query(`CREATE UNIQUE INDEX "UNQ_TEST_ORDER_IDX" ON "question" ("order", "testId") `); + await queryRunner.query(`ALTER TABLE "question" ADD CONSTRAINT "FK_2c8f911efa2fb5b0fe1abe92020" FOREIGN KEY ("testId") REFERENCES "test"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + } + +} diff --git a/src/modules/admin-panel/admin-panel.setup.ts b/src/modules/admin-panel/admin-panel.setup.ts index 4fce2bb..e46f628 100644 --- a/src/modules/admin-panel/admin-panel.setup.ts +++ b/src/modules/admin-panel/admin-panel.setup.ts @@ -9,6 +9,7 @@ import { User } from '@/modules/users/entities/user.entity'; import { RedisService } from '@/common/modules/redis/providers/redis.service'; import { AdminPanelAuthenticator } from './providers/admin-panel-auth.provider'; import { AdminPanelSessionStore } from './admin-panel-session.store'; +import fa from './locales/fa'; /** * AdminJS panel bootstrap. @@ -85,9 +86,14 @@ export class AdminPanelSetup { const adminJs = new AdminJS({ rootPath: configService.get('admin.rootPath'), + locale: { + language: 'fa', + translations: fa, + }, branding: { - companyName: 'Heala Admin', + companyName: 'پنل ادمین هیلا', withMadeWithLove: false, + logo: false, }, resources: [ ...autoResources, diff --git a/src/modules/admin-panel/constants/index.ts b/src/modules/admin-panel/constants/index.ts new file mode 100644 index 0000000..13e382d --- /dev/null +++ b/src/modules/admin-panel/constants/index.ts @@ -0,0 +1,4 @@ +export const MAX_FAILED_ATTEMPTS = 5; +export const ATTEMPT_WINDOW_SECONDS = 15 * 60; +export const DUMMY_BCRYPT_HASH = + '$2b$10$ZFUmcSvMhrye2p.Dt1J7rOcfEdi.NcDLk3Bf55taT3ed57cAcpiNS'; diff --git a/src/modules/admin-panel/locales/fa.ts b/src/modules/admin-panel/locales/fa.ts new file mode 100644 index 0000000..cbdd6e9 --- /dev/null +++ b/src/modules/admin-panel/locales/fa.ts @@ -0,0 +1,140 @@ +const fa = { + actions: { + new: 'ایجاد', + edit: 'ویرایش', + show: 'مشاهده', + delete: 'حذف', + bulkDelete: 'حذف گروهی', + list: 'فهرست', + search: 'جستجو', + filter: 'فیلتر', + }, + + buttons: { + save: 'ذخیره', + addNewItem: 'افزودن مورد جدید', + filter: 'فیلتر', + applyChanges: 'اعمال تغییرات', + resetFilter: 'پاک کردن فیلترها', + confirmRemovalMany: 'حذف موارد انتخاب‌شده', + logout: 'خروج', + }, + + labels: { + navigation: 'منوی اصلی', + pages: 'صفحات', + selectedRecords: 'موارد انتخاب‌شده', + filters: 'فیلترها', + dashboard: 'داشبورد', + loginWelcome: 'به پنل مدیریت خوش آمدید', + }, + + messages: { + successfullyCreated: 'مورد جدید با موفقیت ایجاد شد.', + successfullyUpdated: 'تغییرات با موفقیت ذخیره شد.', + successfullyDeleted: 'مورد با موفقیت حذف شد.', + successfullyBulkDeleted: 'موارد انتخاب‌شده با موفقیت حذف شدند.', + thereWereValidationErrors: 'لطفاً خطاهای فرم را برطرف کنید.', + noRecords: 'هیچ موردی یافت نشد.', + noRecordsInResource: 'هیچ موردی برای نمایش وجود ندارد.', + confirmDelete: 'آیا از حذف این مورد مطمئن هستید؟', + loginWelcome: 'برای ورود به پنل مدیریت، اطلاعات خود را وارد کنید.', + }, + + properties: {}, + resources: { + User: { + labels: { + User: 'کاربران', + }, + properties: { + id: 'شناسه', + firstName: 'نام', + lastName: 'نام خانوادگی', + phone: 'شماره تلفن', + role: 'نقش', + createdAt: 'تاریخ ایجاد', + updatedAt: 'تاریخ به‌روزرسانی', + password: 'رمز عبور', + }, + }, + OTP: { + labels: { + OTP: 'کد‌های تایید', + }, + properties: { + id: 'شناسه', + phone: 'شماره تلفن', + code: 'کد', + expiresAt: 'تاریخ انقضا', + used: 'استفاده شده', + }, + }, + Choice: { + labels: { + Choice: 'گزینه ها', + }, + properties: { + id: 'شناسه', + text: 'متن', + order: 'ترتیب', + score: 'امتیاز', + questionId: 'شناسه پرسش', + }, + }, + QuestionRangeRule: { + labels: { + QuestionRangeRule: 'قوانین بازه‌ای پرسش‌ها', + }, + }, + QuestionTransition: { + labels: { + QuestionTransition: 'مسیر‌ پرسش‌ها', + }, + }, + Question: { + labels: { + Question: 'پرسش‌ها', + }, + }, + ResultRange: { + labels: { + ResultRange: 'بازه نتایج آزمایش', + }, + }, + Test: { + labels: { + Test: 'آزمایش', + }, + }, + SubmissionAnswer: { + labels: { + SubmissionAnswer: 'پاسخ‌های ارسالی', + }, + }, + SubmissionResult: { + labels: { + SubmissionResult: 'نتایج آزمایش‌های ارسالی', + }, + }, + Submission: { + labels: { + Submission: 'آزمایش‌های ارسالی', + }, + }, + Message: { + labels: { + Message: 'پیام‌ها', + }, + }, + Conversation: { + labels: { + Conversation: 'مکالمه‌ها', + }, + }, + }, + components: {}, + pages: {}, +}; + +export default fa; diff --git a/src/modules/admin-panel/providers/admin-panel-auth.provider.ts b/src/modules/admin-panel/providers/admin-panel-auth.provider.ts index 66e81b6..0271c13 100644 --- a/src/modules/admin-panel/providers/admin-panel-auth.provider.ts +++ b/src/modules/admin-panel/providers/admin-panel-auth.provider.ts @@ -4,17 +4,11 @@ import { Role } from '@/common/enums/roles.enum'; import { UsersService } from '@/modules/users/providers/users.service'; import { HashingProvider } from '@/common/modules/hashing/providers/hashing.provider'; import { RedisService } from '@/common/modules/redis/providers/redis.service'; - -const MAX_FAILED_ATTEMPTS = 5; -const ATTEMPT_WINDOW_SECONDS = 15 * 60; - -/** - * Hash of a random throwaway string. Comparing against it when the phone - * number is unknown keeps the response time identical to the success path, - * so attackers cannot enumerate superuser phone numbers via timing. - */ -const DUMMY_BCRYPT_HASH = - '$2b$10$ZFUmcSvMhrye2p.Dt1J7rOcfEdi.NcDLk3Bf55taT3ed57cAcpiNS'; +import { + ATTEMPT_WINDOW_SECONDS, + DUMMY_BCRYPT_HASH, + MAX_FAILED_ATTEMPTS, +} from '../constants'; @Injectable() export class AdminPanelAuthenticator { @@ -54,7 +48,8 @@ export class AdminPanelAuthenticator { } const user = await this.usersService.findOneByPhone(normalizedPhone); - const isSuperuser = !!user && user.role === Role.SUPERUSER; + const isSuperuser = + !!user && (user.role === Role.SUPERUSER || user.role === Role.ADMIN); const passwordMatches = await this.hashingProvider.compare( password, diff --git a/src/modules/auth/http/login.post.endpoints.http b/src/modules/auth/http/login.post.endpoints.http index 03c2e40..f56968d 100644 --- a/src/modules/auth/http/login.post.endpoints.http +++ b/src/modules/auth/http/login.post.endpoints.http @@ -3,8 +3,8 @@ Content-Type: application/json lang: fa { - "phone": "09121212123", - "password": "Password1@" + "phone": "09333026363" + // "password": "Password1@" } {{ diff --git a/src/modules/auth/http/verify-otp.post.endpoints.http b/src/modules/auth/http/verify-otp.post.endpoints.http index 5ca602a..0559d7a 100644 --- a/src/modules/auth/http/verify-otp.post.endpoints.http +++ b/src/modules/auth/http/verify-otp.post.endpoints.http @@ -2,8 +2,8 @@ POST {{baseUrl}}/auth/verify-otp Content-Type: application/json { - "phone": "09121212123", - "otp": "71288" + "phone": "09333026363", + "otp": "92608" } {{ diff --git a/src/modules/questions/entities/question.entity.ts b/src/modules/questions/entities/question.entity.ts index ec57e8c..089e908 100644 --- a/src/modules/questions/entities/question.entity.ts +++ b/src/modules/questions/entities/question.entity.ts @@ -8,6 +8,7 @@ import { OneToMany, PrimaryGeneratedColumn, BaseEntity, + JoinColumn, } from 'typeorm'; import { QuestionType } from '../enums/question-type.enum'; import type { QuestionMetadata } from '../types/question-metadata.type'; @@ -22,9 +23,17 @@ export class Question extends BaseEntity { @PrimaryGeneratedColumn() id!: number; + @Column({ + type: 'int', + name: 'testId', + nullable: false, + }) + testId!: number; + @ManyToOne(() => Test, (test) => test.questions, { onDelete: 'CASCADE', }) + @JoinColumn({ name: 'testId' }) test!: Test; @Column({ diff --git a/src/modules/users/http/users.patch.endpoints.http b/src/modules/users/http/users.patch.endpoints.http index 7159012..a54a5c7 100644 --- a/src/modules/users/http/users.patch.endpoints.http +++ b/src/modules/users/http/users.patch.endpoints.http @@ -4,8 +4,8 @@ Authorization: Bearer {{$global.accessToken}} lang: fa { - "firstName": "تست", - "lastName": "تستعلی", + "firstName": "Radmehr", + "lastName": "Tarnas", "password": "Password1@", "confirmPassword": "Password1@" } \ No newline at end of file