Skip to content

Commit 655df39

Browse files
committed
✨ suggest ministere des armees for intraf.gouv.fr emails
1 parent e2f8ea9 commit 655df39

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

src/controllers/organization.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const getJoinOrganizationController = async (
6060
do_not_propose_suggestions: optionalBooleanSchema(),
6161
});
6262

63-
const { notification, siret_hint, do_not_propose_suggestions } =
63+
let { notification, siret_hint, do_not_propose_suggestions } =
6464
await schema.parseAsync(req.query);
6565

6666
const { id: user_id, email } = getUserFromAuthenticatedSession(req);
@@ -74,13 +74,14 @@ export const getJoinOrganizationController = async (
7474
return res.redirect("/users/organization-suggestions");
7575
}
7676

77+
const emailDomain = getEmailDomain(email);
78+
7779
return res.render("user/join-organization", {
7880
pageTitle: "Rejoindre une organisation",
7981
notifications: await getNotificationsFromRequest(req),
8082
csrfToken: csrfToken(req),
8183
siretHint: siret_hint,
82-
useGendarmerieSearchHint:
83-
getEmailDomain(email) === "gendarmerie.interieur.gouv.fr",
84+
useGendarmerieSearchHint: emailDomain === "gendarmerie.interieur.gouv.fr",
8485
});
8586
} catch (error) {
8687
next(error);

src/managers/organization/join.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
findByUserId,
5454
findByVerifiedEmailDomain,
5555
getById,
56+
getBySiret,
5657
} from "../../repositories/organization/getters";
5758
import {
5859
linkUserToOrganization,
@@ -67,6 +68,7 @@ import {
6768
import { logger } from "../../services/log";
6869
import {
6970
hasLessThanFiftyEmployees,
71+
isArmeeDomain,
7072
isCommune,
7173
isEducationNationaleDomain,
7274
isEtablissementScolaireDuPremierEtSecondDegre,
@@ -110,6 +112,13 @@ export const getOrganizationSuggestions = async ({
110112
return [];
111113
}
112114

115+
if (isArmeeDomain(domain)) {
116+
const armeeOrganization = await getBySiret("11009001600053");
117+
if (armeeOrganization) {
118+
return [armeeOrganization];
119+
}
120+
}
121+
113122
const organizationsSuggestions = await findByVerifiedEmailDomain(domain);
114123

115124
if (organizationsSuggestions.length > MAX_SUGGESTED_ORGANIZATIONS) {

src/repositories/organization/getters.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ export const findByUserId = findByUserIdFactory({
1717
pg: getDatabaseConnection(),
1818
});
1919

20+
export const getBySiret = async (siret: string) => {
21+
const connection = getDatabaseConnection();
22+
23+
const { rows }: QueryResult<Organization> = await connection.query(
24+
`
25+
SELECT id, siret
26+
FROM organizations
27+
WHERE siret = $1
28+
`,
29+
[siret],
30+
);
31+
32+
return rows.shift();
33+
};
34+
2035
export const findPendingByUserId = async (user_id: number) => {
2136
const connection = getDatabaseConnection();
2237

src/services/organization.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ export const isEducationNationaleDomain = (domain: string) => {
115115
return domain.match(/^ac-[a-zA-Z0-9-]*\.fr$/) !== null;
116116
};
117117

118+
export const isArmeeDomain = (domain: string) => {
119+
if (!isDomainValid(domain)) {
120+
return false;
121+
}
122+
return domain === "intradef.gouv.fr";
123+
};
124+
118125
export const getOrganizationTypeLabel = (organization: Organization) => {
119126
if (isEtablissementScolaireDuPremierEtSecondDegre(organization)) {
120127
return "établissement scolaire";

0 commit comments

Comments
 (0)