@proconnect-gouv/proconnect.identite 12.0.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/connectors/index.d.ts +0 -93
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +6 -15
- package/dist/managers/organization/index.d.ts +0 -1
- package/dist/managers/organization/index.d.ts.map +1 -1
- package/dist/managers/organization/index.js +0 -1
- package/dist/repositories/email-domain/index.d.ts +0 -3
- package/dist/repositories/email-domain/index.d.ts.map +1 -1
- package/dist/repositories/email-domain/index.js +0 -1
- package/dist/repositories/franceconnect_userinfo/index.d.ts +0 -2
- package/dist/repositories/franceconnect_userinfo/index.d.ts.map +1 -1
- package/dist/repositories/franceconnect_userinfo/index.js +0 -2
- package/dist/repositories/moderation/index.d.ts +0 -1
- package/dist/repositories/moderation/index.d.ts.map +1 -1
- package/dist/repositories/moderation/index.js +0 -1
- package/dist/repositories/organization/index.d.ts +0 -1
- package/dist/repositories/organization/index.d.ts.map +1 -1
- package/dist/repositories/organization/index.js +0 -1
- package/dist/repositories/user/index.d.ts +0 -1
- package/dist/repositories/user/index.d.ts.map +1 -1
- package/dist/repositories/user/index.js +0 -1
- package/dist/repositories/user_organisation/index.d.ts +0 -3
- package/dist/repositories/user_organisation/index.d.ts.map +1 -1
- package/dist/repositories/user_organisation/index.js +0 -3
- package/package.json +3 -3
- package/src/connectors/index.ts +1 -22
- package/src/managers/organization/index.ts +0 -1
- package/src/repositories/email-domain/index.ts +0 -3
- package/src/repositories/franceconnect_userinfo/index.ts +0 -2
- package/src/repositories/moderation/index.ts +0 -1
- package/src/repositories/organization/index.ts +0 -1
- package/src/repositories/user/index.ts +0 -1
- package/src/repositories/user_organisation/index.ts +0 -3
- package/dist/managers/organization/mark-domain-as-verified.d.ts +0 -18
- package/dist/managers/organization/mark-domain-as-verified.d.ts.map +0 -1
- package/dist/managers/organization/mark-domain-as-verified.js +0 -64
- package/dist/managers/user/assign-user-verification-type-to-domain.d.ts +0 -3
- package/dist/managers/user/assign-user-verification-type-to-domain.d.ts.map +0 -1
- package/dist/managers/user/assign-user-verification-type-to-domain.js +0 -20
- package/dist/managers/user/index.d.ts +0 -2
- package/dist/managers/user/index.d.ts.map +0 -1
- package/dist/managers/user/index.js +0 -1
- package/dist/repositories/email-domain/delete-email-domains-by-verification-types.d.ts +0 -8
- package/dist/repositories/email-domain/delete-email-domains-by-verification-types.d.ts.map +0 -1
- package/dist/repositories/email-domain/delete-email-domains-by-verification-types.js +0 -19
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts +0 -4
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts.map +0 -1
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.js +0 -10
- package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.d.ts +0 -16
- package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.d.ts.map +0 -1
- package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.js +0 -23
- package/dist/repositories/moderation/create-moderation.d.ts +0 -22
- package/dist/repositories/moderation/create-moderation.d.ts.map +0 -1
- package/dist/repositories/moderation/create-moderation.js +0 -21
- package/dist/repositories/organization/find-users-by-organization.d.ts +0 -34
- package/dist/repositories/organization/find-users-by-organization.d.ts.map +0 -1
- package/dist/repositories/organization/find-users-by-organization.js +0 -16
- package/dist/repositories/user/delete.d.ts +0 -3
- package/dist/repositories/user/delete.d.ts.map +0 -1
- package/dist/repositories/user/delete.js +0 -11
- package/dist/repositories/user_organisation/create-user-organization.d.ts +0 -12
- package/dist/repositories/user_organisation/create-user-organization.d.ts.map +0 -1
- package/dist/repositories/user_organisation/create-user-organization.js +0 -21
- package/dist/repositories/user_organisation/delete-user-organization.d.ts +0 -3
- package/dist/repositories/user_organisation/delete-user-organization.d.ts.map +0 -1
- package/dist/repositories/user_organisation/delete-user-organization.js +0 -12
- package/dist/repositories/user_organisation/update-user-organization.d.ts +0 -12
- package/dist/repositories/user_organisation/update-user-organization.d.ts.map +0 -1
- package/dist/repositories/user_organisation/update-user-organization.js +0 -20
- package/src/managers/organization/mark-domain-as-verified.test.ts +0 -250
- package/src/managers/organization/mark-domain-as-verified.ts +0 -123
- package/src/managers/user/assign-user-verification-type-to-domain.test.ts +0 -105
- package/src/managers/user/assign-user-verification-type-to-domain.ts +0 -40
- package/src/managers/user/index.ts +0 -1
- package/src/repositories/email-domain/delete-email-domains-by-verification-types.test.ts +0 -49
- package/src/repositories/email-domain/delete-email-domains-by-verification-types.ts +0 -45
- package/src/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.test.ts +0 -47
- package/src/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.ts +0 -21
- package/src/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.test.ts +0 -102
- package/src/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.ts +0 -41
- package/src/repositories/moderation/create-moderation.test.ts +0 -43
- package/src/repositories/moderation/create-moderation.ts +0 -45
- package/src/repositories/organization/find-users-by-organization.test.ts +0 -51
- package/src/repositories/organization/find-users-by-organization.test.ts.snapshot +0 -35
- package/src/repositories/organization/find-users-by-organization.ts +0 -30
- package/src/repositories/user/delete.test.ts +0 -35
- package/src/repositories/user/delete.ts +0 -19
- package/src/repositories/user_organisation/create-user-organization.test.ts +0 -66
- package/src/repositories/user_organisation/create-user-organization.test.ts.snapshot +0 -25
- package/src/repositories/user_organisation/create-user-organization.ts +0 -39
- package/src/repositories/user_organisation/delete-user-organization.test.ts +0 -55
- package/src/repositories/user_organisation/delete-user-organization.ts +0 -24
- package/src/repositories/user_organisation/update-user-organization.test.ts +0 -48
- package/src/repositories/user_organisation/update-user-organization.ts +0 -42
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { NotFoundError } from "#src/errors";
|
|
4
|
-
import { context, emptyDatabase, migrate, pg } from "#testing";
|
|
5
|
-
import assert from "node:assert/strict";
|
|
6
|
-
import { before, beforeEach, describe, it } from "node:test";
|
|
7
|
-
import { markDomainAsVerifiedFactory } from "./mark-domain-as-verified.js";
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
const markDomainAsVerified = markDomainAsVerifiedFactory(context);
|
|
12
|
-
|
|
13
|
-
describe("markDomainAsVerified", () => {
|
|
14
|
-
before(migrate);
|
|
15
|
-
beforeEach(emptyDatabase);
|
|
16
|
-
|
|
17
|
-
it("should update organization members", async () => {
|
|
18
|
-
await pg.sql`
|
|
19
|
-
INSERT INTO organizations
|
|
20
|
-
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
21
|
-
VALUES
|
|
22
|
-
(1, 'Dark Angels', 'Dark Angels Legion', '🦁', '4444-04-04', '4444-04-04')
|
|
23
|
-
;
|
|
24
|
-
`;
|
|
25
|
-
await pg.sql`
|
|
26
|
-
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
27
|
-
VALUES (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', '0', 'Primarque')
|
|
28
|
-
`;
|
|
29
|
-
await pg.sql`
|
|
30
|
-
INSERT INTO users_organizations
|
|
31
|
-
(user_id, organization_id, created_at, updated_at, is_external, verification_type)
|
|
32
|
-
VALUES (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle')
|
|
33
|
-
;
|
|
34
|
-
`;
|
|
35
|
-
await pg.sql`
|
|
36
|
-
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
37
|
-
VALUES (1, 'darkangels.world', 'not_verified_yet')
|
|
38
|
-
`;
|
|
39
|
-
|
|
40
|
-
await markDomainAsVerified({
|
|
41
|
-
domain: "darkangels.world",
|
|
42
|
-
domain_verification_type: "verified",
|
|
43
|
-
organization_id: 1,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// user verification_type should be updated to "domain"
|
|
47
|
-
const { rows: userLinks } = await pg.sql`
|
|
48
|
-
SELECT user_id, verification_type
|
|
49
|
-
FROM users_organizations
|
|
50
|
-
WHERE organization_id = 1
|
|
51
|
-
`;
|
|
52
|
-
assert.deepEqual(userLinks, [{ user_id: 1, verification_type: "domain" }]);
|
|
53
|
-
|
|
54
|
-
// old email_domain records should be replaced with "verified"
|
|
55
|
-
const { rows: emailDomains } = await pg.sql`
|
|
56
|
-
SELECT domain, verification_type
|
|
57
|
-
FROM email_domains
|
|
58
|
-
WHERE organization_id = 1
|
|
59
|
-
ORDER BY verification_type
|
|
60
|
-
`;
|
|
61
|
-
assert.deepEqual(emailDomains, [
|
|
62
|
-
{ domain: "darkangels.world", verification_type: "verified" },
|
|
63
|
-
]);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("approving a domain should replace an existing rejection for the same domain", async () => {
|
|
67
|
-
await pg.sql`
|
|
68
|
-
INSERT INTO organizations
|
|
69
|
-
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
70
|
-
VALUES
|
|
71
|
-
(1, 'Night Lords', 'Night Lords Legion', '🦇', '4444-04-04', '4444-04-04')
|
|
72
|
-
;
|
|
73
|
-
`;
|
|
74
|
-
await pg.sql`
|
|
75
|
-
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
76
|
-
VALUES (1, 'nightlords.world', 'refused')
|
|
77
|
-
`;
|
|
78
|
-
|
|
79
|
-
await markDomainAsVerified({
|
|
80
|
-
domain: "nightlords.world",
|
|
81
|
-
domain_verification_type: "verified",
|
|
82
|
-
organization_id: 1,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const { rows: emailDomains } = await pg.sql`
|
|
86
|
-
SELECT domain, verification_type
|
|
87
|
-
FROM email_domains
|
|
88
|
-
WHERE organization_id = 1
|
|
89
|
-
ORDER BY verification_type
|
|
90
|
-
`;
|
|
91
|
-
assert.deepEqual(emailDomains, [
|
|
92
|
-
{ domain: "nightlords.world", verification_type: "verified" },
|
|
93
|
-
]);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("rejecting a domain should replace an existing approval for the same domain", async () => {
|
|
97
|
-
await pg.sql`
|
|
98
|
-
INSERT INTO organizations
|
|
99
|
-
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
100
|
-
VALUES
|
|
101
|
-
(1, 'Thousand Sons', 'Thousand Sons Legion', '📖', '4444-04-04', '4444-04-04')
|
|
102
|
-
;
|
|
103
|
-
`;
|
|
104
|
-
await pg.sql`
|
|
105
|
-
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
106
|
-
VALUES (1, 'thousandsons.world', 'verified')
|
|
107
|
-
`;
|
|
108
|
-
|
|
109
|
-
await markDomainAsVerified({
|
|
110
|
-
domain: "thousandsons.world",
|
|
111
|
-
domain_verification_type: "refused",
|
|
112
|
-
organization_id: 1,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const { rows: emailDomains } = await pg.sql`
|
|
116
|
-
SELECT domain, verification_type
|
|
117
|
-
FROM email_domains
|
|
118
|
-
WHERE organization_id = 1
|
|
119
|
-
ORDER BY verification_type
|
|
120
|
-
`;
|
|
121
|
-
assert.deepEqual(emailDomains, [
|
|
122
|
-
{ domain: "thousandsons.world", verification_type: "refused" },
|
|
123
|
-
]);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("should reject a pending domain", async () => {
|
|
127
|
-
await pg.sql`
|
|
128
|
-
INSERT INTO organizations
|
|
129
|
-
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
130
|
-
VALUES
|
|
131
|
-
(1, 'Black Legion', 'Black Legion Warband', '👁️', '4444-04-04', '4444-04-04')
|
|
132
|
-
;
|
|
133
|
-
`;
|
|
134
|
-
await pg.sql`
|
|
135
|
-
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
136
|
-
VALUES (1, 'blacklegion.world', 'not_verified_yet')
|
|
137
|
-
`;
|
|
138
|
-
|
|
139
|
-
await markDomainAsVerified({
|
|
140
|
-
domain: "blacklegion.world",
|
|
141
|
-
domain_verification_type: "refused",
|
|
142
|
-
organization_id: 1,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const { rows: emailDomains } = await pg.sql`
|
|
146
|
-
SELECT domain, verification_type
|
|
147
|
-
FROM email_domains
|
|
148
|
-
WHERE organization_id = 1
|
|
149
|
-
ORDER BY verification_type
|
|
150
|
-
`;
|
|
151
|
-
assert.deepEqual(emailDomains, [
|
|
152
|
-
{ domain: "blacklegion.world", verification_type: "refused" },
|
|
153
|
-
]);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("rejecting a domain should not demote an already domain-verified member", async () => {
|
|
157
|
-
await pg.sql`
|
|
158
|
-
INSERT INTO organizations
|
|
159
|
-
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
160
|
-
VALUES
|
|
161
|
-
(1, 'Word Bearers', 'Word Bearers Legion', '🔥', '4444-04-04', '4444-04-04')
|
|
162
|
-
;
|
|
163
|
-
`;
|
|
164
|
-
await pg.sql`
|
|
165
|
-
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
166
|
-
VALUES (1, 'lorgar.aurelian@wordbearers.world', '4444-04-04', '4444-04-04', 'Lorgar', 'Aurelian', '0', 'Primarque')
|
|
167
|
-
`;
|
|
168
|
-
await pg.sql`
|
|
169
|
-
INSERT INTO users_organizations
|
|
170
|
-
(user_id, organization_id, created_at, updated_at, is_external, verification_type)
|
|
171
|
-
VALUES
|
|
172
|
-
(1, 1, '4444-04-04', '4444-04-04', false, 'domain')
|
|
173
|
-
;
|
|
174
|
-
`;
|
|
175
|
-
await pg.sql`
|
|
176
|
-
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
177
|
-
VALUES (1, 'wordbearers.world', 'not_verified_yet')
|
|
178
|
-
`;
|
|
179
|
-
|
|
180
|
-
await markDomainAsVerified({
|
|
181
|
-
domain: "wordbearers.world",
|
|
182
|
-
domain_verification_type: "refused",
|
|
183
|
-
organization_id: 1,
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
const { rows: userLinks } = await pg.sql`
|
|
187
|
-
SELECT user_id, verification_type
|
|
188
|
-
FROM users_organizations
|
|
189
|
-
WHERE organization_id = 1
|
|
190
|
-
`;
|
|
191
|
-
assert.deepEqual(userLinks, [{ user_id: 1, verification_type: "domain" }]);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it("approving a domain should only promote eligible member links", async () => {
|
|
195
|
-
await pg.sql`
|
|
196
|
-
INSERT INTO organizations
|
|
197
|
-
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
198
|
-
VALUES
|
|
199
|
-
(1, 'Emperor''s Children', 'Emperor''s Children Legion', '🎭', '4444-04-04', '4444-04-04')
|
|
200
|
-
;
|
|
201
|
-
`;
|
|
202
|
-
await pg.sql`
|
|
203
|
-
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
204
|
-
VALUES
|
|
205
|
-
(1, 'fulgrim@emperorschildren.world', '4444-04-04', '4444-04-04', 'Fulgrim', 'Primarque', '0', 'Primarque'),
|
|
206
|
-
(2, 'lucius@emperorschildren.world', '4444-04-04', '4444-04-04', 'Lucius', 'The Eternal', '0', 'Champion')
|
|
207
|
-
;
|
|
208
|
-
`;
|
|
209
|
-
await pg.sql`
|
|
210
|
-
INSERT INTO users_organizations
|
|
211
|
-
(user_id, organization_id, created_at, updated_at, is_external, verification_type)
|
|
212
|
-
VALUES
|
|
213
|
-
(1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle'),
|
|
214
|
-
(2, 1, '4444-04-04', '4444-04-04', false, 'organization_dirigeant')
|
|
215
|
-
;
|
|
216
|
-
`;
|
|
217
|
-
await pg.sql`
|
|
218
|
-
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
219
|
-
VALUES (1, 'emperorschildren.world', 'not_verified_yet')
|
|
220
|
-
`;
|
|
221
|
-
|
|
222
|
-
await markDomainAsVerified({
|
|
223
|
-
domain: "emperorschildren.world",
|
|
224
|
-
domain_verification_type: "verified",
|
|
225
|
-
organization_id: 1,
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
const { rows: userLinks } = await pg.sql`
|
|
229
|
-
SELECT user_id, verification_type
|
|
230
|
-
FROM users_organizations
|
|
231
|
-
WHERE organization_id = 1
|
|
232
|
-
ORDER BY user_id
|
|
233
|
-
`;
|
|
234
|
-
assert.deepEqual(userLinks, [
|
|
235
|
-
{ user_id: 1, verification_type: "domain" },
|
|
236
|
-
{ user_id: 2, verification_type: "organization_dirigeant" },
|
|
237
|
-
]);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it("❎ throws NotFoundError for unknown organization", async () => {
|
|
241
|
-
await assert.rejects(
|
|
242
|
-
markDomainAsVerified({
|
|
243
|
-
domain: "darkangels.world",
|
|
244
|
-
domain_verification_type: "verified",
|
|
245
|
-
organization_id: 999,
|
|
246
|
-
}),
|
|
247
|
-
new NotFoundError(""),
|
|
248
|
-
);
|
|
249
|
-
});
|
|
250
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type { Context } from "#src/connectors";
|
|
4
|
-
import { NotFoundError } from "#src/errors";
|
|
5
|
-
import { assignUserVerificationTypeToDomainFactory } from "#src/managers/user";
|
|
6
|
-
import {
|
|
7
|
-
type EmailDomainApprovedVerificationType,
|
|
8
|
-
EmailDomainApprovedVerificationValues,
|
|
9
|
-
type EmailDomainNoPendingVerificationType,
|
|
10
|
-
EmailDomainPendingVerificationValues,
|
|
11
|
-
type EmailDomainRejectedVerificationType,
|
|
12
|
-
EmailDomainRejectedVerificationValues,
|
|
13
|
-
type EmailDomainVerificationType,
|
|
14
|
-
} from "#src/types";
|
|
15
|
-
|
|
16
|
-
import { isEmpty } from "lodash-es";
|
|
17
|
-
import { match } from "ts-pattern";
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
export function markDomainAsVerifiedFactory(context: Context) {
|
|
22
|
-
const assignUserVerificationTypeToDomain =
|
|
23
|
-
assignUserVerificationTypeToDomainFactory(context);
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
repository: { email_domains, organizations },
|
|
27
|
-
} = context;
|
|
28
|
-
|
|
29
|
-
return async function markDomainAsVerified({
|
|
30
|
-
organization_id,
|
|
31
|
-
domain,
|
|
32
|
-
domain_verification_type,
|
|
33
|
-
}: {
|
|
34
|
-
organization_id: number;
|
|
35
|
-
domain: string;
|
|
36
|
-
domain_verification_type: EmailDomainNoPendingVerificationType;
|
|
37
|
-
}) {
|
|
38
|
-
const organization = await organizations.findById(organization_id);
|
|
39
|
-
|
|
40
|
-
if (isEmpty(organization)) {
|
|
41
|
-
throw new NotFoundError();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return match(domain_verification_type)
|
|
45
|
-
.with(
|
|
46
|
-
...EmailDomainApprovedVerificationValues,
|
|
47
|
-
async (approved_verification_type) => {
|
|
48
|
-
await assignUserVerificationTypeToDomain(organization_id, domain);
|
|
49
|
-
return markDomainAsApproved({
|
|
50
|
-
organization_id,
|
|
51
|
-
domain,
|
|
52
|
-
domain_verification_type: approved_verification_type,
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
)
|
|
56
|
-
.with(
|
|
57
|
-
...EmailDomainRejectedVerificationValues,
|
|
58
|
-
(rejected_verification_type) =>
|
|
59
|
-
markDomainAsRejected({
|
|
60
|
-
organization_id,
|
|
61
|
-
domain,
|
|
62
|
-
domain_verification_type: rejected_verification_type,
|
|
63
|
-
}),
|
|
64
|
-
)
|
|
65
|
-
.exhaustive();
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
async function markDomainAsApproved({
|
|
69
|
-
organization_id,
|
|
70
|
-
domain,
|
|
71
|
-
domain_verification_type,
|
|
72
|
-
}: {
|
|
73
|
-
organization_id: number;
|
|
74
|
-
domain: string;
|
|
75
|
-
domain_verification_type: EmailDomainApprovedVerificationType;
|
|
76
|
-
}) {
|
|
77
|
-
await email_domains.deleteEmailDomainsByVerificationTypes({
|
|
78
|
-
organization_id,
|
|
79
|
-
domain,
|
|
80
|
-
domain_verification_types: [
|
|
81
|
-
...EmailDomainApprovedVerificationValues,
|
|
82
|
-
...EmailDomainPendingVerificationValues,
|
|
83
|
-
...EmailDomainRejectedVerificationValues,
|
|
84
|
-
],
|
|
85
|
-
});
|
|
86
|
-
return email_domains.addDomain({
|
|
87
|
-
organization_id,
|
|
88
|
-
domain,
|
|
89
|
-
verification_type:
|
|
90
|
-
domain_verification_type as EmailDomainVerificationType,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function markDomainAsRejected({
|
|
95
|
-
organization_id,
|
|
96
|
-
domain,
|
|
97
|
-
domain_verification_type,
|
|
98
|
-
}: {
|
|
99
|
-
organization_id: number;
|
|
100
|
-
domain: string;
|
|
101
|
-
domain_verification_type: EmailDomainRejectedVerificationType;
|
|
102
|
-
}) {
|
|
103
|
-
await email_domains.deleteEmailDomainsByVerificationTypes({
|
|
104
|
-
organization_id,
|
|
105
|
-
domain,
|
|
106
|
-
domain_verification_types: [
|
|
107
|
-
...EmailDomainApprovedVerificationValues,
|
|
108
|
-
...EmailDomainPendingVerificationValues,
|
|
109
|
-
...EmailDomainRejectedVerificationValues,
|
|
110
|
-
],
|
|
111
|
-
});
|
|
112
|
-
return email_domains.addDomain({
|
|
113
|
-
organization_id,
|
|
114
|
-
domain,
|
|
115
|
-
verification_type:
|
|
116
|
-
domain_verification_type as EmailDomainVerificationType,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export type MarkDomainAsVerifiedHandler = ReturnType<
|
|
122
|
-
typeof markDomainAsVerifiedFactory
|
|
123
|
-
>;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { context, emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
-
import assert from "node:assert/strict";
|
|
5
|
-
import { before, beforeEach, describe, it } from "node:test";
|
|
6
|
-
import { assignUserVerificationTypeToDomainFactory } from "./assign-user-verification-type-to-domain.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const assignUserVerificationTypeToDomain =
|
|
11
|
-
assignUserVerificationTypeToDomainFactory(context);
|
|
12
|
-
|
|
13
|
-
describe("assignUserVerificationTypeToDomain", () => {
|
|
14
|
-
before(migrate);
|
|
15
|
-
beforeEach(emptyDatabase);
|
|
16
|
-
|
|
17
|
-
it("should update some organization members", async () => {
|
|
18
|
-
await pg.sql`
|
|
19
|
-
INSERT INTO organizations
|
|
20
|
-
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
21
|
-
VALUES
|
|
22
|
-
(1, 'Dark Angels', 'Dark Angels Legion', '🦁', '4444-04-04', '4444-04-04')
|
|
23
|
-
;
|
|
24
|
-
`;
|
|
25
|
-
// user from a different domain — should not be updated
|
|
26
|
-
await pg.sql`
|
|
27
|
-
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
28
|
-
VALUES (1, 'foo@bar.world', '4444-04-04', '4444-04-04', 'Foo', 'Bar', '0', 'None')
|
|
29
|
-
`;
|
|
30
|
-
// user matching domain but already "verified" — should not be updated
|
|
31
|
-
await pg.sql`
|
|
32
|
-
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
33
|
-
VALUES (2, 'foo@darkangels.world', '4444-04-04', '4444-04-04', 'Foo', 'DA', '0', 'None')
|
|
34
|
-
`;
|
|
35
|
-
// user with no_validation_means_available — should be updated
|
|
36
|
-
await pg.sql`
|
|
37
|
-
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
38
|
-
VALUES (3, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', '0', 'Primarque')
|
|
39
|
-
`;
|
|
40
|
-
// user with no_verification_means_for_entreprise_unipersonnelle — should be updated
|
|
41
|
-
await pg.sql`
|
|
42
|
-
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
43
|
-
VALUES (4, 'cat.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Cat', 'El''Jonson', '0', 'Scout')
|
|
44
|
-
`;
|
|
45
|
-
// user with no_verification_means_for_small_association — should be updated
|
|
46
|
-
await pg.sql`
|
|
47
|
-
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
48
|
-
VALUES (5, 'tiger.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Tiger', 'El''Jonson', '0', 'Scout')
|
|
49
|
-
`;
|
|
50
|
-
// user with domain_not_verified_yet — should be updated
|
|
51
|
-
await pg.sql`
|
|
52
|
-
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
53
|
-
VALUES (6, 'mouse.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Mouse', 'El''Jonson', '0', 'Scout')
|
|
54
|
-
`;
|
|
55
|
-
|
|
56
|
-
// link all users to the organization
|
|
57
|
-
await pg.sql`
|
|
58
|
-
INSERT INTO users_organizations
|
|
59
|
-
(user_id, organization_id, created_at, updated_at, is_external, verification_type)
|
|
60
|
-
VALUES (1, 1, '4444-04-04', '4444-04-04', false, 'no_validation_means_available'),
|
|
61
|
-
(2, 1, '4444-04-04', '4444-04-04', false, 'verified'),
|
|
62
|
-
(3, 1, '4444-04-04', '4444-04-04', false, 'no_validation_means_available'),
|
|
63
|
-
(4, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle'),
|
|
64
|
-
(5, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_small_association'),
|
|
65
|
-
(6, 1, '4444-04-04', '4444-04-04', false, 'domain_not_verified_yet')
|
|
66
|
-
;
|
|
67
|
-
`;
|
|
68
|
-
|
|
69
|
-
await assignUserVerificationTypeToDomain(1, "darkangels.world");
|
|
70
|
-
|
|
71
|
-
// verify that the 4 matching users were updated to "domain"
|
|
72
|
-
const { rows } = await pg.sql`
|
|
73
|
-
SELECT user_id, verification_type
|
|
74
|
-
FROM users_organizations
|
|
75
|
-
WHERE organization_id = 1
|
|
76
|
-
ORDER BY user_id
|
|
77
|
-
`;
|
|
78
|
-
|
|
79
|
-
assert.deepEqual(rows, [
|
|
80
|
-
{ user_id: 1, verification_type: "no_validation_means_available" }, // different domain
|
|
81
|
-
{ user_id: 2, verification_type: "verified" }, // already verified
|
|
82
|
-
{ user_id: 3, verification_type: "domain" },
|
|
83
|
-
{ user_id: 4, verification_type: "domain" },
|
|
84
|
-
{ user_id: 5, verification_type: "domain" },
|
|
85
|
-
{ user_id: 6, verification_type: "domain" },
|
|
86
|
-
]);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("❎ should update nothing if no organization members", async () => {
|
|
90
|
-
await pg.sql`
|
|
91
|
-
INSERT INTO organizations
|
|
92
|
-
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
93
|
-
VALUES
|
|
94
|
-
(1, 'Empty', 'Empty Org', '🫥', '4444-04-04', '4444-04-04')
|
|
95
|
-
;
|
|
96
|
-
`;
|
|
97
|
-
|
|
98
|
-
await assignUserVerificationTypeToDomain(1, "darkangels.world");
|
|
99
|
-
|
|
100
|
-
const { rows } = await pg.sql`
|
|
101
|
-
SELECT * FROM users_organizations WHERE organization_id = 1
|
|
102
|
-
`;
|
|
103
|
-
assert.deepEqual(rows, []);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type { Context } from "#src/connectors";
|
|
4
|
-
import { LinkEnum, SuperWeakLinkEnum, UnverifiedLinkEnum } from "#src/types";
|
|
5
|
-
import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
export function assignUserVerificationTypeToDomainFactory({
|
|
10
|
-
repository: { organizations, users_organizations },
|
|
11
|
-
}: Context) {
|
|
12
|
-
return async function assignUserVerificationTypeToDomain(
|
|
13
|
-
organization_id: number,
|
|
14
|
-
domain: string,
|
|
15
|
-
) {
|
|
16
|
-
const usersInOrganization = await organizations.findUsers(organization_id);
|
|
17
|
-
|
|
18
|
-
await Promise.all(
|
|
19
|
-
usersInOrganization.map(
|
|
20
|
-
({ id: user_id, email, verification_type: link_verification_type }) => {
|
|
21
|
-
const userDomain = getEmailDomain(email);
|
|
22
|
-
if (
|
|
23
|
-
userDomain === domain &&
|
|
24
|
-
(UnverifiedLinkEnum.safeParse(link_verification_type).success ||
|
|
25
|
-
SuperWeakLinkEnum.safeParse(link_verification_type).success)
|
|
26
|
-
) {
|
|
27
|
-
return users_organizations.update(
|
|
28
|
-
{ organization_id, user_id },
|
|
29
|
-
{
|
|
30
|
-
verification_type: LinkEnum.enum.domain,
|
|
31
|
-
},
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return null;
|
|
36
|
-
},
|
|
37
|
-
),
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./assign-user-verification-type-to-domain.js";
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
-
import assert from "node:assert/strict";
|
|
5
|
-
import { before, beforeEach, describe, it } from "node:test";
|
|
6
|
-
import { deleteEmailDomainsByVerificationTypesFactory } from "./delete-email-domains-by-verification-types.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const deleteEmailDomainsByVerificationTypes =
|
|
11
|
-
deleteEmailDomainsByVerificationTypesFactory({
|
|
12
|
-
pg: pg as any,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe("deleteEmailDomainsByVerificationTypesFactory", function () {
|
|
16
|
-
before(migrate);
|
|
17
|
-
beforeEach(emptyDatabase);
|
|
18
|
-
|
|
19
|
-
it("should delete domain verification type NULL and 'verified'", async () => {
|
|
20
|
-
await pg.sql`
|
|
21
|
-
INSERT INTO organizations
|
|
22
|
-
(id, siret, created_at, updated_at)
|
|
23
|
-
VALUES
|
|
24
|
-
(1, '66204244933106', '3333-03-03', '3333-04-04')
|
|
25
|
-
;
|
|
26
|
-
`;
|
|
27
|
-
|
|
28
|
-
await pg.sql`
|
|
29
|
-
INSERT INTO email_domains
|
|
30
|
-
(domain, organization_id, verification_type)
|
|
31
|
-
VALUES
|
|
32
|
-
('darkangels.world', 1, 'not_verified_yet'),
|
|
33
|
-
('darkangels.world', 1, 'verified')
|
|
34
|
-
;
|
|
35
|
-
`;
|
|
36
|
-
|
|
37
|
-
const result = await deleteEmailDomainsByVerificationTypes({
|
|
38
|
-
domain: "darkangels.world",
|
|
39
|
-
organization_id: 1,
|
|
40
|
-
domain_verification_types: ["not_verified_yet", "verified"],
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
assert.deepEqual(result, {
|
|
44
|
-
affectedRows: 2,
|
|
45
|
-
fields: [],
|
|
46
|
-
rows: [],
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
DatabaseContext,
|
|
5
|
-
EmailDomain,
|
|
6
|
-
EmailDomainVerificationType,
|
|
7
|
-
} from "#src/types";
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
export function deleteEmailDomainsByVerificationTypesFactory({
|
|
12
|
-
pg,
|
|
13
|
-
}: DatabaseContext) {
|
|
14
|
-
return async function deleteEmailDomainsByVerificationTypes({
|
|
15
|
-
organization_id,
|
|
16
|
-
domain,
|
|
17
|
-
domain_verification_types,
|
|
18
|
-
}: {
|
|
19
|
-
organization_id: EmailDomain["organization_id"];
|
|
20
|
-
domain_verification_types: EmailDomainVerificationType[];
|
|
21
|
-
domain: EmailDomain["domain"];
|
|
22
|
-
}) {
|
|
23
|
-
const SQL_VERIFICATION_TYPES = domain_verification_types
|
|
24
|
-
.map((type) => `verification_type = '${type}'`)
|
|
25
|
-
.join(" OR ");
|
|
26
|
-
|
|
27
|
-
return pg.query(
|
|
28
|
-
`
|
|
29
|
-
DELETE FROM email_domains
|
|
30
|
-
WHERE
|
|
31
|
-
${[
|
|
32
|
-
"organization_id = $1",
|
|
33
|
-
"domain = $2",
|
|
34
|
-
`(${SQL_VERIFICATION_TYPES})`,
|
|
35
|
-
].join(" AND ")}
|
|
36
|
-
;
|
|
37
|
-
`,
|
|
38
|
-
[organization_id, domain],
|
|
39
|
-
);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type DeleteEmailDomainsByVerificationTypesHandler = ReturnType<
|
|
44
|
-
typeof deleteEmailDomainsByVerificationTypesFactory
|
|
45
|
-
>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
-
import assert from "node:assert/strict";
|
|
5
|
-
import { before, beforeEach, describe, it } from "node:test";
|
|
6
|
-
import { deleteFranceconnectUserinfoFactory } from "./delete-franceconnect-userinfo.js";
|
|
7
|
-
import { findFranceconnectUserinfoFactory } from "./find-franceconnect-userinfo.js";
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
const deleteFranceconnectUserinfo = deleteFranceconnectUserinfoFactory({
|
|
12
|
-
pg: pg as any,
|
|
13
|
-
});
|
|
14
|
-
const findFranceconnectUserinfo = findFranceconnectUserinfoFactory({
|
|
15
|
-
pg: pg as any,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe("deleteFranceConnectUserInfo", () => {
|
|
19
|
-
before(migrate);
|
|
20
|
-
beforeEach(emptyDatabase);
|
|
21
|
-
|
|
22
|
-
it("should delete franceconnect user info", async () => {
|
|
23
|
-
await pg.sql`
|
|
24
|
-
INSERT INTO users
|
|
25
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
26
|
-
VALUES
|
|
27
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
28
|
-
;
|
|
29
|
-
`;
|
|
30
|
-
await pg.sql`
|
|
31
|
-
INSERT INTO franceconnect_userinfo
|
|
32
|
-
(user_id, birthdate, birthplace, family_name, gender, given_name, preferred_username, sub, created_at, updated_at)
|
|
33
|
-
VALUES
|
|
34
|
-
(1, '8888-08-08', 'Caliban', 'El''Jonson', 'male', 'Li', 'Li', 'abcdefghijklmnopqrstuvwxyz', '4444-04-04', '4444-04-04')
|
|
35
|
-
;
|
|
36
|
-
`;
|
|
37
|
-
|
|
38
|
-
await deleteFranceconnectUserinfo(1);
|
|
39
|
-
|
|
40
|
-
const user = await findFranceconnectUserinfo(1);
|
|
41
|
-
assert.equal(user, undefined);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should not throw when deleting a user_id with no row", async () => {
|
|
45
|
-
await assert.doesNotReject(() => deleteFranceconnectUserinfo(42));
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type { DatabaseContext } from "#src/types";
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
export function deleteFranceconnectUserinfoFactory({ pg }: DatabaseContext) {
|
|
8
|
-
return async function deleteFranceconnectUserinfo(user_id: number) {
|
|
9
|
-
return pg.query(
|
|
10
|
-
`
|
|
11
|
-
DELETE FROM franceconnect_userinfo
|
|
12
|
-
WHERE user_id = $1
|
|
13
|
-
`,
|
|
14
|
-
[user_id],
|
|
15
|
-
);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type DeleteFranceconnectUserinfoHandler = ReturnType<
|
|
20
|
-
typeof deleteFranceconnectUserinfoFactory
|
|
21
|
-
>;
|