Skip to content

Commit efddcef

Browse files
authored
Ajout de la page Synthèse (#579)
* add overview page with different states and route from step 1 * add charts on audit card * split page in sub components * fix donut theme prop ts check * add conditions to dispay some data * add breadcrumb link, back link on audit page and meta component * update buttons label and remove account page breadcrumb * redesign copy block and update nav items * add meta desc * remove step four page and redirect links to overview instead * add redirect from /partage to /synthese * add new props to progress bar and delete sticky indicators component * move title above sticky header + remove validate button * add toast when audit is done and set publicationDate * make main action in audit row to take full width * update audit creation email content * only send audit creation email when not connected * fix condition to show auditor infos when creating audit * add back links on pages * get audit edit id in report route and show back link on report page * improve responsiveness of header * remove back link on report page + make sure report link are in new tab * add notes button + modal * remove notes tab * fix markdown button type + textarea height * remove edit id in report fetch data * fix accessibility labels * remove markdown button in notes modal * add correct toast wording when updating audit notes * align badge width step title * remove settings link in header dropdown * move audit alert banners from step three to overview page * rename breadcrumb first item when connected * add back link to audit page when not connected * add utility class to remove external icon + fix icon in overview steps buttons * add close button to copy block success message * publish audit when using dev button * update audit finished toast wording for other audit types * update audit creation email content * update icon + highlight first nav link + update copy success message
1 parent b641355 commit efddcef

43 files changed

Lines changed: 1321 additions & 914 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

confiture-rest-api/src/app.module.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Module } from '@nestjs/common';
1+
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
22
import { ConfigModule } from '@nestjs/config';
33
import { FeedbackModule } from './feedback/feedback.module';
44
import { AuditsModule } from './audits/audits.module';
@@ -7,6 +7,7 @@ import { configValidationSchema } from './config-validation-schema';
77
import { MailModule } from './mail/mail.module';
88
import { AuthModule } from './auth/auth.module';
99
import { ProfileModule } from './profile/profile.module';
10+
import { UserMiddleware } from './auth/user.middleware';
1011

1112
@Module({
1213
imports: [
@@ -22,4 +23,8 @@ import { ProfileModule } from './profile/profile.module';
2223
],
2324
controllers: [HealthCheckController],
2425
})
25-
export class AppModule {}
26+
export class AppModule implements NestModule{
27+
configure(consumer: MiddlewareConsumer) {
28+
consumer.apply(UserMiddleware).forRoutes('*')
29+
}
30+
}

confiture-rest-api/src/audits/audits.controller.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ export class AuditsController {
5555
description: 'The audit has been successfully created.',
5656
type: Audit,
5757
})
58-
async createAudit(@Body() body: CreateAuditDto) {
58+
async createAudit(@Body() body: CreateAuditDto, @User() user: AuthenticationJwtPayload) {
5959
const audit = await this.auditService.createAudit(body);
6060

61-
this.mailer.sendAuditCreatedMail(audit).catch((err) => {
62-
console.error(`Failed to send email for audit ${audit.editUniqueId}`);
63-
console.error(err);
64-
});
61+
62+
if (!user) {
63+
this.mailer.sendAuditCreatedMail(audit).catch((err) => {
64+
console.error(`Failed to send email for audit ${audit.editUniqueId}`);
65+
console.error(err);
66+
});
67+
}
6568

6669
return audit;
6770
}

confiture-rest-api/src/auth/auth.guard.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,14 @@ import { JwtService } from '@nestjs/jwt';
88
import type { Request } from 'express';
99
import { AuthenticationJwtPayload } from './jwt-payloads';
1010

11+
/**
12+
* Verify that the request is authenticated.
13+
* This guard requires the `UserMiddleware` to be run on the request.
14+
*/
1115
@Injectable()
1216
export class AuthGuard implements CanActivate {
13-
constructor(private readonly jwt: JwtService) {}
14-
1517
async canActivate(context: ExecutionContext) {
1618
const request = context.switchToHttp().getRequest();
17-
const token = this.extractTokenFromHeader(request);
18-
if (!token) {
19-
throw new UnauthorizedException();
20-
}
21-
22-
try {
23-
const payload = (await this.jwt.verifyAsync(
24-
token,
25-
)) as AuthenticationJwtPayload;
26-
// 💡 We're assigning the payload to the request object here
27-
// so that we can access it in our route handlers
28-
request['user'] = payload;
29-
} catch {
30-
throw new UnauthorizedException();
31-
}
32-
33-
return true;
34-
}
35-
36-
private extractTokenFromHeader(request: Request): string | undefined {
37-
const [type, token] = request.headers.authorization?.split(' ') ?? [];
38-
return type === 'Bearer' ? token : undefined;
19+
return !!request.user
3920
}
4021
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Injectable, NestMiddleware } from "@nestjs/common";
2+
import { JwtService } from "@nestjs/jwt";
3+
import type { Request } from 'express';
4+
import { AuthenticationJwtPayload } from "./jwt-payloads";
5+
6+
/**
7+
* Extract the authentication token and verifies it.
8+
* No error is thrown if there is no token or if the token is invalid. Use the
9+
* AuthRequired decorator if you want a route to only accept authenticated requests.
10+
*/
11+
@Injectable()
12+
export class UserMiddleware implements NestMiddleware {
13+
constructor(private readonly jwt: JwtService) {}
14+
15+
use(req: Request, res: any, next: (error?: any) => void) {
16+
const token = this.extractTokenFromHeader(req);
17+
18+
if (!token) {
19+
next()
20+
return
21+
}
22+
23+
this.jwt.verifyAsync(token)
24+
.then(payload => {
25+
req['user'] = payload;
26+
next()
27+
})
28+
.catch(next)
29+
}
30+
31+
private extractTokenFromHeader(request: Request): string | undefined {
32+
const [type, token] = request.headers.authorization?.split(' ') ?? [];
33+
return type === 'Bearer' ? token : undefined;
34+
}
35+
36+
}

confiture-rest-api/src/mail/audit-creation-email.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { renderMailTemplate } from './render-mjml-template';
22

33
export interface AuditCreationEmailData {
4-
auditorName: string;
54
procedureName: string;
6-
auditUrl: string;
5+
overviewUrl: string;
76
reportUrl: string;
87
}
98

@@ -17,13 +16,12 @@ export function html(data: AuditCreationEmailData): string {
1716

1817
export function plain(data: AuditCreationEmailData): string {
1918
return `
20-
Bonjour ${data.auditorName}, vous venez de créer l’audit "${data.procedureName}".
19+
Bonjour, vous venez de créer l’audit "${data.procedureName}".
2120
22-
Vous trouverez ci-dessous le lien administrateur de l’audit. Pensez bien à le conserver, c’est le seul moyen de reprendre l’édition de l’audit.
23-
${data.auditUrl}
21+
Voici le lien de la synthèse d’audit (privé) permettant d’accéder aux documents suivants : l’audit, le rapport d’audit et la déclaration d’accessibilité (dans le cas d’un audit 106 critères). Pensez-bien à conserver ce lien, c’est le seul moyen d’accéder à vos documents.
22+
${data.overviewUrl}
2423
25-
Vous trouverez ci-dessous le lien public du rapport d’audit. Il vous permet de consulter et vérifier le rapport d’audit. Vous devrez le partager une fois que l’audit sera terminé.
26-
${data.reportUrl}
24+
Voici le lien du rapport d’audit (public) : ${data.reportUrl}
2725
2826
Vous avez une question ? Vous pouvez nous contacter en utilisant l’adresse e-mail ara@design.numerique.gouv.fr.
2927
`;

confiture-rest-api/src/mail/mail.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as updateEmailVerificationEmail from './update-email-verification-email
1313
import * as updateEmailConfirmationEmail from './update-email-confirmation-email';
1414
import * as requestPasswordResetEmail from './request-password-reset-email';
1515
import { EmailConfig } from './email-config.interface';
16+
import { AuditCreationEmailData } from './audit-creation-email'
1617

1718
const EMAILS: Record<EmailType, EmailConfig> = {
1819
[EmailType.AUDIT_CREATION]: auditCreationEmail,
@@ -81,19 +82,18 @@ export class MailService {
8182
}
8283

8384
sendAuditCreatedMail(audit: Audit) {
84-
const auditUrl = `${this.config.get('FRONT_BASE_URL')}/audits/${
85+
const overviewUrl = `${this.config.get('FRONT_BASE_URL')}/audits/${
8586
audit.editUniqueId
86-
}/generation`;
87+
}/synthese`;
8788

8889
const reportUrl = `${this.config.get('FRONT_BASE_URL')}/rapports/${
8990
audit.consultUniqueId
90-
}/resultats`;
91+
}`;
9192

92-
const data = {
93-
auditorName: audit.auditorName,
93+
const data: AuditCreationEmailData = {
9494
procedureName: audit.procedureName,
95-
auditUrl,
96-
reportUrl,
95+
overviewUrl,
96+
reportUrl
9797
};
9898

9999
return this.sendMail(audit.auditorEmail, EmailType.AUDIT_CREATION, data);

confiture-rest-api/templates/account-confirmation.mjml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
</mj-column>
2323
</mj-section>
2424

25-
<mj-section>
26-
<mj-column>
27-
<mj-spacer height="32px"></mj-spacer>
28-
</mj-column>
29-
</mj-section>
30-
3125
<!-- FOOTER -->
3226
<mj-include path="./footer.mjml" />
3327
</mj-body>

confiture-rest-api/templates/account-verification.mjml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929
</mj-column>
3030
</mj-section>
3131

32-
<mj-section>
33-
<mj-column>
34-
<mj-spacer height="32px"></mj-spacer>
35-
</mj-column>
36-
</mj-section>
37-
3832
<!-- FOOTER -->
3933
<mj-include path="./footer.mjml" />
4034
</mj-body>

confiture-rest-api/templates/audit-creation.mjml

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<mjml>
22
<mj-head>
3-
<mj-title>Création d’un nouvel audit : {{ audit.name }}</mj-title>
3+
<mj-title>Création d’un nouvel audit : {{ procedureName }}</mj-title>
44
<mj-attributes>
5-
<mj-preview>Création d’un nouvel audit : {{ audit.name }}</mj-preview>
5+
<mj-preview>Création d’un nouvel audit : {{ procedureName }}</mj-preview>
66
<mj-include path="./styles.mjml" />
77
</mj-attributes>
88
</mj-head>
@@ -13,60 +13,45 @@
1313
<!-- BODY -->
1414
<mj-section>
1515
<mj-column>
16-
<mj-text font-size="20px" font-weight="700" padding-bottom="8px">Bonjour {{ auditorName }}</mj-text>
17-
<mj-text padding-bottom="16px">Vous venez de créer l'audit
18-
<strong>{{ procedureName }}</strong>.
19-
</mj-text>
20-
<mj-text padding-bottom="12px">Vous trouverez ci-dessous le lien administrateur de l’audit.
21-
Pensez-bien à le conserver, c’est le seul moyen de reprendre l’édition
22-
de l’audit.</mj-text>
23-
</mj-column>
24-
</mj-section>
25-
26-
<mj-section mj-class="blue-section">
27-
<mj-column>
28-
<mj-text font-size="20px" font-weight="700" padding-bottom="10px">Lien vers l'audit - Ne pas partager</mj-text>
29-
<mj-text mj-class="blue-link">
30-
<a href="{{auditUrl}}" style="color: inherit;">{{auditUrl}}</a>
31-
</mj-text>
16+
<mj-text font-size="20px" font-weight="700" padding-bottom="16px">Audit créé avec succès</mj-text>
17+
<mj-text>Vous trouverez ci-dessous le lien permettant d’accéder aux documents suivants :</mj-text>
18+
<mj-text>- Audit {{ procedureName }}</mj-text>
19+
<mj-text>- Rapport d’audit (généré automatiquement)</mj-text>
20+
<mj-text padding-bottom="12px">- Déclaration d’accessibilité (dans le cas d’un audit 106 critères).</mj-text>
21+
<mj-text padding-bottom="32px" font-weight="700">Pensez-bien à conserver ces liens, c’est le seul moyen d’accéder à vos documents.</mj-text>
3222
</mj-column>
3323
</mj-section>
3424

3525
<mj-section>
3626
<mj-column>
37-
<mj-spacer height="24px"></mj-spacer>
27+
<mj-text font-size="20px" font-weight="700" padding-bottom="8px">Lien de la synthèse d’audit (privé)</mj-text>
28+
<mj-text padding-bottom="12px">⚠️ Ne pas partagez pas ce lien, il permet de modifier ou supprimer votre audit.</mj-text>
3829
</mj-column>
3930
</mj-section>
4031

41-
<mj-section>
32+
<mj-section mj-class="blue-section">
4233
<mj-column>
43-
<mj-text>Vous trouverez ci-dessous le lien public du rapport d’audit. Il vous
44-
permet de consulter et vérifier le rapport d’audit. Vous devrez le
45-
partager une fois que l’audit sera terminé.</mj-text>
34+
<mj-text mj-class="blue-link">
35+
<a href="{{ overviewUrl }}" style="color: inherit;">{{ overviewUrl }}</a>
36+
</mj-text>
4637
</mj-column>
4738
</mj-section>
4839

4940
<mj-section>
5041
<mj-column>
51-
<mj-spacer height="12px"></mj-spacer>
42+
<mj-text font-size="20px" font-weight="700" padding-top="24px" padding-bottom="8px">Lien du rapport d’audit (public)</mj-text>
43+
<mj-text padding-bottom="12px">Vous pouvez partager ce lien à tout moment.</mj-text>
5244
</mj-column>
5345
</mj-section>
5446

5547
<mj-section mj-class="blue-section">
5648
<mj-column>
57-
<mj-text font-size="20px" font-weight="700" padding-bottom="10px">Lien vers le rapport - À partager au client</mj-text>
5849
<mj-text mj-class="blue-link">
59-
<a href="{{reportUrl}}" style="color: inherit;">{{reportUrl}}</a>
50+
<a href="{{ reportUrl }}" style="color: inherit;">{{ reportUrl }}</a>
6051
</mj-text>
6152
</mj-column>
6253
</mj-section>
6354

64-
<mj-section>
65-
<mj-column>
66-
<mj-spacer height="32px"></mj-spacer>
67-
</mj-column>
68-
</mj-section>
69-
7055
<!-- FOOTER -->
7156
<mj-include path="./footer.mjml" />
7257
</mj-body>

confiture-rest-api/templates/email-update-confirmation.mjml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
</mj-column>
2525
</mj-section>
2626

27-
<mj-section>
28-
<mj-column>
29-
<mj-spacer height="32px"></mj-spacer>
30-
</mj-column>
31-
</mj-section>
32-
3327
<!-- FOOTER -->
3428
<mj-include path="./footer.mjml" />
3529
</mj-body>

0 commit comments

Comments
 (0)