@proconnect-gouv/proconnect.identite 12.0.0 → 13.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 +6 -0
- package/dist/connectors/index.d.ts +0 -37
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +2 -4
- 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/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/package.json +1 -1
- package/src/connectors/index.ts +0 -5
- package/src/managers/organization/index.ts +0 -1
- package/src/repositories/email-domain/index.ts +0 -3
- package/src/repositories/organization/index.ts +0 -1
- 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/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/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/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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @proconnect-gouv/proconnect.identite
|
|
2
2
|
|
|
3
|
+
## 13.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#2372](https://github.com/proconnect-gouv/proconnect-identite/pull/2372) [`a31ca3e`](https://github.com/proconnect-gouv/proconnect-identite/commit/a31ca3e90bcd2b874e754159d3597a720f7a62b0) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Retire `markDomainAsVerifiedFactory` (`managers/organization`) et `assignUserVerificationTypeToDomainFactory` (`managers/user`), ainsi que les repositories qu'ils étaient seuls à utiliser (`email_domains.deleteEmailDomainsByVerificationTypes`, `organizations.findUsers`), sans appelant depuis que les deux applications passent par `markDomainAsVerified` du runtime.
|
|
8
|
+
|
|
3
9
|
## 12.0.0
|
|
4
10
|
|
|
5
11
|
### Major Changes
|
|
@@ -390,11 +390,6 @@ export declare function createContext({ api_entreprise_client, api_insee_client,
|
|
|
390
390
|
created_at: Date;
|
|
391
391
|
updated_at: Date;
|
|
392
392
|
}>;
|
|
393
|
-
deleteEmailDomainsByVerificationTypes: ({ organization_id, domain, domain_verification_types, }: {
|
|
394
|
-
organization_id: import("../types/email-domain.js").EmailDomain["organization_id"];
|
|
395
|
-
domain_verification_types: import("../types/email-domain.js").EmailDomainVerificationType[];
|
|
396
|
-
domain: import("../types/email-domain.js").EmailDomain["domain"];
|
|
397
|
-
}) => Promise<import("pg").QueryResult<any>>;
|
|
398
393
|
findEmailDomainsByOrganizationId: (organization_id: number) => Promise<{
|
|
399
394
|
id: number;
|
|
400
395
|
organization_id: number;
|
|
@@ -536,38 +531,6 @@ export declare function createContext({ api_entreprise_client, api_insee_client,
|
|
|
536
531
|
findPendingByUserId: (user_id: number) => Promise<(import("../types/organization.js").Organization & {
|
|
537
532
|
moderation_id: number;
|
|
538
533
|
})[]>;
|
|
539
|
-
findUsers: (organization_id: number) => Promise<({
|
|
540
|
-
created_at: Date;
|
|
541
|
-
current_challenge: string | null;
|
|
542
|
-
email: string;
|
|
543
|
-
email_verified: boolean;
|
|
544
|
-
email_verified_at: Date | null;
|
|
545
|
-
encrypted_password: string | null;
|
|
546
|
-
encrypted_totp_key: string | null;
|
|
547
|
-
family_name: string | null;
|
|
548
|
-
force_2fa: boolean;
|
|
549
|
-
given_name: string | null;
|
|
550
|
-
id: number;
|
|
551
|
-
job: string | null;
|
|
552
|
-
last_sign_in_at: Date | null;
|
|
553
|
-
magic_link_sent_at: Date | null;
|
|
554
|
-
magic_link_token: string | null;
|
|
555
|
-
needs_inclusionconnect_onboarding_help: boolean;
|
|
556
|
-
needs_inclusionconnect_welcome_page: boolean;
|
|
557
|
-
phone_number: string | null;
|
|
558
|
-
reset_password_sent_at: Date | null;
|
|
559
|
-
reset_password_token: string | null;
|
|
560
|
-
sign_in_count: number;
|
|
561
|
-
totp_key_verified_at: Date | null;
|
|
562
|
-
updated_at: Date;
|
|
563
|
-
verify_email_sent_at: Date | null;
|
|
564
|
-
verify_email_token: string | null;
|
|
565
|
-
} & {
|
|
566
|
-
is_external: boolean;
|
|
567
|
-
verification_type: "domain" | "organization_dirigeant" | "code_sent_to_official_contact_email" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association" | "no_verification_means_for_small_organization";
|
|
568
|
-
verified_at: Date | null;
|
|
569
|
-
has_been_greeted: boolean;
|
|
570
|
-
})[]>;
|
|
571
534
|
getById: (id: number) => Promise<import("../types/organization.js").Organization>;
|
|
572
535
|
upsert: ({ siret, organizationInfo, }: {
|
|
573
536
|
siret: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectors/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectors/index.ts"],"names":[],"mappings":"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"}
|
package/dist/connectors/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
//
|
|
2
2
|
import { createAuthenticatorFactory, deleteAuthenticatorFactory, findAuthenticatorFactory, findAuthenticatorsByUserIdFactory, updateAuthenticatorFactory, } from "#src/repositories/authenticator";
|
|
3
3
|
import { findEmailInDeliverabilityWhiteListFactory } from "#src/repositories/email-deliverability-whitelist";
|
|
4
|
-
import { addDomainFactory,
|
|
4
|
+
import { addDomainFactory, findEmailDomainsByOrganizationIdFactory, } from "#src/repositories/email-domain";
|
|
5
5
|
import { deleteFranceconnectUserinfoFactory, findFranceconnectUserinfoFactory, upsertFranceconnectUserinfoFactory, } from "#src/repositories/franceconnect_userinfo";
|
|
6
6
|
import { createModerationFactory, deleteModerationFactory, findModerationByIdFactory, findPendingModerationFactory, findRejectedModerationFactory, getModerationByIdFactory, reopenModerationFactory, } from "#src/repositories/moderation";
|
|
7
7
|
import { deleteOfficialContactEmailVerificationFactory, findOfficialContactEmailVerificationFactory, upsertOfficialContactEmailVerificationFactory, } from "#src/repositories/official-contact-email-verification";
|
|
8
8
|
import { findByClientIdFactory, upsertAuthorizationRequestFactory, } from "#src/repositories/oidc-client";
|
|
9
|
-
import { findBySiretFactory, findByUserIdFactory, findByVerifiedEmailDomainFactory, findOrganizationByIdFactory, findPendingByUserIdFactory,
|
|
9
|
+
import { findBySiretFactory, findByUserIdFactory, findByVerifiedEmailDomainFactory, findOrganizationByIdFactory, findPendingByUserIdFactory, getOrganizationByIdFactory, upsertFactory, } from "#src/repositories/organization";
|
|
10
10
|
import { createRecoveryWordsFactory, deleteRecoveryWordsByUserIdFactory, findRecoveryWordsByUserIdFactory, } from "#src/repositories/recovery-words";
|
|
11
11
|
import { createUserFactory, deleteUserFactory, findByEmailFactory, findByMagicLinkTokenFactory, findByResetPasswordTokenFactory, findByIdFactory as findUserByIdFactory, getByIdFactory, updateUserFactory, } from "#src/repositories/user";
|
|
12
12
|
import { createUserOrganizationFactory, deleteUserOrganizationFactory, findUserOrganizationFactory, getUserOrganizationFactory, updateUserOrganizationFactory, } from "#src/repositories/user_organisation";
|
|
@@ -32,7 +32,6 @@ export function createContext({ api_entreprise_client, api_insee_client, api_reg
|
|
|
32
32
|
},
|
|
33
33
|
email_domains: {
|
|
34
34
|
addDomain: addDomainFactory({ pg }),
|
|
35
|
-
deleteEmailDomainsByVerificationTypes: deleteEmailDomainsByVerificationTypesFactory({ pg }),
|
|
36
35
|
findEmailDomainsByOrganizationId: findEmailDomainsByOrganizationIdFactory({ pg }),
|
|
37
36
|
},
|
|
38
37
|
moderations: {
|
|
@@ -59,7 +58,6 @@ export function createContext({ api_entreprise_client, api_insee_client, api_reg
|
|
|
59
58
|
findByUserId: findByUserIdFactory({ pg }),
|
|
60
59
|
findByVerifiedEmailDomain: findByVerifiedEmailDomainFactory({ pg }),
|
|
61
60
|
findPendingByUserId: findPendingByUserIdFactory({ pg }),
|
|
62
|
-
findUsers: findUsersByOrganizationFactory({ pg }),
|
|
63
61
|
getById: getOrganizationByIdFactory({ pg }),
|
|
64
62
|
upsert: upsertFactory({ pg }),
|
|
65
63
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/index.ts"],"names":[],"mappings":"AAEA,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/index.ts"],"names":[],"mappings":"AAEA,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
export * from "./add-domain.js";
|
|
2
|
-
export * from "./delete-email-domains-by-verification-types.js";
|
|
3
2
|
export * from "./find-email-domains-by-organization-id.js";
|
|
4
3
|
import type { AddDomainHandler } from "./add-domain.js";
|
|
5
|
-
import type { DeleteEmailDomainsByVerificationTypesHandler } from "./delete-email-domains-by-verification-types.js";
|
|
6
4
|
import type { FindEmailDomainsByOrganizationIdHandler } from "./find-email-domains-by-organization-id.js";
|
|
7
5
|
export type EmailDomainRepository = {
|
|
8
6
|
addDomain: AddDomainHandler;
|
|
9
|
-
deleteEmailDomainsByVerificationTypes: DeleteEmailDomainsByVerificationTypesHandler;
|
|
10
7
|
findEmailDomainsByOrganizationId: FindEmailDomainsByOrganizationIdHandler;
|
|
11
8
|
};
|
|
12
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/email-domain/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/email-domain/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,4CAA4C,CAAC;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,uCAAuC,EAAE,MAAM,4CAA4C,CAAC;AAE1G,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,gBAAgB,CAAC;IAC5B,gCAAgC,EAAE,uCAAuC,CAAC;CAC3E,CAAC"}
|
|
@@ -3,7 +3,6 @@ export * from "./find-by-user-id.js";
|
|
|
3
3
|
export * from "./find-by-verified-email-domain.js";
|
|
4
4
|
export * from "./find-organization-by-id.js";
|
|
5
5
|
export * from "./find-pending-by-user-id.js";
|
|
6
|
-
export * from "./find-users-by-organization.js";
|
|
7
6
|
export * from "./get-organization-by-id.js";
|
|
8
7
|
export * from "./upsert.js";
|
|
9
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/index.ts"],"names":[],"mappings":"AAEA,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/index.ts"],"names":[],"mappings":"AAEA,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,aAAa,CAAC"}
|
|
@@ -4,6 +4,5 @@ export * from "./find-by-user-id.js";
|
|
|
4
4
|
export * from "./find-by-verified-email-domain.js";
|
|
5
5
|
export * from "./find-organization-by-id.js";
|
|
6
6
|
export * from "./find-pending-by-user-id.js";
|
|
7
|
-
export * from "./find-users-by-organization.js";
|
|
8
7
|
export * from "./get-organization-by-id.js";
|
|
9
8
|
export * from "./upsert.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0",
|
|
4
4
|
"homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/identite#readme",
|
|
5
5
|
"bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
|
|
6
6
|
"repository": {
|
package/src/connectors/index.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
import { findEmailInDeliverabilityWhiteListFactory } from "#src/repositories/email-deliverability-whitelist";
|
|
11
11
|
import {
|
|
12
12
|
addDomainFactory,
|
|
13
|
-
deleteEmailDomainsByVerificationTypesFactory,
|
|
14
13
|
findEmailDomainsByOrganizationIdFactory,
|
|
15
14
|
} from "#src/repositories/email-domain";
|
|
16
15
|
import {
|
|
@@ -42,7 +41,6 @@ import {
|
|
|
42
41
|
findByVerifiedEmailDomainFactory,
|
|
43
42
|
findOrganizationByIdFactory,
|
|
44
43
|
findPendingByUserIdFactory,
|
|
45
|
-
findUsersByOrganizationFactory,
|
|
46
44
|
getOrganizationByIdFactory,
|
|
47
45
|
upsertFactory,
|
|
48
46
|
} from "#src/repositories/organization";
|
|
@@ -106,8 +104,6 @@ export function createContext({
|
|
|
106
104
|
},
|
|
107
105
|
email_domains: {
|
|
108
106
|
addDomain: addDomainFactory({ pg }),
|
|
109
|
-
deleteEmailDomainsByVerificationTypes:
|
|
110
|
-
deleteEmailDomainsByVerificationTypesFactory({ pg }),
|
|
111
107
|
findEmailDomainsByOrganizationId:
|
|
112
108
|
findEmailDomainsByOrganizationIdFactory({ pg }),
|
|
113
109
|
},
|
|
@@ -135,7 +131,6 @@ export function createContext({
|
|
|
135
131
|
findByUserId: findByUserIdFactory({ pg }),
|
|
136
132
|
findByVerifiedEmailDomain: findByVerifiedEmailDomainFactory({ pg }),
|
|
137
133
|
findPendingByUserId: findPendingByUserIdFactory({ pg }),
|
|
138
|
-
findUsers: findUsersByOrganizationFactory({ pg }),
|
|
139
134
|
getById: getOrganizationByIdFactory({ pg }),
|
|
140
135
|
upsert: upsertFactory({ pg }),
|
|
141
136
|
},
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
export * from "./add-domain.js";
|
|
2
|
-
export * from "./delete-email-domains-by-verification-types.js";
|
|
3
2
|
export * from "./find-email-domains-by-organization-id.js";
|
|
4
3
|
|
|
5
4
|
import type { AddDomainHandler } from "./add-domain.js";
|
|
6
|
-
import type { DeleteEmailDomainsByVerificationTypesHandler } from "./delete-email-domains-by-verification-types.js";
|
|
7
5
|
import type { FindEmailDomainsByOrganizationIdHandler } from "./find-email-domains-by-organization-id.js";
|
|
8
6
|
|
|
9
7
|
export type EmailDomainRepository = {
|
|
10
8
|
addDomain: AddDomainHandler;
|
|
11
|
-
deleteEmailDomainsByVerificationTypes: DeleteEmailDomainsByVerificationTypesHandler;
|
|
12
9
|
findEmailDomainsByOrganizationId: FindEmailDomainsByOrganizationIdHandler;
|
|
13
10
|
};
|
|
@@ -5,6 +5,5 @@ export * from "./find-by-user-id.js";
|
|
|
5
5
|
export * from "./find-by-verified-email-domain.js";
|
|
6
6
|
export * from "./find-organization-by-id.js";
|
|
7
7
|
export * from "./find-pending-by-user-id.js";
|
|
8
|
-
export * from "./find-users-by-organization.js";
|
|
9
8
|
export * from "./get-organization-by-id.js";
|
|
10
9
|
export * from "./upsert.js";
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Context } from "#src/connectors";
|
|
2
|
-
import { type EmailDomainNoPendingVerificationType } from "#src/types";
|
|
3
|
-
export declare function markDomainAsVerifiedFactory(context: Context): ({ organization_id, domain, domain_verification_type, }: {
|
|
4
|
-
organization_id: number;
|
|
5
|
-
domain: string;
|
|
6
|
-
domain_verification_type: EmailDomainNoPendingVerificationType;
|
|
7
|
-
}) => Promise<{
|
|
8
|
-
id: number;
|
|
9
|
-
organization_id: number;
|
|
10
|
-
domain: string;
|
|
11
|
-
verification_type: "official_contact" | "trackdechets_postal_mail" | "verified" | "external" | "not_verified_yet" | "blacklisted" | "refused";
|
|
12
|
-
can_be_suggested: boolean;
|
|
13
|
-
verified_at: Date | null;
|
|
14
|
-
created_at: Date;
|
|
15
|
-
updated_at: Date;
|
|
16
|
-
}>;
|
|
17
|
-
export type MarkDomainAsVerifiedHandler = ReturnType<typeof markDomainAsVerifiedFactory>;
|
|
18
|
-
//# sourceMappingURL=mark-domain-as-verified.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mark-domain-as-verified.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/mark-domain-as-verified.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAGL,KAAK,oCAAoC,EAK1C,MAAM,YAAY,CAAC;AAOpB,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,IAQf,wDAIxC;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB,EAAE,oCAAoC,CAAC;CAChE;;;;;;;;;GAkFF;AAED,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAClD,OAAO,2BAA2B,CACnC,CAAC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { NotFoundError } from "#src/errors";
|
|
3
|
-
import { assignUserVerificationTypeToDomainFactory } from "#src/managers/user";
|
|
4
|
-
import { EmailDomainApprovedVerificationValues, EmailDomainPendingVerificationValues, EmailDomainRejectedVerificationValues, } from "#src/types";
|
|
5
|
-
import { isEmpty } from "lodash-es";
|
|
6
|
-
import { match } from "ts-pattern";
|
|
7
|
-
//
|
|
8
|
-
export function markDomainAsVerifiedFactory(context) {
|
|
9
|
-
const assignUserVerificationTypeToDomain = assignUserVerificationTypeToDomainFactory(context);
|
|
10
|
-
const { repository: { email_domains, organizations }, } = context;
|
|
11
|
-
return async function markDomainAsVerified({ organization_id, domain, domain_verification_type, }) {
|
|
12
|
-
const organization = await organizations.findById(organization_id);
|
|
13
|
-
if (isEmpty(organization)) {
|
|
14
|
-
throw new NotFoundError();
|
|
15
|
-
}
|
|
16
|
-
return match(domain_verification_type)
|
|
17
|
-
.with(...EmailDomainApprovedVerificationValues, async (approved_verification_type) => {
|
|
18
|
-
await assignUserVerificationTypeToDomain(organization_id, domain);
|
|
19
|
-
return markDomainAsApproved({
|
|
20
|
-
organization_id,
|
|
21
|
-
domain,
|
|
22
|
-
domain_verification_type: approved_verification_type,
|
|
23
|
-
});
|
|
24
|
-
})
|
|
25
|
-
.with(...EmailDomainRejectedVerificationValues, (rejected_verification_type) => markDomainAsRejected({
|
|
26
|
-
organization_id,
|
|
27
|
-
domain,
|
|
28
|
-
domain_verification_type: rejected_verification_type,
|
|
29
|
-
}))
|
|
30
|
-
.exhaustive();
|
|
31
|
-
};
|
|
32
|
-
async function markDomainAsApproved({ organization_id, domain, domain_verification_type, }) {
|
|
33
|
-
await email_domains.deleteEmailDomainsByVerificationTypes({
|
|
34
|
-
organization_id,
|
|
35
|
-
domain,
|
|
36
|
-
domain_verification_types: [
|
|
37
|
-
...EmailDomainApprovedVerificationValues,
|
|
38
|
-
...EmailDomainPendingVerificationValues,
|
|
39
|
-
...EmailDomainRejectedVerificationValues,
|
|
40
|
-
],
|
|
41
|
-
});
|
|
42
|
-
return email_domains.addDomain({
|
|
43
|
-
organization_id,
|
|
44
|
-
domain,
|
|
45
|
-
verification_type: domain_verification_type,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
async function markDomainAsRejected({ organization_id, domain, domain_verification_type, }) {
|
|
49
|
-
await email_domains.deleteEmailDomainsByVerificationTypes({
|
|
50
|
-
organization_id,
|
|
51
|
-
domain,
|
|
52
|
-
domain_verification_types: [
|
|
53
|
-
...EmailDomainApprovedVerificationValues,
|
|
54
|
-
...EmailDomainPendingVerificationValues,
|
|
55
|
-
...EmailDomainRejectedVerificationValues,
|
|
56
|
-
],
|
|
57
|
-
});
|
|
58
|
-
return email_domains.addDomain({
|
|
59
|
-
organization_id,
|
|
60
|
-
domain,
|
|
61
|
-
verification_type: domain_verification_type,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Context } from "#src/connectors";
|
|
2
|
-
export declare function assignUserVerificationTypeToDomainFactory({ repository: { organizations, users_organizations }, }: Context): (organization_id: number, domain: string) => Promise<void>;
|
|
3
|
-
//# sourceMappingURL=assign-user-verification-type-to-domain.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assign-user-verification-type-to-domain.d.ts","sourceRoot":"","sources":["../../../src/managers/user/assign-user-verification-type-to-domain.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAM/C,wBAAgB,yCAAyC,CAAC,EACxD,UAAU,EAAE,EAAE,aAAa,EAAE,mBAAmB,EAAE,GACnD,EAAE,OAAO,IAEN,iBAAiB,MAAM,EACvB,QAAQ,MAAM,mBA0BjB"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { LinkEnum, SuperWeakLinkEnum, UnverifiedLinkEnum } from "#src/types";
|
|
3
|
-
import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
|
|
4
|
-
//
|
|
5
|
-
export function assignUserVerificationTypeToDomainFactory({ repository: { organizations, users_organizations }, }) {
|
|
6
|
-
return async function assignUserVerificationTypeToDomain(organization_id, domain) {
|
|
7
|
-
const usersInOrganization = await organizations.findUsers(organization_id);
|
|
8
|
-
await Promise.all(usersInOrganization.map(({ id: user_id, email, verification_type: link_verification_type }) => {
|
|
9
|
-
const userDomain = getEmailDomain(email);
|
|
10
|
-
if (userDomain === domain &&
|
|
11
|
-
(UnverifiedLinkEnum.safeParse(link_verification_type).success ||
|
|
12
|
-
SuperWeakLinkEnum.safeParse(link_verification_type).success)) {
|
|
13
|
-
return users_organizations.update({ organization_id, user_id }, {
|
|
14
|
-
verification_type: LinkEnum.enum.domain,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
}));
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/managers/user/index.ts"],"names":[],"mappings":"AAAA,cAAc,8CAA8C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./assign-user-verification-type-to-domain.js";
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { DatabaseContext, EmailDomain, EmailDomainVerificationType } from "#src/types";
|
|
2
|
-
export declare function deleteEmailDomainsByVerificationTypesFactory({ pg, }: DatabaseContext): ({ organization_id, domain, domain_verification_types, }: {
|
|
3
|
-
organization_id: EmailDomain["organization_id"];
|
|
4
|
-
domain_verification_types: EmailDomainVerificationType[];
|
|
5
|
-
domain: EmailDomain["domain"];
|
|
6
|
-
}) => Promise<import("pg").QueryResult<any>>;
|
|
7
|
-
export type DeleteEmailDomainsByVerificationTypesHandler = ReturnType<typeof deleteEmailDomainsByVerificationTypesFactory>;
|
|
8
|
-
//# sourceMappingURL=delete-email-domains-by-verification-types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delete-email-domains-by-verification-types.d.ts","sourceRoot":"","sources":["../../../src/repositories/email-domain/delete-email-domains-by-verification-types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,2BAA2B,EAC5B,MAAM,YAAY,CAAC;AAIpB,wBAAgB,4CAA4C,CAAC,EAC3D,EAAE,GACH,EAAE,eAAe,IAC4C,yDAIzD;IACD,eAAe,EAAE,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAChD,yBAAyB,EAAE,2BAA2B,EAAE,CAAC;IACzD,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;CAC/B,4CAmBF;AAED,MAAM,MAAM,4CAA4C,GAAG,UAAU,CACnE,OAAO,4CAA4C,CACpD,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
export function deleteEmailDomainsByVerificationTypesFactory({ pg, }) {
|
|
4
|
-
return async function deleteEmailDomainsByVerificationTypes({ organization_id, domain, domain_verification_types, }) {
|
|
5
|
-
const SQL_VERIFICATION_TYPES = domain_verification_types
|
|
6
|
-
.map((type) => `verification_type = '${type}'`)
|
|
7
|
-
.join(" OR ");
|
|
8
|
-
return pg.query(`
|
|
9
|
-
DELETE FROM email_domains
|
|
10
|
-
WHERE
|
|
11
|
-
${[
|
|
12
|
-
"organization_id = $1",
|
|
13
|
-
"domain = $2",
|
|
14
|
-
`(${SQL_VERIFICATION_TYPES})`,
|
|
15
|
-
].join(" AND ")}
|
|
16
|
-
;
|
|
17
|
-
`, [organization_id, domain]);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { DatabaseContext } from "#src/types";
|
|
2
|
-
export declare function findUsersByOrganizationFactory({ pg }: DatabaseContext): (organization_id: number) => Promise<({
|
|
3
|
-
created_at: Date;
|
|
4
|
-
current_challenge: string | null;
|
|
5
|
-
email: string;
|
|
6
|
-
email_verified: boolean;
|
|
7
|
-
email_verified_at: Date | null;
|
|
8
|
-
encrypted_password: string | null;
|
|
9
|
-
encrypted_totp_key: string | null;
|
|
10
|
-
family_name: string | null;
|
|
11
|
-
force_2fa: boolean;
|
|
12
|
-
given_name: string | null;
|
|
13
|
-
id: number;
|
|
14
|
-
job: string | null;
|
|
15
|
-
last_sign_in_at: Date | null;
|
|
16
|
-
magic_link_sent_at: Date | null;
|
|
17
|
-
magic_link_token: string | null;
|
|
18
|
-
needs_inclusionconnect_onboarding_help: boolean;
|
|
19
|
-
needs_inclusionconnect_welcome_page: boolean;
|
|
20
|
-
phone_number: string | null;
|
|
21
|
-
reset_password_sent_at: Date | null;
|
|
22
|
-
reset_password_token: string | null;
|
|
23
|
-
sign_in_count: number;
|
|
24
|
-
totp_key_verified_at: Date | null;
|
|
25
|
-
updated_at: Date;
|
|
26
|
-
verify_email_sent_at: Date | null;
|
|
27
|
-
verify_email_token: string | null;
|
|
28
|
-
} & {
|
|
29
|
-
is_external: boolean;
|
|
30
|
-
verification_type: "domain" | "organization_dirigeant" | "code_sent_to_official_contact_email" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association" | "no_verification_means_for_small_organization";
|
|
31
|
-
verified_at: Date | null;
|
|
32
|
-
has_been_greeted: boolean;
|
|
33
|
-
})[]>;
|
|
34
|
-
//# sourceMappingURL=find-users-by-organization.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find-users-by-organization.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/find-users-by-organization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,YAAY,CAAC;AAKpB,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,iBAAiB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAiBtE"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
export function findUsersByOrganizationFactory({ pg }) {
|
|
4
|
-
return async function findUsersByOrganization(organization_id) {
|
|
5
|
-
const { rows } = await pg.query(`
|
|
6
|
-
SELECT u.*,
|
|
7
|
-
uo.is_external,
|
|
8
|
-
uo.verification_type,
|
|
9
|
-
uo.verified_at,
|
|
10
|
-
uo.has_been_greeted
|
|
11
|
-
FROM users u
|
|
12
|
-
INNER JOIN users_organizations AS uo ON uo.user_id = u.id
|
|
13
|
-
WHERE uo.organization_id = $1`, [organization_id]);
|
|
14
|
-
return rows;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -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,51 +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 { findUsersByOrganizationFactory } from "./find-users-by-organization.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const findUsersByOrganization = findUsersByOrganizationFactory({
|
|
11
|
-
pg: pg as any,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe("findUsersByOrganizationFactory", () => {
|
|
15
|
-
before(migrate);
|
|
16
|
-
beforeEach(emptyDatabase);
|
|
17
|
-
|
|
18
|
-
it("should find users by organization id", async (t) => {
|
|
19
|
-
await pg.sql`
|
|
20
|
-
INSERT INTO organizations
|
|
21
|
-
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
22
|
-
VALUES
|
|
23
|
-
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
24
|
-
;
|
|
25
|
-
`;
|
|
26
|
-
|
|
27
|
-
await pg.sql`
|
|
28
|
-
INSERT INTO users
|
|
29
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
30
|
-
VALUES
|
|
31
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
32
|
-
;
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
await pg.sql`
|
|
36
|
-
INSERT INTO users_organizations
|
|
37
|
-
(user_id, organization_id, created_at, updated_at, is_external, verification_type)
|
|
38
|
-
VALUES (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_available')
|
|
39
|
-
;
|
|
40
|
-
`;
|
|
41
|
-
|
|
42
|
-
const user = await findUsersByOrganization(1);
|
|
43
|
-
|
|
44
|
-
t.assert.snapshot(user);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("❎ fail to find users for unknown organization id", async () => {
|
|
48
|
-
const user = await findUsersByOrganization(42);
|
|
49
|
-
assert.deepEqual(user, []);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
exports[`findUsersByOrganizationFactory > should find users by organization id 1`] = `
|
|
2
|
-
[
|
|
3
|
-
{
|
|
4
|
-
"id": 1,
|
|
5
|
-
"email": "lion.eljonson@darkangels.world",
|
|
6
|
-
"encrypted_password": null,
|
|
7
|
-
"reset_password_token": null,
|
|
8
|
-
"reset_password_sent_at": null,
|
|
9
|
-
"sign_in_count": 0,
|
|
10
|
-
"last_sign_in_at": null,
|
|
11
|
-
"created_at": "4444-04-04T00:00:00.000Z",
|
|
12
|
-
"updated_at": "4444-04-04T00:00:00.000Z",
|
|
13
|
-
"email_verified": false,
|
|
14
|
-
"verify_email_token": null,
|
|
15
|
-
"verify_email_sent_at": null,
|
|
16
|
-
"given_name": "lion",
|
|
17
|
-
"family_name": "el'jonson",
|
|
18
|
-
"phone_number": "i",
|
|
19
|
-
"job": "primarque",
|
|
20
|
-
"magic_link_token": null,
|
|
21
|
-
"magic_link_sent_at": null,
|
|
22
|
-
"email_verified_at": null,
|
|
23
|
-
"current_challenge": null,
|
|
24
|
-
"needs_inclusionconnect_welcome_page": false,
|
|
25
|
-
"needs_inclusionconnect_onboarding_help": false,
|
|
26
|
-
"encrypted_totp_key": null,
|
|
27
|
-
"totp_key_verified_at": null,
|
|
28
|
-
"force_2fa": false,
|
|
29
|
-
"is_external": false,
|
|
30
|
-
"verification_type": "no_verification_means_available",
|
|
31
|
-
"verified_at": null,
|
|
32
|
-
"has_been_greeted": false
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
`;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
BaseUserOrganizationLink,
|
|
5
|
-
DatabaseContext,
|
|
6
|
-
User,
|
|
7
|
-
} from "#src/types";
|
|
8
|
-
import type { QueryResult } from "pg";
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
export function findUsersByOrganizationFactory({ pg }: DatabaseContext) {
|
|
13
|
-
return async function findUsersByOrganization(organization_id: number) {
|
|
14
|
-
const { rows }: QueryResult<User & BaseUserOrganizationLink> =
|
|
15
|
-
await pg.query(
|
|
16
|
-
`
|
|
17
|
-
SELECT u.*,
|
|
18
|
-
uo.is_external,
|
|
19
|
-
uo.verification_type,
|
|
20
|
-
uo.verified_at,
|
|
21
|
-
uo.has_been_greeted
|
|
22
|
-
FROM users u
|
|
23
|
-
INNER JOIN users_organizations AS uo ON uo.user_id = u.id
|
|
24
|
-
WHERE uo.organization_id = $1`,
|
|
25
|
-
[organization_id],
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
return rows;
|
|
29
|
-
};
|
|
30
|
-
}
|