diff --git a/.github/workflows/trivy-db.yml b/.github/workflows/trivy-db.yml index 70873dc9..7a501559 100644 --- a/.github/workflows/trivy-db.yml +++ b/.github/workflows/trivy-db.yml @@ -34,7 +34,7 @@ jobs: - name: Run Trivy on Postgres image uses: aquasecurity/trivy-action@master with: - image-ref: "postgres:15.5-alpine" + image-ref: "postgres:15.6-alpine" format: sarif output: "postgres-trivy-results.sarif" severity: "CRITICAL,HIGH" diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 46cdb5e2..d6396aef 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ variables: value: rapportnav-v2 description: "Nom du projet à déployer" BDD_IAMGE: - value: postgres:15.5-alpine + value: postgres:15.6-alpine description: "Image de la base de données" PROJECT_VERSION: value: "1.1.0" diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/RapportNavApplication.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/RapportNavApplication.kt index 1aa00cd0..315aa61f 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/RapportNavApplication.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/RapportNavApplication.kt @@ -20,7 +20,10 @@ fun main(args: Array) { if (isSentryEnabled == "true") { Sentry.init { options -> options.dsn = sentryDsn - options.proxy = SentryOptions.Proxy("172.27.229.197", "8090") + options.proxy = SentryOptions.Proxy( + ctx.environment.getProperty("sentry.proxy.host"), + ctx.environment.getProperty("sentry.proxy.port") + ) options.tracesSampleRate = 1.0 } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/env/envActions/EnvActionEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/env/envActions/EnvActionEntity.kt index eb5c21cf..8d79658f 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/env/envActions/EnvActionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/env/envActions/EnvActionEntity.kt @@ -1,6 +1,5 @@ package fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions -import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonSubTypes import com.fasterxml.jackson.annotation.JsonTypeInfo import com.fasterxml.jackson.databind.annotation.JsonDeserialize @@ -21,15 +20,15 @@ import java.util.* JsonSubTypes.Type(EnvActionNoteEntity::class, name = "NOTE"), ) abstract class EnvActionEntity( - open val id: UUID, - open val actionType: ActionTypeEnum, - open val actionStartDateTimeUtc: ZonedDateTime? = null, - open val actionEndDateTimeUtc: ZonedDateTime? = null, - open val department: String? = null, - open val facade: String? = null, - @JsonDeserialize(using = GeometryDeserializer::class) open val geom: Geometry? = null, - open val isAdministrativeControl: Boolean? = null, - open val isComplianceWithWaterRegulationsControl: Boolean? = null, - open val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null, - open val isSeafarersControl: Boolean? = null, + open val id: UUID, + open val actionType: ActionTypeEnum, + open val actionStartDateTimeUtc: ZonedDateTime? = null, + open val actionEndDateTimeUtc: ZonedDateTime? = null, + open val department: String? = null, + open val facade: String? = null, + @JsonDeserialize(using = GeometryDeserializer::class) open val geom: Geometry? = null, + open val isAdministrativeControl: Boolean? = null, + open val isComplianceWithWaterRegulationsControl: Boolean? = null, + open val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null, + open val isSeafarersControl: Boolean? = null, ) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/AttachControlsToActionControl.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/AttachControlsToActionControl.kt index 8a44b3d0..78e0e1f0 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/AttachControlsToActionControl.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/AttachControlsToActionControl.kt @@ -14,16 +14,16 @@ class AttachControlsToActionControl( actionId: String?, action: ExtendedFishActionEntity ): ExtendedFishActionEntity { - if (actionId != null && action != null) { - action?.controlAction?.controlAdministrative = + if (actionId != null) { + action.controlAction?.controlAdministrative = getControlByActionId.getControlAdministrative(actionControlId = actionId) - action?.controlAction?.controlSecurity = + action.controlAction?.controlSecurity = getControlByActionId.getControlSecurity(actionControlId = actionId) - action?.controlAction?.controlNavigation = + action.controlAction?.controlNavigation = getControlByActionId.getControlNavigation( actionControlId = actionId ) - action?.controlAction?.controlGensDeMer = + action.controlAction?.controlGensDeMer = getControlByActionId.getControlGensDeMer(actionControlId = actionId) return action @@ -36,15 +36,15 @@ class AttachControlsToActionControl( action: ExtendedEnvActionEntity ): ExtendedEnvActionEntity { if (actionId != null) { - action?.controlAction?.controlAdministrative = + action.controlAction?.controlAdministrative = getControlByActionId.getControlAdministrative(actionControlId = actionId) - action?.controlAction?.controlSecurity = + action.controlAction?.controlSecurity = getControlByActionId.getControlSecurity(actionControlId = actionId) - action?.controlAction?.controlNavigation = + action.controlAction?.controlNavigation = getControlByActionId.getControlNavigation( actionControlId = actionId ) - action?.controlAction?.controlGensDeMer = + action.controlAction?.controlGensDeMer = getControlByActionId.getControlGensDeMer(actionControlId = actionId) return action diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/GetNavActionByIdAndMissionId.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/GetNavActionByIdAndMissionId.kt index c9fb96b8..fecb7b0b 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/GetNavActionByIdAndMissionId.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/GetNavActionByIdAndMissionId.kt @@ -25,7 +25,7 @@ class GetNavActionByIdAndMissionId( attachControlsToActionControl.toNavAction( actionId = id.toString(), action = actionControl - )?.toNavAction() + ).toNavAction() } } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/AddOrUpdateControl.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/AddOrUpdateControl.kt index 120adb0f..c1412ad1 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/AddOrUpdateControl.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/AddOrUpdateControl.kt @@ -22,7 +22,7 @@ class AddOrUpdateControl( fun addOrUpdateControlAdministrative(control: ControlAdministrativeEntity): ControlAdministrativeEntity { val existingControl = getControlByActionId.getControlAdministrative(control.actionControlId) - var controlToSave: ControlAdministrativeEntity? = null + var controlToSave: ControlAdministrativeEntity? if (existingControl != null) { controlToSave = control controlToSave.id = existingControl.id @@ -35,7 +35,7 @@ class AddOrUpdateControl( fun addOrUpdateControlSecurity(control: ControlSecurityEntity): ControlSecurityEntity { val existingControl = getControlByActionId.getControlSecurity(control.actionControlId) - var controlToSave: ControlSecurityEntity? = null + var controlToSave: ControlSecurityEntity? if (existingControl != null) { controlToSave = control controlToSave.id = existingControl.id @@ -48,7 +48,7 @@ class AddOrUpdateControl( fun addOrUpdateControlNavigation(control: ControlNavigationEntity): ControlNavigationEntity { val existingControl = getControlByActionId.getControlNavigation(control.actionControlId) - var controlToSave: ControlNavigationEntity? = null + var controlToSave: ControlNavigationEntity? if (existingControl != null) { controlToSave = control controlToSave.id = existingControl.id @@ -61,7 +61,7 @@ class AddOrUpdateControl( fun addOrUpdateControlGensDeMer(control: ControlGensDeMerEntity): ControlGensDeMerEntity { val existingControl = getControlByActionId.getControlGensDeMer(control.actionControlId) - var controlToSave: ControlGensDeMerEntity? = null + var controlToSave: ControlGensDeMerEntity? if (existingControl != null) { controlToSave = control controlToSave.id = existingControl.id diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/AddOrUpdateInfraction.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/AddOrUpdateInfraction.kt index cb3a6e14..a9325663 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/AddOrUpdateInfraction.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/AddOrUpdateInfraction.kt @@ -24,9 +24,9 @@ class AddOrUpdateInfraction( fun execute(infraction: InfractionEntity): InfractionEntity { // create control if it doesn't exist // users might add infractions without having checked a control - if (infraction.controlId != null) { + return if (infraction.controlId != null) { val savedData = infractionRepo.save(infraction).toInfractionEntity() - return savedData + savedData } else { // Check if any of the controls already exist val existingControl = @@ -74,7 +74,7 @@ class AddOrUpdateInfraction( if (newControl != null) { // save the control - val control = when (infraction.controlType) { + when (infraction.controlType) { ControlType.ADMINISTRATIVE -> controlAdministrativeRepo.save(newControl as ControlAdministrativeEntity) ControlType.SECURITY -> controlSecurityRepo.save(newControl as ControlSecurityEntity) ControlType.NAVIGATION -> controlNavigationRepo.save(newControl as ControlNavigationEntity) @@ -89,7 +89,7 @@ class AddOrUpdateInfraction( val savedData = infractionRepo.save(infraction).toInfractionEntity() - return savedData + savedData } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/GetInfractionById.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/GetInfractionById.kt index 369f6e1e..dc5df43c 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/GetInfractionById.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/GetInfractionById.kt @@ -9,10 +9,10 @@ import java.util.* class GetInfractionById(private val repo: IInfractionRepository) { fun execute(id: UUID): InfractionEntity? { val infractionModel = repo.findById(id) - if (infractionModel.isPresent) { - return infractionModel.get().toInfractionEntity() + return if (infractionModel.isPresent) { + infractionModel.get().toInfractionEntity() } else { - return null + null } } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/ActionController.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/ActionController.kt index 98efaf97..75591deb 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/ActionController.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/ActionController.kt @@ -62,7 +62,7 @@ class ActionController( } else if (id in fakeMissionData.getFishActionIds()) { val fakeAction = getFishActionsByMissionId.getFakeActions(missionId) - .first { it -> it.controlAction?.action?.id.toString() == id } + .first { it.controlAction?.action?.id.toString() == id } return Action.fromFishAction( fishAction = fakeAction, missionId = missionId @@ -145,10 +145,8 @@ class ActionController( fun getActionStatus(action: Action): ActionStatusType { // if already a status action - no need to recompute - if (action.source == MissionSourceEnum.RAPPORTNAV) { - if (action.data is NavActionStatus) { - return action.data.status - } + if (action.source == MissionSourceEnum.RAPPORTNAV && action.data is NavActionStatus) { + return action.data.status } // get last started status for this time and missionId @@ -273,7 +271,7 @@ class ActionController( } } val withReportCountNatinf = - allNatinfs?.count { it != null } + allNatinfs?.count { true } val natinfTag = if (withReportCountNatinf == 0) { "Sans infraction" diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/MissionController.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/MissionController.kt index f4c625f5..e97b7e51 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/MissionController.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/MissionController.kt @@ -62,24 +62,24 @@ class MissionController( @QueryMapping fun mission(@Argument missionId: Int): Mission? { - if (missionId in fakeMissionData.getEmptyMissionIds()) { + return if (missionId in fakeMissionData.getEmptyMissionIds()) { var fakeMission = fakeMissionData.emptyMission(missionId) val navMission = getNavMissionById.execute(missionId = missionId) fakeMission.actions = fakeMission.actions?.plus(navMission.actions.map { MissionActionEntity.NavAction(it) }) - return Mission.fromMissionEntity(fakeMission) + Mission.fromMissionEntity(fakeMission) } else if (missionId in fakeMissionData.getFullMissionIds()) { val fakeMission = fakeMissionData.fullMission(missionId) val navMission = getNavMissionById.execute(missionId = missionId) fakeMission.actions = fakeMission.actions?.plus(navMission.actions.map { MissionActionEntity.NavAction(it) }) - return Mission.fromMissionEntity(fakeMission) + Mission.fromMissionEntity(fakeMission) } else { val envMission = getEnvMissionById.execute(missionId = missionId) ?: return null val fishMissionActions = getFishActionsByMissionId.execute(missionId = missionId) val navMission = getNavMissionById.execute(missionId = missionId) - return Mission.fromMissionEntity(MissionEntity(envMission, navMission, fishMissionActions)) + Mission.fromMissionEntity(MissionEntity(envMission, navMission, fishMissionActions)) } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/model/Mission.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/model/Mission.kt index 438ab692..4e06afb2 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/model/Mission.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/model/Mission.kt @@ -15,17 +15,6 @@ data class Mission( val actions: List?, val openBy: String? = null, ) { -// fun fromMissionEntity(mission: MissionEntity): Mission { -// return Mission( -// id = mission.id, -// isClosed = mission.isClosed, -// missionSource = mission.missionSource, -// startDateTimeUtc = mission.startDateTimeUtc, -// endDateTimeUtc = mission.endDateTimeUtc, -// actions = mission.actions -// ) -// } - companion object { fun fromMissionEntity(mission: MissionEntity): Mission { val actions: List? = mission.actions?.mapNotNull { missionAction -> diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/model/action/Action.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/model/action/Action.kt index 22748517..cb71a143 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/model/action/Action.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/bff/model/action/Action.kt @@ -24,8 +24,8 @@ data class Action( companion object { fun fromEnvAction(envAction: ExtendedEnvActionEntity? = null, missionId: Int): Action? { - if (envAction?.controlAction?.action != null) { - return Action( + return envAction?.controlAction?.action?.let { + Action( id = envAction.controlAction.action.id, missionId = missionId, source = MissionSourceEnum.MONITORENV, @@ -36,7 +36,7 @@ data class Action( id = envAction.controlAction.action.id, actionStartDateTimeUtc = it, actionEndDateTimeUtc = envAction.controlAction.action.actionEndDateTimeUtc, - actionType = envAction.controlAction.action.actionType!!, + actionType = envAction.controlAction.action.actionType, geom = envAction.controlAction.action.geom, observations = envAction.controlAction.action.observations, actionNumberOfControls = envAction.controlAction.action.actionNumberOfControls, @@ -55,14 +55,12 @@ data class Action( ) } ) - } else { - return null } } fun fromFishAction(fishAction: ExtendedFishActionEntity, missionId: Int): Action? { - if (fishAction?.controlAction?.action != null) { - val action = fishAction?.controlAction?.action + return fishAction.controlAction?.action?.let { + val action = fishAction.controlAction?.action return Action( id = action.id.toString(), missionId = missionId, @@ -122,26 +120,30 @@ data class Action( isSafetyEquipmentAndStandardsComplianceControl = action.isSafetyEquipmentAndStandardsComplianceControl, isSeafarersControl = action.isSeafarersControl, // controls - controlAdministrative = ControlAdministrative.fromControlAdministrativeEntity(fishAction?.controlAction?.controlAdministrative), - controlNavigation = ControlNavigation.fromControlNavigationEntity(fishAction?.controlAction?.controlNavigation), - controlSecurity = ControlSecurity.fromControlSecurityEntity(fishAction?.controlAction?.controlSecurity), - controlGensDeMer = ControlGensDeMer.fromControlGensDeMerEntity(fishAction?.controlAction?.controlGensDeMer), + controlAdministrative = ControlAdministrative.fromControlAdministrativeEntity(fishAction.controlAction?.controlAdministrative), + controlNavigation = ControlNavigation.fromControlNavigationEntity(fishAction.controlAction?.controlNavigation), + controlSecurity = ControlSecurity.fromControlSecurityEntity(fishAction.controlAction?.controlSecurity), + controlGensDeMer = ControlGensDeMer.fromControlGensDeMerEntity(fishAction.controlAction?.controlGensDeMer), ) ) - } else { - return null } } fun fromNavAction(navAction: NavActionEntity): Action? { var data: ActionData? = null - if (navAction.statusAction != null) { - data = navAction.statusAction.toNavActionStatus() - } else if (navAction.controlAction != null) { - data = navAction.controlAction.toNavActionControl() - } else if (navAction.freeNoteAction != null) { - data = navAction.freeNoteAction.toNavActionFreeNote() + when { + navAction.statusAction != null -> { + data = navAction.statusAction.toNavActionStatus() + } + + navAction.controlAction != null -> { + data = navAction.controlAction.toNavActionControl() + } + + navAction.freeNoteAction != null -> { + data = navAction.freeNoteAction.toNavActionFreeNote() + } } return Action( id = navAction.id, diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/model/mission/infraction/InfractionEnvTargetModel.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/model/mission/infraction/InfractionEnvTargetModel.kt index ef01a86a..733d2d19 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/model/mission/infraction/InfractionEnvTargetModel.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/model/mission/infraction/InfractionEnvTargetModel.kt @@ -62,7 +62,7 @@ data class InfractionEnvTargetModel( id = infractionTarget.id, missionId = infractionTarget.missionId, actionId = infractionTarget.actionId, - infraction = infraction?.let { it -> InfractionModel.fromInfractionEntity(it) }, + infraction = infraction?.let { InfractionModel.fromInfractionEntity(it) }, vesselIdentifier = infractionTarget.vesselIdentifier, identityControlledPerson = infractionTarget.identityControlledPerson, vesselType = infractionTarget.vesselType.toString(), diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/repositories/user/JPAUserRepository.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/repositories/user/JPAUserRepository.kt index 1da9e729..b84d0b19 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/repositories/user/JPAUserRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/repositories/user/JPAUserRepository.kt @@ -27,7 +27,6 @@ class JPAUserRepository( @Transactional override fun save(user: User): User? { return try { -// user.setPassword(user.password) val userModel = UserModel.fromUser(user, mapper) dbUserRepository.save(userModel).toUser(mapper) } catch (e: InvalidDataAccessApiUsageException) { diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/monitorfish/APIFishActionRepositoryEnv.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/monitorfish/APIFishActionRepositoryEnv.kt index 455fefe0..b523fbcf 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/monitorfish/APIFishActionRepositoryEnv.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/monitorfish/APIFishActionRepositoryEnv.kt @@ -30,13 +30,12 @@ class APIFishActionRepositoryEnv( val response = client.send(request, HttpResponse.BodyHandlers.ofString()) - if (response.statusCode() in 200..299) { + return if (response.statusCode() in 200..299) { mapper.registerModule(JtsModule()) - val fishActions = mapper.readValue(response.body(), object : TypeReference>() {}) - return fishActions + mapper.readValue(response.body(), object : TypeReference>() {}) } else { logger.info("Failed to fetch data. Status code: ${response.statusCode()}") - return listOf() + emptyList() } } } diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/AbstractDBTests.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/AbstractDBTests.kt index d9a644d0..7c5f3c6f 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/AbstractDBTests.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/AbstractDBTests.kt @@ -19,7 +19,7 @@ abstract class AbstractDBTests { companion object { @JvmStatic - val container = PostgreSQLContainer("postgres:15.5-alpine") + val container = PostgreSQLContainer("postgres:15.6-alpine") .apply { withExposedPorts(5432) withEnv("POSTGRES_DB", "testdb") diff --git a/docker-compose.yml b/docker-compose.yml index d4687600..9d58534d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services: # - backend-network db: - image: postgres:15.5-alpine + image: postgres:15.6-alpine ports: - "5432:5432" environment: diff --git a/docker-compose.yml.j2 b/docker-compose.yml.j2 index 07a089e1..2197d0ff 100644 --- a/docker-compose.yml.j2 +++ b/docker-compose.yml.j2 @@ -26,7 +26,7 @@ services: max-size: "1024m" db: - image: "{{ nexus_proxy }}/postgres:15.5-alpine" + image: "{{ nexus_proxy }}/postgres:15.6-alpine" volumes: # - "${RAPPORTNAV_BACKUPS_FOLDER}:/opt/rapportnav_backups" - db:/var/lib/postgresql/data diff --git a/frontend/src/auth/csrf.test.ts b/frontend/src/auth/csrf.test.ts new file mode 100644 index 00000000..bc43c563 --- /dev/null +++ b/frontend/src/auth/csrf.test.ts @@ -0,0 +1,44 @@ +import { csrfToken } from './csrf'; + +describe('csrfToken', () => { + // Mocking document.cookie for testing + const originalDocumentCookie = document.cookie; + beforeAll(() => { + Object.defineProperty(document, 'cookie', { + writable: true, + value: 'XSRF-TOKEN=abc123; other_cookie=def456', + }); + }); + + afterAll(() => { + document.cookie = originalDocumentCookie; + }); + + it('should return the CSRF token if it exists in the cookie', () => { + expect(csrfToken()).toEqual('abc123'); + }); + + it('should return null if the CSRF token does not exist in the cookie', () => { + // Simulate empty cookie + document.cookie = ''; + expect(csrfToken()).toBeNull(); + }); + + it('should return null if the CSRF token is not found in the cookie', () => { + // Simulate cookie without XSRF-TOKEN + document.cookie = 'other_cookie=def456'; + expect(csrfToken()).toBeNull(); + }); + + it('should return the CSRF token even if there are other cookies in the string', () => { + // Simulate cookie with multiple cookies + document.cookie = 'XSRF-TOKEN=abc123; other_cookie=def456'; + expect(csrfToken()).toEqual('abc123'); + }); + + it('should return the CSRF token if it has special characters', () => { + // Simulate cookie with special characters in the token + document.cookie = 'XSRF-TOKEN=ab!c_12*3; other_cookie=def456'; + expect(csrfToken()).toEqual('ab!c_12*3'); + }); +}); diff --git a/frontend/src/auth/csrf.ts b/frontend/src/auth/csrf.ts index a7658529..14d2f8a1 100644 --- a/frontend/src/auth/csrf.ts +++ b/frontend/src/auth/csrf.ts @@ -1,2 +1,4 @@ -export const csrfToken = (): string | null => - document.cookie.replace(/(?:(?:^|.*;\s*)XSRF-TOKEN\s*=\s*([^;]*).*$)|^.*$/, '$1') +export const csrfToken = (): string | null => { + const match = /XSRF-TOKEN=([^;]*)/.exec(document.cookie); + return match ? match[1] : null; +} diff --git a/frontend/src/pam/mission/timeline/timeline.tsx b/frontend/src/pam/mission/timeline/timeline.tsx index a5848b66..74989d08 100644 --- a/frontend/src/pam/mission/timeline/timeline.tsx +++ b/frontend/src/pam/mission/timeline/timeline.tsx @@ -13,143 +13,143 @@ import useGetMissionTimeline from "./use-mission-timeline.tsx"; import { find } from "lodash"; interface MissionTimelineProps { - missionId?: string - onSelectAction: (action: Action) => void + missionId?: string + onSelectAction: (action: Action) => void } const MissionTimeline: React.FC = ({missionId, onSelectAction}) => { - const {data: mission, loading, error} = useGetMissionTimeline(missionId) + const {data: mission, loading, error} = useGetMissionTimeline(missionId) - if (error) { - return ( - - - - Une erreur s'est produite lors du chargement de la timeline.
- Si le problème persiste, veuillez contacter l'équipe RapportNav. -
- - Erreur: {error.message} - -
-
- ) - } + if (error) { + return ( + + + + Une erreur s'est produite lors du chargement de la timeline.
+ Si le problème persiste, veuillez contacter l'équipe RapportNav. +
+ + Erreur: {error.message} + +
+
+ ) + } - if (loading) { - return ( - - - - - - ) - } + if (loading) { + return ( + + + + + + ) + } - if (mission && !!!mission.actions?.length) { - return ( - - - - Aucune action n'est ajoutée pour le moment - - - - ) - } + if (mission && !!!mission.actions?.length) { + return ( + + + + Aucune action n'est ajoutée pour le moment + + + + ) + } - if (mission) { - return ( -
- - - - {Object.entries(groupByDay(mission.actions, 'startDateTimeUtc')).map(([day, actions], index) => ( - - {/* Render Divider if it's not the first day */} - {index !== 0 && ( - - -
- - )} + if (mission) { + return ( +
+ + + + {Object.entries(groupByDay(mission.actions, 'startDateTimeUtc')).map(([day, actions], index) => ( + + {/* Render Divider if it's not the first day */} + {index !== 0 && ( + + +
+ + )} - - - {/* Render actions for the day */} - {(actions as Action[]).map((action: Action) => { - return ( - - - - - - - {formatShortDate(action.startDateTimeUtc)} - - - - - à {formatTime(action.startDateTimeUtc)} - - - - - - - item === action) + 1 - )} - onClick={() => onSelectAction(action)}/> - - - {action.type !== ActionTypeEnum.STATUS && ( - -
-   -
-
- )} -
-
- ) - })} -
-
- - ))} - - - -
- ) - } + + + {/* Render actions for the day */} + {(actions as Action[]).map((action: Action) => { + return ( + + + + + + + {formatShortDate(action.startDateTimeUtc)} + + + + + à {formatTime(action.startDateTimeUtc)} + + + + + + + item === action) + 1 + )} + onClick={() => onSelectAction(action)}/> + + + {action.type !== ActionTypeEnum.STATUS && ( + +
+   +
+
+ )} +
+
+ ) + })} +
+
+
+ ))} +
+
+
+
+ ) + } } diff --git a/infra/docker-compose.dev.yml b/infra/docker-compose.dev.yml index 16f46572..88c04548 100644 --- a/infra/docker-compose.dev.yml +++ b/infra/docker-compose.dev.yml @@ -1,7 +1,7 @@ version: "3" services: db: - image: postgres:15.5-alpine + image: postgres:15.6-alpine ports: - "5432:5432" environment: diff --git a/infra/docker-compose.prod.yml b/infra/docker-compose.prod.yml index fe2b035f..78f251fa 100644 --- a/infra/docker-compose.prod.yml +++ b/infra/docker-compose.prod.yml @@ -24,7 +24,7 @@ services: max-size: "1024m" db: - image: postgres:15.5-alpine + image: postgres:15.6-alpine volumes: - "${RAPPORTNAV_BACKUPS_FOLDER}:/opt/rapportnav_backups" - db:/var/lib/postgresql/data diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index 12117505..2481d967 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -14,7 +14,7 @@ services: - db db: - image: postgres:15.5-alpine + image: postgres:15.6-alpine ports: - "5432:5432" environment: