Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrige un bug lié à l'ancienne gestion des critères transverses provoquant parfois des écrasements de données #876

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Tous les changements notables de Ara sont documentés ici avec leur date, leur catégorie (nouvelle fonctionnalité, correction de bug ou autre changement) et leur pull request (PR) associée.

## 14/11/2024

### Corrections 🐛

- Corrige un bug lié à l'ancienne gestion des critères transverses provoquant parfois des écrasenements de données ([#876](https://github.com/DISIC/Ara/pull/876))

## 07/11/2024

### Corrections 🐛
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- You are about to drop the column `transverse` on the `CriterionResult` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "CriterionResult" DROP COLUMN "transverse";
44 changes: 21 additions & 23 deletions confiture-rest-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ model Audit {
/// @DtoEntityHidden
pages AuditedPage[] @relation("UserPages")
// single page for transverse elements
transverseElementsPage AuditedPage @relation("TransversePage", fields: [transverseElementsPageId], references: [id])
transverseElementsPageId Int @unique
transverseElementsPage AuditedPage @relation("TransversePage", fields: [transverseElementsPageId], references: [id])
transverseElementsPageId Int @unique
auditorName String?
auditorEmail String?
showAuditorEmailInReport Boolean @default(false)
Expand Down Expand Up @@ -96,11 +96,11 @@ model Audit {
}

model TestEnvironment {
id Int @id @default(autoincrement())
platform String
operatingSystem String
assistiveTechnology String
browser String
id Int @id @default(autoincrement())
platform String
operatingSystem String
assistiveTechnology String
browser String

audit Audit? @relation(fields: [auditUniqueId], references: [editUniqueId], onDelete: Cascade)
auditUniqueId String?
Expand All @@ -121,15 +121,13 @@ model AuditedPage {
// parent audit when the page is a transverse page
auditTransverse Audit? @relation(name: "TransversePage")


results CriterionResult[]
}

model CriterionResult {
id Int @id @default(autoincrement())

status CriterionResultStatus @default(NOT_TESTED)
transverse Boolean @default(false)
status CriterionResultStatus @default(NOT_TESTED)

compliantComment String?

Expand Down Expand Up @@ -175,15 +173,15 @@ model StoredFile {
id Int @id @default(autoincrement())
originalFilename String

// The default mimetype set to "image/unknown" to handle existing files
// in the DB (before the property has been added).
// Originally, all files were images.
mimetype String @default("image/unknown")
// The default mimetype set to "image/unknown" to handle existing files
// in the DB (before the property has been added).
// Originally, all files were images.
mimetype String @default("image/unknown")

size Int
size Int

// S3 storage keys
key String
key String
thumbnailKey String

criterionResult CriterionResult? @relation(fields: [criterionResultId], references: [id], onDelete: Cascade, onUpdate: Cascade)
Expand All @@ -194,18 +192,18 @@ model AuditFile {
id Int @id @default(autoincrement())
originalFilename String

// The default mimetype set to "image/unknown" to handle existing files
// in the DB (before the property has been added).
// Originally, all files were images.
mimetype String @default("image/unknown")
// The default mimetype set to "image/unknown" to handle existing files
// in the DB (before the property has been added).
// Originally, all files were images.
mimetype String @default("image/unknown")

size Int
size Int

// S3 storage key
key String
key String
thumbnailKey String?

audit Audit? @relation(fields: [auditUniqueId], references: [editUniqueId], onDelete: Cascade)
audit Audit? @relation(fields: [auditUniqueId], references: [editUniqueId], onDelete: Cascade)
auditUniqueId String?
}

Expand Down
62 changes: 1 addition & 61 deletions confiture-rest-api/src/audits/audit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ export class AuditService {
userImpact: null,
notApplicableComment: null,
exampleImages: [],
transverse: false,
quickWin: false,

topic: criterion.topic,
Expand Down Expand Up @@ -371,10 +370,6 @@ export class AuditService {
}

async updateResults(uniqueId: string, body: UpdateResultsDto) {
const pages = await this.prisma.auditedPage.findMany({
where: { auditUniqueId: uniqueId }
});

const promises = body.data
.map((item) => {
const data: Prisma.CriterionResultUpsertArgs["create"] = {
Expand All @@ -391,19 +386,12 @@ export class AuditService {
notCompliantComment: item.notCompliantComment,
notApplicableComment: item.notApplicableComment,
userImpact: item.userImpact,
quickWin: item.quickWin,
transverse: item.transverse
quickWin: item.quickWin
};

const result = [
this.prisma.criterionResult.upsert({
where: {
// auditUniqueId_pageUrl_topic_criterium: {
// auditUniqueId: uniqueId,
// criterium: item.criterium,
// pageUrl: item.pageUrl,
// topic: item.topic,
// },
pageId_topic_criterium: {
criterium: item.criterium,
topic: item.topic,
Expand All @@ -415,53 +403,6 @@ export class AuditService {
})
];

if (item.transverse) {
pages
.filter((page) => page.id !== item.pageId)
.forEach((page) => {
const data: Prisma.CriterionResultUpsertArgs["create"] = {
criterium: item.criterium,
topic: item.topic,
page: {
connect: {
id: page.id
}
},

status: item.status,
transverse: true,

...(item.status === CriterionResultStatus.COMPLIANT && {
compliantComment: item.compliantComment
}),

...(item.status === CriterionResultStatus.NOT_COMPLIANT && {
notCompliantComment: item.notCompliantComment,
userImpact: item.userImpact,
quickWin: item.quickWin
}),

...(item.status === CriterionResultStatus.NOT_APPLICABLE && {
notApplicableComment: item.notApplicableComment
})
};

result.push(
this.prisma.criterionResult.upsert({
where: {
pageId_topic_criterium: {
criterium: item.criterium,
topic: item.topic,
pageId: page.id
}
},
create: data,
update: data
})
);
});
}

Comment on lines -418 to -464
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce bloc de code avait été oublié lors du passage au nouveau système de critères transverses. Il provoquait des bugs d'écrasement de données avec les critères qui étaient anciennement marqués comme transverses (y compris dans des audits copiés)

return result;
})
.flat();
Expand Down Expand Up @@ -1049,7 +990,6 @@ export class AuditService {
criterium: r.criterium,

status: r.status,
transverse: r.transverse,

compliantComment: r.compliantComment,
notCompliantComment: r.notCompliantComment,
Expand Down
2 changes: 0 additions & 2 deletions confiture-rest-api/src/audits/dto/audit-report.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ class ReportCriterionResult {
@ApiProperty({ enum: CriterionResultStatus })
status: CriterionResultStatus;

transverse: boolean;

compliantComment: string | null;

/**
Expand Down
7 changes: 0 additions & 7 deletions confiture-rest-api/src/audits/dto/update-results.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ class UpdateResultsItem {
@IsIn(Object.values(CriterionResultStatus))
status: CriterionResultStatus;

/**
* Whether the status is the same on all pages
*/
@IsBoolean()
@IsOptional()
transverse?: boolean;

/**
* @example "Ad culpa cupidatat proident amet ullamco proident proident mollit ipsum enim consectetur consequat labore."
*/
Expand Down
1 change: 0 additions & 1 deletion confiture-web-app/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export interface CriteriumResult {

// DATA
status: CriteriumResultStatus;
transverse: boolean;

compliantComment: string | null;
notCompliantComment: string | null;
Expand Down
Loading