@proconnect-gouv/proconnect.identite.runtime 0.4.0 → 0.6.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 +30 -0
- package/dist/activity/activity-context-schemas.d.ts +51 -0
- package/dist/activity/activity-context-schemas.d.ts.map +1 -1
- package/dist/certification/activities.d.ts +64 -0
- package/dist/certification/activities.d.ts.map +1 -0
- package/dist/certification/activities.js +78 -0
- package/dist/certification/index.d.ts +2 -0
- package/dist/certification/index.d.ts.map +1 -0
- package/dist/certification/index.js +2 -0
- package/dist/domains/activities.d.ts +22 -0
- package/dist/domains/activities.d.ts.map +1 -1
- package/dist/domains/activities.js +20 -1
- package/dist/domains/change-email-domain-verification.d.ts +29 -0
- package/dist/domains/change-email-domain-verification.d.ts.map +1 -0
- package/dist/domains/change-email-domain-verification.js +167 -0
- package/dist/domains/index.d.ts +1 -1
- package/dist/domains/index.d.ts.map +1 -1
- package/dist/domains/index.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/runtime/create-identite-runtime.d.ts +60 -20
- package/dist/runtime/create-identite-runtime.d.ts.map +1 -1
- package/dist/runtime/create-identite-runtime.js +13 -3
- package/dist/users/activities.d.ts +29 -0
- package/dist/users/activities.d.ts.map +1 -1
- package/dist/users/activities.js +20 -0
- package/dist/users/change-password.d.ts +16 -0
- package/dist/users/change-password.d.ts.map +1 -0
- package/dist/users/change-password.js +38 -0
- package/dist/users/index.d.ts +2 -0
- package/dist/users/index.d.ts.map +1 -1
- package/dist/users/index.js +2 -0
- package/dist/users/update-personal-informations.d.ts +21 -0
- package/dist/users/update-personal-informations.d.ts.map +1 -0
- package/dist/users/update-personal-informations.js +53 -0
- package/package.json +3 -3
- package/src/certification/activities.test.ts +128 -0
- package/src/certification/activities.ts +103 -0
- package/src/certification/index.ts +3 -0
- package/src/domains/activities.ts +23 -1
- package/src/domains/{mark-domain-as-verified.test.ts → change-email-domain-verification.test.ts} +98 -8
- package/src/domains/change-email-domain-verification.ts +305 -0
- package/src/domains/index.ts +1 -1
- package/src/index.ts +1 -0
- package/src/runtime/create-identite-runtime.test.ts +20 -28
- package/src/runtime/create-identite-runtime.ts +18 -3
- package/src/users/activities.ts +21 -0
- package/src/users/change-password.test.ts +91 -0
- package/src/users/change-password.ts +64 -0
- package/src/users/index.ts +2 -0
- package/src/users/update-personal-informations.test.ts +113 -0
- package/src/users/update-personal-informations.ts +97 -0
- package/dist/domains/mark-domain-as-verified.d.ts +0 -25
- package/dist/domains/mark-domain-as-verified.d.ts.map +0 -1
- package/dist/domains/mark-domain-as-verified.js +0 -103
- package/src/domains/mark-domain-as-verified.ts +0 -174
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
EmailDomainApprovedVerificationEnum,
|
|
5
|
+
EmailDomainRejectedVerificationEnum,
|
|
6
|
+
} from "@proconnect-gouv/proconnect.identite/types";
|
|
4
7
|
import * as z from "zod";
|
|
5
8
|
|
|
6
9
|
//
|
|
7
10
|
|
|
8
11
|
export const domainActivities = {
|
|
12
|
+
"domain.refused": z.object({
|
|
13
|
+
inputs: z.object({
|
|
14
|
+
domain: z.string(),
|
|
15
|
+
verification_type: EmailDomainRejectedVerificationEnum,
|
|
16
|
+
}),
|
|
17
|
+
outcome: z.object({
|
|
18
|
+
email_domain_id: z.number(),
|
|
19
|
+
replaced_verification_types: z.array(z.string()),
|
|
20
|
+
}),
|
|
21
|
+
}),
|
|
22
|
+
"domain.removed": z.object({
|
|
23
|
+
inputs: z.object({
|
|
24
|
+
domain: z.string(),
|
|
25
|
+
}),
|
|
26
|
+
outcome: z.object({
|
|
27
|
+
email_domain_id: z.number(),
|
|
28
|
+
previous_verification_type: z.string(),
|
|
29
|
+
}),
|
|
30
|
+
}),
|
|
9
31
|
"domain.verified": z.object({
|
|
10
32
|
inputs: z.object({
|
|
11
33
|
domain: z.string(),
|
package/src/domains/{mark-domain-as-verified.test.ts → change-email-domain-verification.test.ts}
RENAMED
|
@@ -102,7 +102,7 @@ async function setup() {
|
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
describe("
|
|
105
|
+
describe("changeEmailDomainVerification", () => {
|
|
106
106
|
before(() => {
|
|
107
107
|
mock.timers.enable({ apis: ["Date"], now: new Date("5555-05-05") });
|
|
108
108
|
});
|
|
@@ -111,10 +111,10 @@ describe("markDomainAsVerified", () => {
|
|
|
111
111
|
const { db, runtime } = await setup();
|
|
112
112
|
const before = await snapshot(db);
|
|
113
113
|
|
|
114
|
-
const outcome = await runtime.
|
|
114
|
+
const outcome = await runtime.changeEmailDomainVerification({
|
|
115
115
|
domain: "notfound.world",
|
|
116
|
-
domain_verification_type: "verified",
|
|
117
116
|
organization_id: 404,
|
|
117
|
+
verification_type: "verified",
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
assert.deepEqual(outcome, {
|
|
@@ -128,10 +128,10 @@ describe("markDomainAsVerified", () => {
|
|
|
128
128
|
it("✅ replaces the domain states, promotes the domain members and journals the verification under the moderator and each promotion under the app", async () => {
|
|
129
129
|
const { db, runtime } = await setup();
|
|
130
130
|
|
|
131
|
-
const outcome = await runtime.
|
|
131
|
+
const outcome = await runtime.changeEmailDomainVerification({
|
|
132
132
|
domain: "darkangels.world",
|
|
133
|
-
domain_verification_type: "verified",
|
|
134
133
|
organization_id: 1,
|
|
134
|
+
verification_type: "verified",
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
const verified_domain = await db.query.email_domains.findFirst({
|
|
@@ -140,7 +140,7 @@ describe("markDomainAsVerified", () => {
|
|
|
140
140
|
and(eq(table.domain, "darkangels.world"), eq(table.organization_id, 1)),
|
|
141
141
|
});
|
|
142
142
|
assert.deepEqual(outcome, {
|
|
143
|
-
kind: "
|
|
143
|
+
kind: "domain_verification_changed",
|
|
144
144
|
activity_id: 1,
|
|
145
145
|
email_domain: {
|
|
146
146
|
id: verified_domain?.id,
|
|
@@ -154,6 +154,7 @@ describe("markDomainAsVerified", () => {
|
|
|
154
154
|
},
|
|
155
155
|
{ previous_verification_type: "domain_not_verified_yet", user_id: 2 },
|
|
156
156
|
],
|
|
157
|
+
removed_members: [],
|
|
157
158
|
replaced_verification_types: ["not_verified_yet", "refused"],
|
|
158
159
|
});
|
|
159
160
|
assert.deepEqual(
|
|
@@ -303,6 +304,95 @@ describe("markDomainAsVerified", () => {
|
|
|
303
304
|
]);
|
|
304
305
|
});
|
|
305
306
|
|
|
307
|
+
it("✅ refuses the domain, removes every member of the domain and journals the refusal under the moderator and each removal under the app", async () => {
|
|
308
|
+
const { db, runtime } = await setup();
|
|
309
|
+
|
|
310
|
+
const outcome = await runtime.changeEmailDomainVerification({
|
|
311
|
+
domain: "darkangels.world",
|
|
312
|
+
organization_id: 1,
|
|
313
|
+
verification_type: "refused",
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const refused_domain = await db.query.email_domains.findFirst({
|
|
317
|
+
columns: { id: true, verified_at: true },
|
|
318
|
+
where: (table, { and, eq }) =>
|
|
319
|
+
and(eq(table.domain, "darkangels.world"), eq(table.organization_id, 1)),
|
|
320
|
+
});
|
|
321
|
+
assert.deepEqual(outcome, {
|
|
322
|
+
kind: "domain_verification_changed",
|
|
323
|
+
activity_id: 1,
|
|
324
|
+
email_domain: { id: refused_domain?.id, verification_type: "refused" },
|
|
325
|
+
promoted_members: [],
|
|
326
|
+
removed_members: [
|
|
327
|
+
{
|
|
328
|
+
previous_verification_type:
|
|
329
|
+
"no_verification_means_for_entreprise_unipersonnelle",
|
|
330
|
+
user_id: 1,
|
|
331
|
+
},
|
|
332
|
+
{ previous_verification_type: "domain_not_verified_yet", user_id: 2 },
|
|
333
|
+
{ previous_verification_type: "organization_dirigeant", user_id: 3 },
|
|
334
|
+
],
|
|
335
|
+
replaced_verification_types: ["not_verified_yet", "refused"],
|
|
336
|
+
});
|
|
337
|
+
assert.equal(refused_domain?.verified_at, null);
|
|
338
|
+
assert.deepEqual(
|
|
339
|
+
await db.query.users_organizations.findMany({
|
|
340
|
+
columns: { organization_id: true, user_id: true },
|
|
341
|
+
orderBy: (table, { asc }) => [
|
|
342
|
+
asc(table.organization_id),
|
|
343
|
+
asc(table.user_id),
|
|
344
|
+
],
|
|
345
|
+
}),
|
|
346
|
+
[
|
|
347
|
+
{ organization_id: 1, user_id: 4 },
|
|
348
|
+
{ organization_id: 2, user_id: 1 },
|
|
349
|
+
],
|
|
350
|
+
);
|
|
351
|
+
assert.deepEqual(
|
|
352
|
+
(await readActivityLogs(db)).map(
|
|
353
|
+
({ action, actor_ref, cause_activity_id, context, user_id }) => ({
|
|
354
|
+
action,
|
|
355
|
+
actor_ref,
|
|
356
|
+
cause_activity_id,
|
|
357
|
+
context,
|
|
358
|
+
user_id,
|
|
359
|
+
}),
|
|
360
|
+
),
|
|
361
|
+
[
|
|
362
|
+
{
|
|
363
|
+
action: "domain.refused",
|
|
364
|
+
actor_ref: "moderator+verifies-darkangels.world",
|
|
365
|
+
cause_activity_id: null,
|
|
366
|
+
context: {
|
|
367
|
+
inputs: {
|
|
368
|
+
domain: "darkangels.world",
|
|
369
|
+
verification_type: "refused",
|
|
370
|
+
},
|
|
371
|
+
outcome: {
|
|
372
|
+
email_domain_id: refused_domain?.id,
|
|
373
|
+
replaced_verification_types: ["not_verified_yet", "refused"],
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
user_id: null,
|
|
377
|
+
},
|
|
378
|
+
...[
|
|
379
|
+
"no_verification_means_for_entreprise_unipersonnelle",
|
|
380
|
+
"domain_not_verified_yet",
|
|
381
|
+
"organization_dirigeant",
|
|
382
|
+
].map((verification_type, index) => ({
|
|
383
|
+
action: "member.removed",
|
|
384
|
+
actor_ref: "domain.remove_members",
|
|
385
|
+
cause_activity_id: 1,
|
|
386
|
+
context: {
|
|
387
|
+
inputs: {},
|
|
388
|
+
outcome: { is_external: false, verification_type },
|
|
389
|
+
},
|
|
390
|
+
user_id: index + 1,
|
|
391
|
+
})),
|
|
392
|
+
],
|
|
393
|
+
);
|
|
394
|
+
});
|
|
395
|
+
|
|
306
396
|
it("❎ rolls back the domain state and its journal row when a member update fails", async () => {
|
|
307
397
|
const { db, runtime } = await setup();
|
|
308
398
|
await db.execute(sql`
|
|
@@ -313,10 +403,10 @@ describe("markDomainAsVerified", () => {
|
|
|
313
403
|
const before = await snapshot(db);
|
|
314
404
|
|
|
315
405
|
await assert.rejects(
|
|
316
|
-
runtime.
|
|
406
|
+
runtime.changeEmailDomainVerification({
|
|
317
407
|
domain: "darkangels.world",
|
|
318
|
-
domain_verification_type: "verified",
|
|
319
408
|
organization_id: 1,
|
|
409
|
+
verification_type: "verified",
|
|
320
410
|
}),
|
|
321
411
|
(error: Error) =>
|
|
322
412
|
error.cause instanceof Error &&
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { ActivityContexts, RuntimeContext } from "#src/activity";
|
|
4
|
+
import type { IdentiteTransaction } from "#src/database";
|
|
5
|
+
import { insertActivity } from "#src/journal";
|
|
6
|
+
import {
|
|
7
|
+
email_domains,
|
|
8
|
+
users_organizations,
|
|
9
|
+
} from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
10
|
+
import { getMembershipChangesByDomainVerification } from "@proconnect-gouv/proconnect.identite/services/organization";
|
|
11
|
+
import {
|
|
12
|
+
EmailDomainApprovedVerificationValues,
|
|
13
|
+
EmailDomainPendingVerificationValues,
|
|
14
|
+
EmailDomainRejectedVerificationValues,
|
|
15
|
+
LinkEnum,
|
|
16
|
+
type EmailDomainNoPendingVerificationType,
|
|
17
|
+
} from "@proconnect-gouv/proconnect.identite/types";
|
|
18
|
+
import { and, eq, inArray, sql, type SQL } from "drizzle-orm";
|
|
19
|
+
|
|
20
|
+
//
|
|
21
|
+
|
|
22
|
+
type ChangeEmailDomainVerificationOutcome =
|
|
23
|
+
| {
|
|
24
|
+
kind: "domain_verification_changed";
|
|
25
|
+
activity_id: number;
|
|
26
|
+
email_domain: {
|
|
27
|
+
id: number;
|
|
28
|
+
verification_type: EmailDomainNoPendingVerificationType;
|
|
29
|
+
};
|
|
30
|
+
promoted_members: ReadonlyArray<{
|
|
31
|
+
previous_verification_type: string;
|
|
32
|
+
user_id: number;
|
|
33
|
+
}>;
|
|
34
|
+
removed_members: ReadonlyArray<{
|
|
35
|
+
previous_verification_type: string;
|
|
36
|
+
user_id: number;
|
|
37
|
+
}>;
|
|
38
|
+
replaced_verification_types: ReadonlyArray<string>;
|
|
39
|
+
}
|
|
40
|
+
| { kind: "organization_not_found"; organization_id: number };
|
|
41
|
+
|
|
42
|
+
type Member = Awaited<ReturnType<typeof findMembers>>[number];
|
|
43
|
+
|
|
44
|
+
export function changeEmailDomainVerificationFactory({
|
|
45
|
+
actor,
|
|
46
|
+
app,
|
|
47
|
+
db,
|
|
48
|
+
}: RuntimeContext) {
|
|
49
|
+
return function changeEmailDomainVerification({
|
|
50
|
+
domain,
|
|
51
|
+
organization_id,
|
|
52
|
+
verification_type,
|
|
53
|
+
}: {
|
|
54
|
+
domain: string;
|
|
55
|
+
organization_id: number;
|
|
56
|
+
verification_type: EmailDomainNoPendingVerificationType;
|
|
57
|
+
}): Promise<ChangeEmailDomainVerificationOutcome> {
|
|
58
|
+
return db.transaction(async (tx) => {
|
|
59
|
+
const organization = await tx.query.organizations.findFirst({
|
|
60
|
+
columns: { id: true },
|
|
61
|
+
where: (table, { eq }) => eq(table.id, organization_id),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!organization) {
|
|
65
|
+
return { kind: "organization_not_found", organization_id };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const changes = getMembershipChangesByDomainVerification({
|
|
69
|
+
domain,
|
|
70
|
+
members: await findMembers(tx, { organization_id }),
|
|
71
|
+
verification_type,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
switch (changes.kind) {
|
|
75
|
+
case "domain_approved": {
|
|
76
|
+
const { email_domain_id, replaced_verification_types } =
|
|
77
|
+
await replaceEmailDomain(tx, {
|
|
78
|
+
domain,
|
|
79
|
+
organization_id,
|
|
80
|
+
verification_type: changes.verification_type,
|
|
81
|
+
verified_at: sql`now()`,
|
|
82
|
+
});
|
|
83
|
+
const { activity_id } = await insertActivity<ActivityContexts>(tx, {
|
|
84
|
+
action: "domain.verified",
|
|
85
|
+
actor,
|
|
86
|
+
app,
|
|
87
|
+
context: {
|
|
88
|
+
inputs: { domain, verification_type: changes.verification_type },
|
|
89
|
+
outcome: { email_domain_id, replaced_verification_types },
|
|
90
|
+
},
|
|
91
|
+
organization_id,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
await promoteMembers(tx, {
|
|
95
|
+
app,
|
|
96
|
+
cause_activity_id: activity_id,
|
|
97
|
+
members: changes.promoted_members,
|
|
98
|
+
organization_id,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
kind: "domain_verification_changed",
|
|
103
|
+
activity_id,
|
|
104
|
+
email_domain: { id: email_domain_id, verification_type },
|
|
105
|
+
promoted_members:
|
|
106
|
+
changes.promoted_members.map(toPreviousMembership),
|
|
107
|
+
removed_members: [],
|
|
108
|
+
replaced_verification_types,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
case "domain_refused": {
|
|
112
|
+
const { email_domain_id, replaced_verification_types } =
|
|
113
|
+
await replaceEmailDomain(tx, {
|
|
114
|
+
domain,
|
|
115
|
+
organization_id,
|
|
116
|
+
verification_type: changes.verification_type,
|
|
117
|
+
verified_at: null,
|
|
118
|
+
});
|
|
119
|
+
const { activity_id } = await insertActivity<ActivityContexts>(tx, {
|
|
120
|
+
action: "domain.refused",
|
|
121
|
+
actor,
|
|
122
|
+
app,
|
|
123
|
+
context: {
|
|
124
|
+
inputs: { domain, verification_type: changes.verification_type },
|
|
125
|
+
outcome: { email_domain_id, replaced_verification_types },
|
|
126
|
+
},
|
|
127
|
+
organization_id,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
await removeMembers(tx, {
|
|
131
|
+
app,
|
|
132
|
+
cause_activity_id: activity_id,
|
|
133
|
+
members: changes.removed_members,
|
|
134
|
+
organization_id,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
kind: "domain_verification_changed",
|
|
139
|
+
activity_id,
|
|
140
|
+
email_domain: { id: email_domain_id, verification_type },
|
|
141
|
+
promoted_members: [],
|
|
142
|
+
removed_members: changes.removed_members.map(toPreviousMembership),
|
|
143
|
+
replaced_verification_types,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
default: {
|
|
147
|
+
const unhandled_changes: never = changes;
|
|
148
|
+
throw new Error(
|
|
149
|
+
`Unhandled membership changes: ${JSON.stringify(unhandled_changes)}`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
//
|
|
158
|
+
|
|
159
|
+
async function findMembers(
|
|
160
|
+
tx: IdentiteTransaction,
|
|
161
|
+
{ organization_id }: { organization_id: number },
|
|
162
|
+
) {
|
|
163
|
+
const memberships = await tx.query.users_organizations.findMany({
|
|
164
|
+
columns: { is_external: true, user_id: true, verification_type: true },
|
|
165
|
+
where: (table, { eq }) => eq(table.organization_id, organization_id),
|
|
166
|
+
with: { user: { columns: { email: true } } },
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
return memberships.map(
|
|
170
|
+
({ is_external, user: { email }, user_id, verification_type }) => ({
|
|
171
|
+
email,
|
|
172
|
+
is_external,
|
|
173
|
+
user_id,
|
|
174
|
+
verification_type,
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function replaceEmailDomain(
|
|
180
|
+
tx: IdentiteTransaction,
|
|
181
|
+
{
|
|
182
|
+
domain,
|
|
183
|
+
organization_id,
|
|
184
|
+
verification_type,
|
|
185
|
+
verified_at,
|
|
186
|
+
}: {
|
|
187
|
+
domain: string;
|
|
188
|
+
organization_id: number;
|
|
189
|
+
verification_type: EmailDomainNoPendingVerificationType;
|
|
190
|
+
verified_at: SQL | null;
|
|
191
|
+
},
|
|
192
|
+
) {
|
|
193
|
+
const replaced = await tx
|
|
194
|
+
.delete(email_domains)
|
|
195
|
+
.where(
|
|
196
|
+
and(
|
|
197
|
+
eq(email_domains.organization_id, organization_id),
|
|
198
|
+
eq(email_domains.domain, domain),
|
|
199
|
+
inArray(email_domains.verification_type, [
|
|
200
|
+
...EmailDomainApprovedVerificationValues,
|
|
201
|
+
...EmailDomainPendingVerificationValues,
|
|
202
|
+
...EmailDomainRejectedVerificationValues,
|
|
203
|
+
]),
|
|
204
|
+
),
|
|
205
|
+
)
|
|
206
|
+
.returning({ verification_type: email_domains.verification_type });
|
|
207
|
+
|
|
208
|
+
const [email_domain] = await tx
|
|
209
|
+
.insert(email_domains)
|
|
210
|
+
.values({ domain, organization_id, verification_type, verified_at })
|
|
211
|
+
.returning({ id: email_domains.id });
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
email_domain_id: email_domain.id,
|
|
215
|
+
replaced_verification_types: replaced.map(
|
|
216
|
+
({ verification_type }) => verification_type,
|
|
217
|
+
),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function promoteMembers(
|
|
222
|
+
tx: IdentiteTransaction,
|
|
223
|
+
{
|
|
224
|
+
app,
|
|
225
|
+
cause_activity_id,
|
|
226
|
+
members,
|
|
227
|
+
organization_id,
|
|
228
|
+
}: Pick<RuntimeContext, "app"> & {
|
|
229
|
+
cause_activity_id: number;
|
|
230
|
+
members: ReadonlyArray<Member>;
|
|
231
|
+
organization_id: number;
|
|
232
|
+
},
|
|
233
|
+
) {
|
|
234
|
+
if (members.length === 0) return;
|
|
235
|
+
|
|
236
|
+
await tx
|
|
237
|
+
.update(users_organizations)
|
|
238
|
+
.set({ updated_at: sql`now()`, verification_type: LinkEnum.enum.domain })
|
|
239
|
+
.where(
|
|
240
|
+
and(
|
|
241
|
+
eq(users_organizations.organization_id, organization_id),
|
|
242
|
+
inArray(
|
|
243
|
+
users_organizations.user_id,
|
|
244
|
+
members.map(({ user_id }) => user_id),
|
|
245
|
+
),
|
|
246
|
+
),
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
for (const { user_id, verification_type } of members) {
|
|
250
|
+
await insertActivity<ActivityContexts>(tx, {
|
|
251
|
+
action: "member.promoted",
|
|
252
|
+
actor: { type: "app", job: "domain.promote_members" },
|
|
253
|
+
app,
|
|
254
|
+
cause_activity_id,
|
|
255
|
+
context: {
|
|
256
|
+
inputs: { previous_verification_type: verification_type },
|
|
257
|
+
outcome: { verification_type: LinkEnum.enum.domain },
|
|
258
|
+
},
|
|
259
|
+
organization_id,
|
|
260
|
+
user_id,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function removeMembers(
|
|
266
|
+
tx: IdentiteTransaction,
|
|
267
|
+
{
|
|
268
|
+
app,
|
|
269
|
+
cause_activity_id,
|
|
270
|
+
members,
|
|
271
|
+
organization_id,
|
|
272
|
+
}: Pick<RuntimeContext, "app"> & {
|
|
273
|
+
cause_activity_id: number;
|
|
274
|
+
members: ReadonlyArray<Member>;
|
|
275
|
+
organization_id: number;
|
|
276
|
+
},
|
|
277
|
+
) {
|
|
278
|
+
if (members.length === 0) return;
|
|
279
|
+
|
|
280
|
+
await tx.delete(users_organizations).where(
|
|
281
|
+
and(
|
|
282
|
+
eq(users_organizations.organization_id, organization_id),
|
|
283
|
+
inArray(
|
|
284
|
+
users_organizations.user_id,
|
|
285
|
+
members.map(({ user_id }) => user_id),
|
|
286
|
+
),
|
|
287
|
+
),
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
for (const { is_external, user_id, verification_type } of members) {
|
|
291
|
+
await insertActivity<ActivityContexts>(tx, {
|
|
292
|
+
action: "member.removed",
|
|
293
|
+
actor: { type: "app", job: "domain.remove_members" },
|
|
294
|
+
app,
|
|
295
|
+
cause_activity_id,
|
|
296
|
+
context: { inputs: {}, outcome: { is_external, verification_type } },
|
|
297
|
+
organization_id,
|
|
298
|
+
user_id,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function toPreviousMembership({ user_id, verification_type }: Member) {
|
|
304
|
+
return { previous_verification_type: verification_type, user_id };
|
|
305
|
+
}
|
package/src/domains/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -11,31 +11,23 @@ import * as z from "zod";
|
|
|
11
11
|
//
|
|
12
12
|
|
|
13
13
|
const hyyypertool_activities = {
|
|
14
|
-
"
|
|
14
|
+
"moderation.commented": z.object({
|
|
15
15
|
inputs: z.object({
|
|
16
|
-
|
|
17
|
-
verification_type: z.literal("refused"),
|
|
16
|
+
comment: z.string(),
|
|
18
17
|
}),
|
|
19
18
|
outcome: z.object({
|
|
20
|
-
|
|
21
|
-
replaced_verification_types: z.array(z.string()),
|
|
19
|
+
moderation_id: z.number(),
|
|
22
20
|
}),
|
|
23
21
|
}),
|
|
24
22
|
};
|
|
25
23
|
|
|
26
24
|
type HyyypertoolActivityContexts = ContextsOf<typeof hyyypertool_activities>;
|
|
27
25
|
|
|
28
|
-
const
|
|
29
|
-
action: "
|
|
26
|
+
const darkangels_commented = {
|
|
27
|
+
action: "moderation.commented" as const,
|
|
30
28
|
context: {
|
|
31
|
-
inputs: {
|
|
32
|
-
|
|
33
|
-
verification_type: "refused" as const,
|
|
34
|
-
},
|
|
35
|
-
outcome: {
|
|
36
|
-
email_domain_id: 7,
|
|
37
|
-
replaced_verification_types: ["not_verified_yet"],
|
|
38
|
-
},
|
|
29
|
+
inputs: { comment: "darkangels.world looks legit" },
|
|
30
|
+
outcome: { moderation_id: 7 },
|
|
39
31
|
},
|
|
40
32
|
organization_id: 1,
|
|
41
33
|
};
|
|
@@ -48,7 +40,7 @@ async function setup() {
|
|
|
48
40
|
moderator: createIdentiteRuntime<HyyypertoolActivityContexts>({
|
|
49
41
|
app: "hyyypertool",
|
|
50
42
|
db,
|
|
51
|
-
}).as({ type: "moderator", sub: "moderator+
|
|
43
|
+
}).as({ type: "moderator", sub: "moderator+comments-darkangels.world" }),
|
|
52
44
|
};
|
|
53
45
|
}
|
|
54
46
|
|
|
@@ -57,18 +49,18 @@ describe("record", () => {
|
|
|
57
49
|
const { db, moderator } = await setup();
|
|
58
50
|
|
|
59
51
|
const outcome = await db.transaction((tx) =>
|
|
60
|
-
moderator.record(tx,
|
|
52
|
+
moderator.record(tx, darkangels_commented),
|
|
61
53
|
);
|
|
62
54
|
|
|
63
55
|
assert.deepEqual(outcome, { activity_id: 1 });
|
|
64
56
|
assert.deepEqual(await readActivityLogs(db), [
|
|
65
57
|
{
|
|
66
|
-
action: "
|
|
67
|
-
actor_ref: "moderator+
|
|
58
|
+
action: "moderation.commented",
|
|
59
|
+
actor_ref: "moderator+comments-darkangels.world",
|
|
68
60
|
actor_type: "moderator",
|
|
69
61
|
app: "hyyypertool",
|
|
70
62
|
cause_activity_id: null,
|
|
71
|
-
context:
|
|
63
|
+
context: darkangels_commented.context,
|
|
72
64
|
interaction_cid: null,
|
|
73
65
|
moderation_id: null,
|
|
74
66
|
organization_id: 1,
|
|
@@ -86,24 +78,24 @@ describe("record", () => {
|
|
|
86
78
|
|
|
87
79
|
void ((tx: IdentiteTransaction) =>
|
|
88
80
|
record(tx, {
|
|
89
|
-
// @ts-expect-error domain.verified belongs to the runtime, only
|
|
81
|
+
// @ts-expect-error domain.verified belongs to the runtime, only changeEmailDomainVerification writes it
|
|
90
82
|
action: "domain.verified",
|
|
91
|
-
context:
|
|
83
|
+
context: darkangels_commented.context,
|
|
92
84
|
}));
|
|
93
85
|
|
|
94
86
|
void ((tx: IdentiteTransaction) =>
|
|
95
87
|
record(tx, {
|
|
96
|
-
action: "
|
|
97
|
-
// @ts-expect-error the context does not match
|
|
98
|
-
context: { inputs: {
|
|
88
|
+
action: "moderation.commented",
|
|
89
|
+
// @ts-expect-error the context does not match moderation.commented
|
|
90
|
+
context: { inputs: { comment: "darkangels.world" }, outcome: {} },
|
|
99
91
|
}));
|
|
100
92
|
|
|
101
93
|
void (() =>
|
|
102
94
|
// @ts-expect-error the bare database is not a transaction
|
|
103
|
-
record(db,
|
|
95
|
+
record(db, darkangels_commented));
|
|
104
96
|
|
|
105
97
|
type OverlappingContexts = {
|
|
106
|
-
"domain.verified": HyyypertoolActivityContexts["
|
|
98
|
+
"domain.verified": HyyypertoolActivityContexts["moderation.commented"];
|
|
107
99
|
};
|
|
108
100
|
// @ts-expect-error domain.verified is already defined by the runtime
|
|
109
101
|
void createIdentiteRuntime<OverlappingContexts>({ app: "hyyypertool", db });
|
|
@@ -112,6 +104,6 @@ describe("record", () => {
|
|
|
112
104
|
createIdentiteRuntime({ app: "proconnect-identite", db })
|
|
113
105
|
.as({ type: "app", job: "join.official_contact" })
|
|
114
106
|
// @ts-expect-error proconnect-identite has no app-only action to record
|
|
115
|
-
.record(tx,
|
|
107
|
+
.record(tx, darkangels_commented));
|
|
116
108
|
});
|
|
117
109
|
});
|
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
RuntimeContext,
|
|
10
10
|
} from "#src/activity";
|
|
11
11
|
import type { IdentiteTransaction } from "#src/database";
|
|
12
|
-
import {
|
|
12
|
+
import { changeEmailDomainVerificationFactory } from "#src/domains";
|
|
13
13
|
import {
|
|
14
14
|
connectFranceConnectFactory,
|
|
15
15
|
disconnectFranceConnectFactory,
|
|
@@ -21,7 +21,12 @@ import {
|
|
|
21
21
|
updateMembershipFactory,
|
|
22
22
|
} from "#src/memberships";
|
|
23
23
|
import { openModerationFactory } from "#src/moderations";
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
changePasswordFactory,
|
|
26
|
+
deleteUserFactory,
|
|
27
|
+
resetMfaFactory,
|
|
28
|
+
updatePersonalInformationsFactory,
|
|
29
|
+
} from "#src/users";
|
|
25
30
|
|
|
26
31
|
//
|
|
27
32
|
|
|
@@ -34,6 +39,12 @@ export function createIdentiteRuntime<
|
|
|
34
39
|
as(actor: Actor) {
|
|
35
40
|
return {
|
|
36
41
|
addMembership: addMembershipFactory({ actor, app, db }),
|
|
42
|
+
changeEmailDomainVerification: changeEmailDomainVerificationFactory({
|
|
43
|
+
actor,
|
|
44
|
+
app,
|
|
45
|
+
db,
|
|
46
|
+
}),
|
|
47
|
+
changePassword: changePasswordFactory({ actor, app, db }),
|
|
37
48
|
connectFranceConnect: connectFranceConnectFactory({ actor, app, db }),
|
|
38
49
|
deleteUser: deleteUserFactory({ actor, app, db }),
|
|
39
50
|
disconnectFranceConnect: disconnectFranceConnectFactory({
|
|
@@ -41,7 +52,6 @@ export function createIdentiteRuntime<
|
|
|
41
52
|
app,
|
|
42
53
|
db,
|
|
43
54
|
}),
|
|
44
|
-
markDomainAsVerified: markDomainAsVerifiedFactory({ actor, app, db }),
|
|
45
55
|
openModeration: openModerationFactory({ actor, app, db }),
|
|
46
56
|
removeMembership: removeMembershipFactory({ actor, app, db }),
|
|
47
57
|
record: (
|
|
@@ -50,6 +60,11 @@ export function createIdentiteRuntime<
|
|
|
50
60
|
) => insertActivity<OwnContexts>(tx, { ...activity, actor, app }),
|
|
51
61
|
resetMfa: resetMfaFactory({ actor, app, db }),
|
|
52
62
|
updateMembership: updateMembershipFactory({ actor, app, db }),
|
|
63
|
+
updatePersonalInformations: updatePersonalInformationsFactory({
|
|
64
|
+
actor,
|
|
65
|
+
app,
|
|
66
|
+
db,
|
|
67
|
+
}),
|
|
53
68
|
};
|
|
54
69
|
},
|
|
55
70
|
};
|