Skip to content

Commit d0bbca1

Browse files
committed
remove usages of userApi and userApi itself
1 parent 0e893f3 commit d0bbca1

File tree

11 files changed

+14
-171
lines changed

11 files changed

+14
-171
lines changed

api/scripts/compile-data.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { env } from "../src/env";
77
(async () => {
88
const kyselyDb = new Kysely<Database>({ dialect: createPgDialect(env.databaseUrl) });
99
const { useCases } = await bootstrapCore({
10-
"keycloakUserApiParams": undefined,
1110
"dbConfig": {
1211
"dbKind": "kysely",
1312
"kyselyDb": kyselyDb

api/src/core/adapters/dbApi/in-memory/createInMemoryAgentRepository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export const createInMemoryAgentRepository = (): {
3333
},
3434
getAllOrganizations: () => {
3535
throw new Error("Not implemented");
36-
}
36+
},
37+
countAll: async () => agents.length
3738
},
3839
testHelpers: {
3940
setAgents: (newAgents: DbAgentWithId[]) => {

api/src/core/adapters/dbApi/kysely/createPgAgentRepository.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export const createPgAgentRepository = (db: Kysely<Database>): AgentRepository =
3838
declarations: [...usersDeclarations, ...referentsDeclarations]
3939
}))
4040
),
41+
countAll: () =>
42+
db
43+
.selectFrom("agents")
44+
.select(qb => qb.fn.countAll<number>().as("count"))
45+
.executeTakeFirstOrThrow()
46+
.then(({ count }) => +count),
4147
getAllOrganizations: () =>
4248
db
4349
.selectFrom("agents")

api/src/core/adapters/userApi.ts

Lines changed: 0 additions & 109 deletions
This file was deleted.

api/src/core/bootstrap.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Kysely } from "kysely";
2-
import { createObjectThatThrowsIfAccessed } from "../tools/createObjectThatThrowsIfAccessed";
32
import { comptoirDuLibreApi } from "./adapters/comptoirDuLibreApi";
43
import { createKyselyPgDbApi } from "./adapters/dbApi/kysely/createPgDbApi";
54
import { Database } from "./adapters/dbApi/kysely/kysely.database";
@@ -10,13 +9,11 @@ import { createGetSoftwareLatestVersion } from "./adapters/getSoftwareLatestVers
109
import { getWikidataSoftware } from "./adapters/wikidata/getWikidataSoftware";
1110
import { getWikidataSoftwareOptions } from "./adapters/wikidata/getWikidataSoftwareOptions";
1211
import { halAdapter } from "./adapters/hal";
13-
import { createKeycloakUserApi, type KeycloakUserApiParams } from "./adapters/userApi";
1412
import type { ComptoirDuLibreApi } from "./ports/ComptoirDuLibreApi";
1513
import { DbApiV2 } from "./ports/DbApiV2";
1614
import type { ExternalDataOrigin, GetSoftwareExternalData } from "./ports/GetSoftwareExternalData";
1715
import type { GetSoftwareExternalDataOptions } from "./ports/GetSoftwareExternalDataOptions";
1816
import type { GetSoftwareLatestVersion } from "./ports/GetSoftwareLatestVersion";
19-
import type { UserApi } from "./ports/UserApi";
2017
import { UseCases } from "./usecases";
2118
import { makeGetAgent } from "./usecases/getAgent";
2219
import { makeGetSoftwareFormAutoFillDataFromExternalAndOtherSources } from "./usecases/getSoftwareFormAutoFillDataFromExternalAndOtherSources";
@@ -28,7 +25,6 @@ type DbConfig = PgDbConfig;
2825

2926
type ParamsOfBootstrapCore = {
3027
dbConfig: DbConfig;
31-
keycloakUserApiParams: KeycloakUserApiParams | undefined;
3228
githubPersonalAccessTokenForApiRateLimit: string;
3329
doPerPerformPeriodicalCompilation: boolean;
3430
doPerformCacheInitialization: boolean;
@@ -41,7 +37,6 @@ type ParamsOfBootstrapCore = {
4137
export type Context = {
4238
paramsOfBootstrapCore: ParamsOfBootstrapCore;
4339
dbApi: DbApiV2;
44-
userApi: UserApi;
4540
comptoirDuLibreApi: ComptoirDuLibreApi;
4641
getSoftwareExternalData: GetSoftwareExternalData;
4742
getSoftwareLatestVersion: GetSoftwareLatestVersion;
@@ -63,10 +58,8 @@ export async function bootstrapCore(
6358
): Promise<{ dbApi: DbApiV2; context: Context; useCases: UseCases }> {
6459
const {
6560
dbConfig,
66-
keycloakUserApiParams,
6761
githubPersonalAccessTokenForApiRateLimit,
6862
doPerPerformPeriodicalCompilation,
69-
doPerformCacheInitialization,
7063
externalSoftwareDataOrigin,
7164
initializeSoftwareFromSource,
7265
botAgentEmail,
@@ -81,20 +74,9 @@ export async function bootstrapCore(
8174

8275
const { dbApi } = getDbApiAndInitializeCache(dbConfig);
8376

84-
const { userApi, initializeUserApiCache } =
85-
keycloakUserApiParams === undefined
86-
? {
87-
"userApi": createObjectThatThrowsIfAccessed<Context["userApi"]>({
88-
"debugMessage": "No Keycloak server"
89-
}),
90-
"initializeUserApiCache": async () => {}
91-
}
92-
: createKeycloakUserApi(keycloakUserApiParams);
93-
9477
const context: Context = {
9578
"paramsOfBootstrapCore": params,
9679
dbApi,
97-
userApi,
9880
comptoirDuLibreApi,
9981
getSoftwareExternalData,
10082
getSoftwareLatestVersion
@@ -114,11 +96,6 @@ export async function bootstrapCore(
11496
getAgent: makeGetAgent({ agentRepository: dbApi.agent })
11597
};
11698

117-
if (doPerformCacheInitialization) {
118-
console.log("Performing user cache initialization...");
119-
await initializeUserApiCache();
120-
}
121-
12299
if (initializeSoftwareFromSource) {
123100
if (!botAgentEmail) throw new Error("No bot agent email provided");
124101
if (externalSoftwareDataOrigin === "HAL") {

api/src/core/ports/DbApiV2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export interface AgentRepository {
9999
remove: (agentId: number) => Promise<void>;
100100
getByEmail: (email: string) => Promise<AgentWithId | undefined>;
101101
getAll: () => Promise<AgentWithId[]>;
102+
countAll: () => Promise<number>;
102103
getAllOrganizations: () => Promise<string[]>;
103104
}
104105

api/src/core/ports/UserApi.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

api/src/rpc/createTestCaller.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ export const createTestCaller = async ({ user }: TestCallerConfig = { user: defa
2424
const externalSoftwareDataOrigin: ExternalDataOrigin = "wikidata";
2525
const kyselyDb = new Kysely<Database>({ dialect: createPgDialect(testPgUrl) });
2626

27-
const { context, dbApi, useCases } = await bootstrapCore({
27+
const { dbApi, useCases } = await bootstrapCore({
2828
"dbConfig": { dbKind: "kysely", kyselyDb },
29-
"keycloakUserApiParams": undefined,
3029
"githubPersonalAccessTokenForApiRateLimit": "fake-token",
3130
"doPerPerformPeriodicalCompilation": false,
3231
"doPerformCacheInitialization": false,
@@ -44,7 +43,6 @@ export const createTestCaller = async ({ user }: TestCallerConfig = { user: defa
4443
const { router } = createRouter({
4544
useCases,
4645
dbApi,
47-
coreContext: context,
4846
keycloakParams: undefined,
4947
redirectUrl: undefined,
5048
externalSoftwareDataOrigin,

api/src/rpc/router.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import superjson from "superjson";
88
import type { Equals, ReturnType } from "tsafe";
99
import { assert } from "tsafe/assert";
1010
import { z } from "zod";
11-
import type { Context as CoreContext } from "../core";
1211
import { DbApiV2 } from "../core/ports/DbApiV2";
1312
import {
1413
ExternalDataOrigin,
@@ -35,7 +34,6 @@ import type { User } from "./user";
3534
export function createRouter(params: {
3635
dbApi: DbApiV2;
3736
useCases: UseCases;
38-
coreContext: CoreContext;
3937
keycloakParams:
4038
| (KeycloakParams & {
4139
organizationUserProfileAttributeName: string;
@@ -51,7 +49,6 @@ export function createRouter(params: {
5149
}) {
5250
const {
5351
useCases,
54-
coreContext,
5552
dbApi,
5653
keycloakParams,
5754
jwtClaimByUserKey,
@@ -494,7 +491,7 @@ export function createRouter(params: {
494491
});
495492
await dbApi.agent.update({ ...agent, email: newEmail });
496493
}),
497-
"getRegisteredUserCount": loggedProcedure.query(async () => coreContext.userApi.getUserCount()),
494+
"getRegisteredUserCount": loggedProcedure.query(async () => dbApi.agent.countAll()),
498495
"getTotalReferentCount": loggedProcedure.query(async () => {
499496
const referentCount = await dbApi.softwareReferent.getTotalCount();
500497
return { referentCount };

api/src/rpc/start.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,11 @@ export async function startRpcService(params: {
6868

6969
const kyselyDb = new Kysely<Database>({ dialect: createPgDialect(databaseUrl) });
7070

71-
const {
72-
dbApi,
73-
context: coreContext,
74-
useCases
75-
} = await bootstrapCore({
71+
const { dbApi, useCases } = await bootstrapCore({
7672
"dbConfig": {
7773
"dbKind": "kysely",
7874
"kyselyDb": kyselyDb
7975
},
80-
"keycloakUserApiParams":
81-
keycloakParams === undefined
82-
? undefined
83-
: {
84-
"url": keycloakParams.url,
85-
"realm": keycloakParams.realm,
86-
"adminPassword": keycloakParams.adminPassword
87-
},
8876
githubPersonalAccessTokenForApiRateLimit,
8977
"doPerPerformPeriodicalCompilation": true,
9078
// "doPerPerformPeriodicalCompilation": !isDevEnvironnement && redirectUrl === undefined,
@@ -117,7 +105,6 @@ export async function startRpcService(params: {
117105
dbApi,
118106
getSoftwareExternalDataOptions,
119107
getSoftwareExternalData,
120-
coreContext,
121108
jwtClaimByUserKey,
122109
"keycloakParams":
123110
keycloakParams === undefined

web/src/ui/pages/account/Account.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { useEffect, useState, useMemo } from "react";
1+
import { useEffect, useState } from "react";
22
import { tss } from "tss-react";
33
import { fr } from "@codegouvfr/react-dsfr";
4-
import { useTranslation, useGetOrganizationFullName, evtLang } from "ui/i18n";
4+
import { useTranslation, evtLang } from "ui/i18n";
55
import { assert } from "tsafe/assert";
66
import { Equals } from "tsafe";
77
import { declareComponentKeys } from "i18nifty";
@@ -209,9 +209,6 @@ function AccountReady(props: { className?: string }) {
209209
}
210210

211211
const useStyles = tss.withName({ Account }).create({
212-
organizationInput: {
213-
flex: 1
214-
},
215212
"oidcInfos": {
216213
"paddingTop": fr.spacing("6v"),
217214
"maxWidth": 650,

0 commit comments

Comments
 (0)