Skip to content

Commit

Permalink
refactor(edit moderation): create route + page for edit moderation ac…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
rebeccadumazert committed Oct 9, 2024
1 parent b6796b3 commit 5572617
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 1 deletion.
48 changes: 48 additions & 0 deletions src/controllers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,51 @@ export const getHelpController = async (
next(error);
}
};

export const getEditModerationController = async (
req: Request,
res: Response,
next: NextFunction,
) => {
try {
let email: string | undefined;
let user: User | undefined;
let cached_libelle: string | null | undefined;

if (isWithinAuthenticatedSession(req.session)) {
user = getUserFromAuthenticatedSession(req);
email = user.email;
}

const schema = z.object({
moderation_id: z.union([idSchema(), z.undefined()]),
});
let { moderation_id } = await schema.parseAsync(req.query);

if (!isEmpty(user) && moderation_id) {
try {
const organization = await getOrganizationFromModeration({
user,
moderation_id,
});
cached_libelle = organization.cached_libelle;
} catch (e) {
if (!(e instanceof NotFoundError || e instanceof ForbiddenError)) {
return next(e);
}

moderation_id = undefined;
}
}

return res.render("edit-moderation", {
pageTitle: "Modifier une demande de rattachement en cours",
email,
csrfToken: email && csrfToken(req),
organization_label: cached_libelle,
moderation_id,
});
} catch (error) {
next(error);
}
};
9 changes: 9 additions & 0 deletions src/routers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type Express, Router, urlencoded } from "express";
import nocache from "nocache";
import {
getConnectionAndAccountController,
getEditModerationController,
getHelpController,
getHomeController,
getManageOrganizationsController,
Expand Down Expand Up @@ -152,6 +153,14 @@ export const mainRouter = (app: Express) => {
getHelpController,
);

mainRouter.get(
"/edit-moderation",
urlencoded({ extended: false }),
ejsLayoutMiddlewareFactory(app, true),
csrfProtectionMiddleware,
getEditModerationController,
);

return mainRouter;
};

Expand Down
10 changes: 10 additions & 0 deletions src/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ export const userRouter = () => {
),
);

userRouter.post(
"/cancel-moderation-and-redirect-to-personal-information/:moderation_id",
rateLimiterMiddleware,
checkUserHasPersonalInformationsMiddleware,
csrfProtectionMiddleware,
postCancelModerationAndRedirectControllerFactory(
"/users/personal-information",
),
);

userRouter.get(
"/select-organization",
checkUserHasAtLeastOneOrganizationMiddleware,
Expand Down
90 changes: 90 additions & 0 deletions src/views/edit-moderation.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<div class="page-container">
<div id="modifier-moderation">
<h1 class="fr-h2 title-with-anchor">
<span>Modifier une demande de rattachement en cours</span>
<a
aria-label="Lien direct vers section Modifier une demande de rattachement en cours"
class="fr-btn fr-btn--sm fr-icon-link fr-btn--tertiary-no-outline"
href="#modifier-moderation"
></a>
</h1>
<p>
Vous avez demandé à être rattaché à <%= organization_label; %> avec votre
adresse <%= email; %> :
</p>
<ul>
<li class="fr-mb-3w">
Vous voulez utiliser une autre adresse email<br />
💡 <b>
<form
class="inline-form"
autocomplete="off"
action="/users/cancel-moderation-and-redirect-to-sign-in/<%= moderation_id; %>"
method="post"
>
<input
type="hidden"
name="_csrf"
value="<%= csrfToken; %>"
autocomplete="off"
/>
<input
aria-label="Corriger l’email <%= email; %>"
class="fr-link"
type="submit"
value="Annuler la demande en cours et utiliser une autre adresse email"
/>
</form>
</b>
</li>
<li class="fr-mb-3w">
Vous voulez être rattaché à une autre organisation<br />
💡 <b>
<form
class="inline-form"
autocomplete="off"
action="/users/cancel-moderation-and-redirect-to-join-org/<%= moderation_id; %>"
method="post"
>
<input
type="hidden"
name="_csrf"
value="<%= csrfToken; %>"
autocomplete="off"
/>
<input
aria-label="Corriger l’organisation <%= organization_label; %>"
class="fr-link"
type="submit"
value="Annuler la demande en cours et sélectionner une organisation différente"
/>
</form>
</b>
</li>
<li class="fr-mb-3w">
Vous voulez modifier vos informations personnelles<br />
💡 <b>
<form
class="inline-form"
autocomplete="off"
action="/cancel-moderation-and-redirect-to-personal-information/<%= moderation_id; %>"
method="post"
>
<input
type="hidden"
name="_csrf"
value="<%= csrfToken; %>"
autocomplete="off"
/>
<input
aria-label="Corriger ses informations personnelles"
class="fr-link"
type="submit"
value="Annuler la demande en cours et corriger ses informations personnelles"
/>
</form>
</b>
</li>
</ul>
</div>
</div>
2 changes: 1 addition & 1 deletion src/views/user/verify-email.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<div>
<a
class="fr-link fr-icon-question-line fr-link--icon-left"
href="/help#code-verification"
href="/edit-moderation"
>
J'ai attendu 15 minutes et je ne reçois pas de code de vérification
</a>
Expand Down

0 comments on commit 5572617

Please sign in to comment.