From 19720ee6ca31a575d2b3bf46fb433e7fc3a1d73b Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Tue, 8 Apr 2025 18:33:16 +0200 Subject: [PATCH] adjust configs, add GMS_PLAYGROUND_ROUTE, move export script into apis folder like in humhub --- admin/vite.config.js | 4 ++ backend/package.json | 3 +- .../gmsUsers.ts => apis/gms/ExportUsers.ts} | 23 ++----- backend/src/config/index.ts | 1 + backend/src/config/schema.ts | 7 +++ .../util/authenticateGmsUserPlayground.ts | 2 +- .../graphql/resolver/util/sendUserToGms.ts | 8 ++- backend/src/seeds/gmsUserList.ts | 60 ------------------- frontend/vite.config.js | 4 ++ 9 files changed, 28 insertions(+), 84 deletions(-) rename backend/src/{seeds/gmsUsers.ts => apis/gms/ExportUsers.ts} (83%) delete mode 100644 backend/src/seeds/gmsUserList.ts diff --git a/admin/vite.config.js b/admin/vite.config.js index 29dd0a69a..72f7e8c47 100644 --- a/admin/vite.config.js +++ b/admin/vite.config.js @@ -40,6 +40,10 @@ export default defineConfig(async ({ command }) => { host: CONFIG.ADMIN_MODULE_HOST, // '0.0.0.0', port: CONFIG.ADMIN_MODULE_PORT, // 8080, }, + preview: { + host: CONFIG.ADMIN_MODULE_HOST, // '0.0.0.0', + port: CONFIG.ADMIN_MODULE_PORT, // 8080, + }, resolve: { alias: { '@': path.resolve(__dirname, './src'), diff --git a/backend/package.json b/backend/package.json index 2d4756afb..880d48a53 100644 --- a/backend/package.json +++ b/backend/package.json @@ -16,8 +16,7 @@ "test": "cross-env TZ=UTC NODE_ENV=development jest --runInBand --forceExit --detectOpenHandles", "seed": "cross-env TZ=UTC NODE_ENV=development ts-node -r tsconfig-paths/register src/seeds/index.ts", "klicktipp": "cross-env TZ=UTC NODE_ENV=development ts-node -r tsconfig-paths/register src/util/executeKlicktipp.ts", - "gmsusers": "cross-env TZ=UTC NODE_ENV=development ts-node -r tsconfig-paths/register src/seeds/gmsUsers.ts", - "gmsuserList": "cross-env TZ=UTC NODE_ENV=development ts-node -r tsconfig-paths/register src/seeds/gmsUserList.ts", + "gmsusers": "cross-env TZ=UTC NODE_ENV=development ts-node -r tsconfig-paths/register src/apis/gms/ExportUsers.ts", "humhubUserExport": "cross-env TZ=UTC NODE_ENV=development ts-node -r tsconfig-paths/register src/apis/humhub/ExportUsers.ts", "locales": "scripts/sort.sh" }, diff --git a/backend/src/seeds/gmsUsers.ts b/backend/src/apis/gms/ExportUsers.ts similarity index 83% rename from backend/src/seeds/gmsUsers.ts rename to backend/src/apis/gms/ExportUsers.ts index 6f059697d..4b8a303f6 100644 --- a/backend/src/seeds/gmsUsers.ts +++ b/backend/src/apis/gms/ExportUsers.ts @@ -4,7 +4,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-return */ -import { entities } from '@entity/index' import { User as DbUser } from '@entity/User' // import { createTestClient } from 'apollo-server-testing' @@ -18,6 +17,8 @@ import { LogError } from '@/server/LogError' import { backendLogger as logger } from '@/server/logger' CONFIG.EMAIL = false +// use force to copy over all user even if gmsRegistered is set to true +const forceMode = process.argv.includes('--force') const context = { token: '', @@ -31,21 +32,6 @@ const context = { clientTimezoneOffset: 0, } -export const cleanDB = async () => { - // this only works as long we do not have foreign key constraints - for (const entity of entities) { - await resetEntity(entity) - } -} - -const resetEntity = async (entity: any) => { - const items = await entity.find({ withDeleted: true }) - if (items.length > 0) { - const ids = items.map((e: any) => e.id) - await entity.delete(ids) - } -} - const run = async () => { const server = await createServer(context) // const seedClient = createTestClient(server.apollo) @@ -59,8 +45,7 @@ const run = async () => { const userIds = await DbUser.createQueryBuilder() .select('id') .where({ foreign: false }) - // .andWhere('deleted_at is null') - // .andWhere({ gmsRegistered: false }) + .andWhere('deleted_at is null') .getRawMany() logger.debug('userIds:', userIds) @@ -73,7 +58,7 @@ const run = async () => { if (user) { logger.debug('found local User:', user) if (user.gmsAllowed) { - await sendUserToGms(user, homeCom) + await sendUserToGms(user, homeCom, forceMode) /* const gmsUser = new GmsUser(user) try { diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 32118e248..af62fc76b 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -138,6 +138,7 @@ const gms = { // koordinates of Illuminz-instance of GMS GMS_API_URL: process.env.GMS_API_URL ?? 'http://localhost:4044/', GMS_DASHBOARD_URL: process.env.GMS_DASHBOARD_URL ?? 'http://localhost:8080/', + GMS_PLAYGROUND_ROUTE: process.env.GMS_PLAYGROUND_ROUTE ?? 'usersearch-playground', // used as secret postfix attached at the gms community-auth-url endpoint ('/hook/gms/' + 'secret') GMS_WEBHOOK_SECRET: process.env.GMS_WEBHOOK_SECRET ?? 'secret', } diff --git a/backend/src/config/schema.ts b/backend/src/config/schema.ts index 19eed15ed..0158dfdaa 100644 --- a/backend/src/config/schema.ts +++ b/backend/src/config/schema.ts @@ -279,6 +279,13 @@ export const schema = Joi.object({ .default('http://localhost:8080/') .description('The URL for the GMS dashboard'), + GMS_PLAYGROUND_ROUTE: Joi.string() + .pattern(/^[\w_-]*$/) + .default('usersearch-playground') + .description( + 'gms frontend playground route, playground for standalone playground, usersearch-playground for old', + ), + GMS_WEBHOOK_SECRET: Joi.string() .min(1) .default('secret') diff --git a/backend/src/graphql/resolver/util/authenticateGmsUserPlayground.ts b/backend/src/graphql/resolver/util/authenticateGmsUserPlayground.ts index 11e92ce53..41307eb55 100644 --- a/backend/src/graphql/resolver/util/authenticateGmsUserPlayground.ts +++ b/backend/src/graphql/resolver/util/authenticateGmsUserPlayground.ts @@ -14,7 +14,7 @@ export async function authenticateGmsUserPlayground( const result = new GmsUserAuthenticationResult() const dashboardUrl = ensureUrlEndsWithSlash(CONFIG.GMS_DASHBOARD_URL) - result.url = dashboardUrl.concat('usersearch-playground') + result.url = dashboardUrl.concat(CONFIG.GMS_PLAYGROUND_ROUTE) result.token = await verifyAuthToken(dbUser.communityUuid, token) logger.info('GmsUserAuthenticationResult:', result) return result diff --git a/backend/src/graphql/resolver/util/sendUserToGms.ts b/backend/src/graphql/resolver/util/sendUserToGms.ts index 22af795d4..90351125f 100644 --- a/backend/src/graphql/resolver/util/sendUserToGms.ts +++ b/backend/src/graphql/resolver/util/sendUserToGms.ts @@ -7,14 +7,18 @@ import { CONFIG } from '@/config' import { LogError } from '@/server/LogError' import { backendLogger as logger } from '@/server/logger' -export async function sendUserToGms(user: DbUser, homeCom: DbCommunity): Promise { +export async function sendUserToGms( + user: DbUser, + homeCom: DbCommunity, + alwaysCreateUser?: boolean, +): Promise { if (homeCom.gmsApiKey === null) { throw new LogError('HomeCommunity needs GMS-ApiKey to publish user data to GMS.') } logger.debug('User send to GMS:', user) const gmsUser = new GmsUser(user) try { - if (!user.gmsRegistered && user.gmsRegisteredAt === null) { + if (alwaysCreateUser === true || (!user.gmsRegistered && user.gmsRegisteredAt === null)) { logger.debug('create user in gms:', gmsUser) // eslint-disable-next-line @typescript-eslint/no-unsafe-argument if (await createGmsUser(homeCom.gmsApiKey, gmsUser)) { diff --git a/backend/src/seeds/gmsUserList.ts b/backend/src/seeds/gmsUserList.ts deleted file mode 100644 index 7603ca116..000000000 --- a/backend/src/seeds/gmsUserList.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-unsafe-return */ - -import { entities } from '@entity/index' -// import { createTestClient } from 'apollo-server-testing' - -import { CONFIG } from '@/config' -import { createServer } from '@/server/createServer' -import { backendLogger as logger } from '@/server/logger' - -CONFIG.EMAIL = false - -const context = { - token: '', - setHeaders: { - push: (value: { key: string; value: string }): void => { - context.token = value.value - }, - // eslint-disable-next-line @typescript-eslint/no-empty-function - forEach: (): void => {}, - }, - clientTimezoneOffset: 0, -} - -export const cleanDB = async () => { - // this only works as long we do not have foreign key constraints - for (const entity of entities) { - await resetEntity(entity) - } -} - -const resetEntity = async (entity: any) => { - const items = await entity.find({ withDeleted: true }) - if (items.length > 0) { - const ids = items.map((e: any) => e.id) - await entity.delete(ids) - } -} - -const run = async () => { - const server = await createServer(context) - // const seedClient = createTestClient(server.apollo) - const { con } = server - - // test GMS-Api Client - try { - // const gmsComArray = await communityList() - // logger.debug('GMS-Community-List:', gmsComArray) - // const gmsUserArray = await userList() - // logger.debug('GMS-Community-User-List:', gmsUserArray) - } catch (err) { - logger.error('Error in GMS-API:', err) - } - await con.close() -} - -void run() diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 42e025e4b..28a222388 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -48,6 +48,10 @@ export default defineConfig(async ({ command }) => { minify: CONFIG.PRODUCTION === true, }, }, + preview: { + host: CONFIG.FRONTEND_MODULE_HOST, // '0.0.0.0', + port: CONFIG.FRONTEND_MODULE_PORT, // 3000, + }, resolve: { alias: { '@': path.resolve(__dirname, './src'),