adjust configs, add GMS_PLAYGROUND_ROUTE, move export script into apis folder like in humhub

This commit is contained in:
einhornimmond 2025-04-08 18:33:16 +02:00
parent e2a3725679
commit 19720ee6ca
9 changed files with 28 additions and 84 deletions

View File

@ -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'),

View File

@ -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"
},

View File

@ -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 {

View File

@ -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',
}

View File

@ -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')

View File

@ -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

View File

@ -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<void> {
export async function sendUserToGms(
user: DbUser,
homeCom: DbCommunity,
alwaysCreateUser?: boolean,
): Promise<void> {
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)) {

View File

@ -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()

View File

@ -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'),