Skip to content

Commit

Permalink
Permet d'accéder à un rapport lorsque l'audit est supprimé (#662)
Browse files Browse the repository at this point in the history
* update delete modal wording + harmonize danger-button styles

* only hide deleted audit

* hide names in report and context pages when audit is soft deleted

* fix typo

* update changelog

---------

Co-authored-by: Adrien Boutigny <[email protected]>
  • Loading branch information
bellangerq and hissalht authored May 23, 2024
1 parent 03a33a3 commit 5b0c4aa
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 90 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

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.

## 23/05/2024

### Nouvelles fonctionnalités 🚀

- Permet d’accéder à un rapport quand l’audit est supprimer ([#662](https://github.com/DISIC/Ara/pull/662))

## 26/04/2024

### Autres changements ⚙️

- Ajoute un lien de retour vers le rapport depuis la page de contexte de l’audit ([#703](https://github.com/DISIC/Ara/pull/703))


## 17/04/2024

### Nouvelles fonctionnalités 🚀
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Audit" ADD COLUMN "isHidden" BOOLEAN NOT NULL DEFAULT false;
4 changes: 4 additions & 0 deletions confiture-rest-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ model Audit {
sourceAuditId Int?
auditCopies Audit[] @relation("AuditDuplicationHistory")
// As of https://github.com/DISIC/Ara/pull/662, when an audit is deleted, its
// data is longer editable, but the report remainn available
isHidden Boolean @default(false)
@@unique([editUniqueId, consultUniqueId])
}

Expand Down
8 changes: 6 additions & 2 deletions confiture-rest-api/src/audits/audit-export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ export class AuditExportService {
}

async getCsvExport(editUniqueId: string): Promise<StreamableFile> {
const audit =
await this.auditService.getAuditWithEditUniqueId(editUniqueId);
const audit = (await this.auditService.findAuditWithEditUniqueId(
editUniqueId,
{ pages: true }
)) as Audit & {
pages: AuditedPage[];
};
const results =
await this.auditService.getResultsWithEditUniqueId(editUniqueId);

Expand Down
63 changes: 36 additions & 27 deletions confiture-rest-api/src/audits/audit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,10 @@ export class AuditService {
});
}

// getAuditWithConsultUniqueId(uniqueId: string) {
// return this.prisma.audit.findUnique({
// where: { consultUniqueId: uniqueId },
// });
// }

getAuditWithEditUniqueId(uniqueId: string) {
return this.prisma.audit.findUnique({
where: { editUniqueId: uniqueId },
include: {
recipients: true,
environments: true,
pages: true,
sourceAudit: {
select: {
procedureName: true
}
}
}
findAuditWithEditUniqueId(uniqueId: string, include?: Prisma.AuditInclude) {
return this.prisma.audit.findFirst({
where: { editUniqueId: uniqueId, isHidden: false },
include
});
}

Expand Down Expand Up @@ -555,10 +540,10 @@ export class AuditService {
}

/**
* Delete an audit and the data associated with it.
* Completely delete an audit and all the data associated with it.
* @returns True if an audit was deleted, false otherwise.
*/
async deleteAudit(uniqueId: string): Promise<boolean> {
async hardDeleteAudit(uniqueId: string): Promise<boolean> {
try {
const storedFiles = await this.prisma.storedFile.findMany({
where: {
Expand Down Expand Up @@ -594,6 +579,30 @@ export class AuditService {
}
}

/**
* Mark an audit as deleted and remove auditor informations. Its data will be not be deleted.
* @returns True if an audit was deleted, false otherwise.
*/
async softDeleteAudit(uniqueId: string): Promise<boolean> {
try {
await this.prisma.audit.update({
where: { editUniqueId: uniqueId },
data: {
isHidden: true,
auditorEmail: null,
auditorName: null,
auditorOrganisation: null
}
});
return true;
} catch (e) {
if (e?.code === "P2025") {
return false;
}
throw e;
}
}

/**
* Checks if an audit was deleted by checking the presence of an audit trace.
* @param uniqueId edit unique id of the checked audit
Expand Down Expand Up @@ -930,9 +939,8 @@ export class AuditService {
}

async isAuditComplete(uniqueId: string): Promise<boolean> {
const audit = await this.prisma.audit.findUnique({
where: { editUniqueId: uniqueId },
include: { pages: true }
const audit = await this.findAuditWithEditUniqueId(uniqueId, {
pages: true
});

const testedCount = await this.prisma.criterionResult.count({
Expand All @@ -959,8 +967,8 @@ export class AuditService {
}

async duplicateAudit(sourceUniqueId: string, newAuditName: string) {
const originalAudit = await this.prisma.audit.findUnique({
where: { editUniqueId: sourceUniqueId },
const originalAudit = await this.prisma.audit.findFirst({
where: { editUniqueId: sourceUniqueId, isHidden: false },
include: {
environments: true,
pages: {
Expand Down Expand Up @@ -1132,7 +1140,8 @@ export class AuditService {
async getAuditsByAuditorEmail(email: string) {
const audits = await this.prisma.audit.findMany({
where: {
auditorEmail: email
auditorEmail: email,
isHidden: false
},
select: {
procedureName: true,
Expand Down
16 changes: 12 additions & 4 deletions confiture-rest-api/src/audits/audits.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ export class AuditsController {
@ApiNotFoundResponse({ description: "The audit does not exist." })
@ApiGoneResponse({ description: "The audit has been previously deleted." })
async getAudit(@Param("uniqueId") uniqueId: string) {
const audit = await this.auditService.getAuditWithEditUniqueId(uniqueId);
const audit = await this.auditService.findAuditWithEditUniqueId(uniqueId, {
environments: true,
pages: true,
sourceAudit: {
select: {
procedureName: true
}
}
});

if (!audit) {
return this.sendAuditNotFoundStatus(uniqueId);
Expand Down Expand Up @@ -153,7 +161,7 @@ export class AuditsController {
file: Express.Multer.File,
@Body() body: UploadImageDto
) {
const audit = await this.auditService.getAuditWithEditUniqueId(uniqueId);
const audit = await this.auditService.findAuditWithEditUniqueId(uniqueId);

if (!audit) {
return this.sendAuditNotFoundStatus(uniqueId);
Expand Down Expand Up @@ -210,7 +218,7 @@ export class AuditsController {
@Param("uniqueId") uniqueId: string,
@Body() body: UpdateResultsDto
) {
const audit = await this.auditService.getAuditWithEditUniqueId(uniqueId);
const audit = await this.auditService.findAuditWithEditUniqueId(uniqueId);

if (!audit) {
return this.sendAuditNotFoundStatus(uniqueId);
Expand Down Expand Up @@ -247,7 +255,7 @@ export class AuditsController {
@ApiNotFoundResponse({ description: "The audit does not exist." })
@ApiGoneResponse({ description: "The audit has been previously deleted." })
async deleteAudit(@Param("uniqueId") uniqueId: string) {
const deleted = await this.auditService.deleteAudit(uniqueId);
const deleted = await this.auditService.softDeleteAudit(uniqueId);

if (!deleted) {
return this.sendAuditNotFoundStatus(uniqueId);
Expand Down
16 changes: 0 additions & 16 deletions confiture-web-app/src/components/account/settings/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,4 @@ async function hideAccountDeletionForm() {
.wrapper {
max-width: 24rem;
}
.danger-button-outline {
color: var(--background-action-high-error);
}
.danger-button {
background-color: var(--background-action-high-error);
}
.danger-button:hover {
background-color: var(--background-action-high-error-hover);
}
.danger-button:focus {
background-color: var(--background-action-high-error-active);
}
</style>
28 changes: 7 additions & 21 deletions confiture-web-app/src/components/audit/DeleteModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ defineExpose({
class="fr-icon-warning-line fr-fi--lg"
aria-hidden="true"
/>
Vous allez supprimer l’audit
Vous allez supprimer cet audit
</h1>
<p>
Toutes les informations saisies seront effacées (cela comprend
l’audit, le rapport et toute donnée personnelle associée). Cette
action est irréversible. Souhaitez-vous supprimer l’audit ?
Cet audit sera définitivement supprimé. Le rapport de cet audit
restera disponible mais toutes vos informations personnelles
seront supprimées : prénom, nom, nom de la structure et adresse
e-mail.
</p>
</div>
<div class="fr-modal__footer">
Expand All @@ -51,15 +52,15 @@ defineExpose({
class="fr-btn danger-button"
@click="$emit('confirm')"
>
Oui, supprimer
Supprimer l’audit
</button>
</li>
<li>
<button
class="fr-btn fr-btn--secondary"
@click="modal?.hide()"
>
Non
Annuler
</button>
</li>
</ul>
Expand All @@ -70,18 +71,3 @@ defineExpose({
</div>
</DsfrModal>
</template>

<style scoped>
/* FIXME: create utility class (`fr-btn__danger` and `fr-btn__danger-outline`) */
.danger-button {
background-color: var(--background-action-high-error);
}
.danger-button:hover {
background-color: var(--background-action-high-error-hover);
}
.danger-button:focus {
background-color: var(--background-action-high-error-active);
}
</style>
14 changes: 0 additions & 14 deletions confiture-web-app/src/components/audit/LeaveModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,3 @@ defineExpose({
</div>
</DsfrModal>
</template>

<style scoped>
.danger-button {
background-color: var(--background-action-high-error);
}
.danger-button:hover {
background-color: var(--background-action-high-error-hover);
}
.danger-button:focus {
background-color: var(--background-action-high-error-active);
}
</style>
8 changes: 3 additions & 5 deletions confiture-web-app/src/pages/report/ContextPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ useWrappedFetch(() => report.fetchReport(uniqueId));
<h2 class="fr-mb-2w fr-mb-md-3w">Auditeur ou auditrice</h2>

<p class="fr-mb-9v fr-mb-md-6w">
<template v-if="report.data.context.auditorName">
Cet audit a été réalisé par
<strong>{{ report.data.context.auditorName }}</strong
>.
</template>
Cet audit a été réalisé par
<strong>{{ report.data.context.auditorName }}</strong
>.
</p>
</template>

Expand Down
2 changes: 1 addition & 1 deletion confiture-web-app/src/pages/report/ReportPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const siteUrl = computed(() => {
<p class="fr-mb-0">
Référentiel : <strong>{{ report.data.context.referencial }}</strong>
</p>
<p class="fr-mb-1v">
<p v-if="report.data.context.auditorName" class="fr-mb-1v">
Auditeur ou auditrice :
<strong>{{ report.data.context.auditorName }}</strong>
</p>
Expand Down
19 changes: 19 additions & 0 deletions confiture-web-app/src/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,22 @@ from DSFR links with `target="_blank"` */
[target="_blank"].no-external-icon::after {
content: none !important;
}

/* DSFR-style primary button with "danger" variant */
.danger-button {
background-color: var(--background-action-high-error) !important;
color: var(--grey-950-125) !important;
}

.danger-button:hover {
background-color: var(--background-action-high-error-hover) !important;
}

.danger-button:focus {
background-color: var(--background-action-high-error-active) !important;
}

/* DSFR-style outline button with "danger" variant */
.danger-button-outline {
color: var(--background-action-high-error) !important;
}

0 comments on commit 5b0c4aa

Please sign in to comment.