From be58aba8d1a36246cc015add225ce33c75536d5d Mon Sep 17 00:00:00 2001 From: "Yassine R." Date: Wed, 30 Oct 2024 18:17:29 +0100 Subject: [PATCH] fix(backend): fix role for doc download --- packages/backend/src/auth/auth.module.ts | 2 +- .../auth/guards/usager-doc-access.guard.ts | 2 +- .../services/structures-auth.service.spec.ts | 2 +- .../services/admins-auth.service.spec.ts | 2 +- .../portail-usagers-profile.controller.ts | 2 +- .../services/usagers-auth.service.spec.ts | 2 +- .../src/app/interceptors/jwt.interceptor.ts | 2 +- .../components/button/button.component.html | 19 ++----------------- .../components/button/button.component.ts | 1 - .../components/upload/upload.component.ts | 7 ++++++- packages/frontend/src/assets/css/main.scss | 1 + .../section-docs.component.spec.ts | 9 ++++++++- .../services/usager-doc.service.spec.ts | 3 ++- 13 files changed, 26 insertions(+), 28 deletions(-) diff --git a/packages/backend/src/auth/auth.module.ts b/packages/backend/src/auth/auth.module.ts index ab9a1a2d8d..29a9475a91 100644 --- a/packages/backend/src/auth/auth.module.ts +++ b/packages/backend/src/auth/auth.module.ts @@ -26,7 +26,7 @@ import { StructuresAuthController } from "./structures-auth.controller"; JwtModule.register({ secret: domifaConfig().security.jwtSecret, signOptions: { - expiresIn: "24h", + expiresIn: "12h", }, }) ), diff --git a/packages/backend/src/auth/guards/usager-doc-access.guard.ts b/packages/backend/src/auth/guards/usager-doc-access.guard.ts index be8cda8da1..41201614f7 100644 --- a/packages/backend/src/auth/guards/usager-doc-access.guard.ts +++ b/packages/backend/src/auth/guards/usager-doc-access.guard.ts @@ -18,7 +18,7 @@ export class UsagerDocAccessGuard implements CanActivate { const user = request?.user as UserStructureAuthenticated; if ( - user?.role === "simple" || + user?.role === "facteur" || !isUUID(request.params.docUuid) || !isNumber(user?.structureId) ) { diff --git a/packages/backend/src/auth/services/structures-auth.service.spec.ts b/packages/backend/src/auth/services/structures-auth.service.spec.ts index 8a5ce3cc3a..0d0f3ccb2f 100644 --- a/packages/backend/src/auth/services/structures-auth.service.spec.ts +++ b/packages/backend/src/auth/services/structures-auth.service.spec.ts @@ -15,7 +15,7 @@ describe("StructuresAuthService", () => { JwtModule.register({ secretOrPrivateKey: "secretKey", signOptions: { - expiresIn: 3600, + expiresIn: "12h", }, }), UsersModule, diff --git a/packages/backend/src/modules/portail-admin/services/admins-auth.service.spec.ts b/packages/backend/src/modules/portail-admin/services/admins-auth.service.spec.ts index a84e984110..c08164c8ad 100644 --- a/packages/backend/src/modules/portail-admin/services/admins-auth.service.spec.ts +++ b/packages/backend/src/modules/portail-admin/services/admins-auth.service.spec.ts @@ -17,7 +17,7 @@ describe("AdminsAuthService", () => { JwtModule.register({ secretOrPrivateKey: "secretKey", signOptions: { - expiresIn: 3600, + expiresIn: "12h", }, }), UsersModule, diff --git a/packages/backend/src/modules/portail-usagers/controllers/postail-usagers-profile/portail-usagers-profile.controller.ts b/packages/backend/src/modules/portail-usagers/controllers/postail-usagers-profile/portail-usagers-profile.controller.ts index 6ee1928e3f..0a7b01d5b7 100644 --- a/packages/backend/src/modules/portail-usagers/controllers/postail-usagers-profile/portail-usagers-profile.controller.ts +++ b/packages/backend/src/modules/portail-usagers/controllers/postail-usagers-profile/portail-usagers-profile.controller.ts @@ -158,7 +158,7 @@ export class PortailUsagersProfileController { }); try { - return this.fileManagerService.dowloadEncryptedFile( + return await this.fileManagerService.dowloadEncryptedFile( res, currentUser.structure.uuid, currentUser.usager.uuid, diff --git a/packages/backend/src/modules/portail-usagers/services/usagers-auth.service.spec.ts b/packages/backend/src/modules/portail-usagers/services/usagers-auth.service.spec.ts index a6b8ef09e0..cac58b2037 100644 --- a/packages/backend/src/modules/portail-usagers/services/usagers-auth.service.spec.ts +++ b/packages/backend/src/modules/portail-usagers/services/usagers-auth.service.spec.ts @@ -17,7 +17,7 @@ describe("UsagersAuthService", () => { JwtModule.register({ secretOrPrivateKey: "secretKey", signOptions: { - expiresIn: 3600, + expiresIn: "12h", }, }), UsersModule, diff --git a/packages/frontend/src/app/interceptors/jwt.interceptor.ts b/packages/frontend/src/app/interceptors/jwt.interceptor.ts index f2f1802058..d7153a3bf2 100644 --- a/packages/frontend/src/app/interceptors/jwt.interceptor.ts +++ b/packages/frontend/src/app/interceptors/jwt.interceptor.ts @@ -19,7 +19,7 @@ export class JwtInterceptor implements HttpInterceptor { ): Observable> { const currentUser = this.authService.currentUserValue; - if (currentUser && currentUser.access_token) { + if (currentUser?.access_token) { request = request.clone({ setHeaders: { Authorization: `Bearer ${currentUser.access_token}`, diff --git a/packages/frontend/src/app/modules/shared/components/button/button.component.html b/packages/frontend/src/app/modules/shared/components/button/button.component.html index 18baf40def..f0d7e82fea 100644 --- a/packages/frontend/src/app/modules/shared/components/button/button.component.html +++ b/packages/frontend/src/app/modules/shared/components/button/button.component.html @@ -13,9 +13,10 @@ - Patientez... + {{ loadingText }} {{ content }} - - - - {{ loadingText }} - diff --git a/packages/frontend/src/app/modules/shared/components/button/button.component.ts b/packages/frontend/src/app/modules/shared/components/button/button.component.ts index d3c47887b1..4a075fdc85 100644 --- a/packages/frontend/src/app/modules/shared/components/button/button.component.ts +++ b/packages/frontend/src/app/modules/shared/components/button/button.component.ts @@ -13,7 +13,6 @@ export class ButtonComponent { @Input() icon?: IconName; @Input() prefix: IconPrefix = "fas"; @Input() loadingText = "Patientez..."; - @Input() loadingAriaLabel = "Chargement en cours"; @Input() content = ""; @Input() ariaLabel = ""; diff --git a/packages/frontend/src/app/modules/usager-shared/components/upload/upload.component.ts b/packages/frontend/src/app/modules/usager-shared/components/upload/upload.component.ts index eb9b12044b..861070414f 100644 --- a/packages/frontend/src/app/modules/usager-shared/components/upload/upload.component.ts +++ b/packages/frontend/src/app/modules/usager-shared/components/upload/upload.component.ts @@ -58,7 +58,12 @@ export class UploadComponent implements OnInit, OnDestroy { file: ["", [Validators.required]], label: [ "", - [Validators.required, NoWhiteSpaceValidator, Validators.minLength(2)], + [ + Validators.required, + NoWhiteSpaceValidator, + Validators.minLength(2), + Validators.maxLength(100), + ], ], }); } diff --git a/packages/frontend/src/assets/css/main.scss b/packages/frontend/src/assets/css/main.scss index fc78ceaefc..778f512b45 100644 --- a/packages/frontend/src/assets/css/main.scss +++ b/packages/frontend/src/assets/css/main.scss @@ -17,6 +17,7 @@ ul { caption { color: black !important; } + .content { background-color: #f2f2f2; min-height: calc(90vh - 78px); diff --git a/packages/portail-usagers/src/app/modules/usager-account/components/home-usager/sections/section-docs/section-docs.component.spec.ts b/packages/portail-usagers/src/app/modules/usager-account/components/home-usager/sections/section-docs/section-docs.component.spec.ts index 9692cbc675..1173f02b87 100644 --- a/packages/portail-usagers/src/app/modules/usager-account/components/home-usager/sections/section-docs/section-docs.component.spec.ts +++ b/packages/portail-usagers/src/app/modules/usager-account/components/home-usager/sections/section-docs/section-docs.component.spec.ts @@ -1,6 +1,10 @@ import { ComponentFixture, TestBed } from "@angular/core/testing"; import { SectionDocsComponent } from "./section-docs.component"; +import { DEFAULT_USAGER } from "../../../../../../../_common"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; +import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from "@angular/core"; +import { SharedModule } from "../../../../../shared/shared.module"; describe("SectionDocsComponent", () => { let component: SectionDocsComponent; @@ -8,11 +12,14 @@ describe("SectionDocsComponent", () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [SectionDocsComponent], + declarations: [SectionDocsComponent], + imports: [SharedModule, HttpClientTestingModule], + schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA], }).compileComponents(); fixture = TestBed.createComponent(SectionDocsComponent); component = fixture.componentInstance; + component.usager = DEFAULT_USAGER; fixture.detectChanges(); }); diff --git a/packages/portail-usagers/src/app/modules/usager-account/services/usager-doc.service.spec.ts b/packages/portail-usagers/src/app/modules/usager-account/services/usager-doc.service.spec.ts index 76896b7c4f..35890c92d3 100644 --- a/packages/portail-usagers/src/app/modules/usager-account/services/usager-doc.service.spec.ts +++ b/packages/portail-usagers/src/app/modules/usager-account/services/usager-doc.service.spec.ts @@ -1,12 +1,13 @@ import { TestBed } from "@angular/core/testing"; import { UsagerDocService } from "./usager-doc.service"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; describe("UsagerDocService", () => { let service: UsagerDocService; beforeEach(() => { - TestBed.configureTestingModule({}); + TestBed.configureTestingModule({ imports: [HttpClientTestingModule] }); service = TestBed.inject(UsagerDocService); });