syncronize user on change with humhub

This commit is contained in:
einhornimmond 2024-04-19 19:21:24 +02:00
parent 24224e9638
commit 6cb7c783f0
3 changed files with 47 additions and 1 deletions

View File

@ -24,7 +24,7 @@ function getUsersPage(page: number, limit: number): Promise<[User[], number]> {
/**
* @param client
* @returns user map indiced with email
* @returns user map indices with email
*/
async function loadUsersFromHumHub(client: HumHubClient): Promise<Map<string, GetUser>> {
const start = new Date().getTime()

View File

@ -79,6 +79,7 @@ import { getKlicktippState } from './util/getKlicktippState'
import { Location2Point } from './util/Location2Point'
import { setUserRole, deleteUserRole } from './util/modifyUserRole'
import { sendUserToGms } from './util/sendUserToGms'
import { syncHumhub } from './util/syncHumhub'
import { validateAlias } from './util/validateAlias'
const LANGUAGES = ['de', 'en', 'es', 'fr', 'nl']
@ -670,6 +671,9 @@ export class UserResolver {
logger.debug(`gms-user update successfully.`)
}
}
if (CONFIG.HUMHUB_ACTIVE) {
await syncHumhub(updateUserInfosArgs, user)
}
return true
}

View File

@ -0,0 +1,42 @@
import { User } from '@entity/User'
import { HumHubClient } from '@/apis/humhub/HumHubClient'
import { GetUser } from '@/apis/humhub/model/GetUser'
import { syncUser } from '@/apis/humhub/syncUser'
import { UpdateUserInfosArgs } from '@/graphql/arg/UpdateUserInfosArgs'
import { backendLogger as logger } from '@/server/logger'
export async function syncHumhub(
updateUserInfosArg: UpdateUserInfosArgs,
user: User,
): Promise<void> {
// check for humhub relevant changes
if (
!updateUserInfosArg.alias &&
!updateUserInfosArg.firstName &&
!updateUserInfosArg.lastName &&
!updateUserInfosArg.humhubAllowed &&
!updateUserInfosArg.humhubPublishName &&
!updateUserInfosArg.language
) {
return
}
logger.debug('changed user-settings relevant for humhub-user update...')
const humhubClient = HumHubClient.getInstance()
if (!humhubClient) {
return
}
logger.debug('retrieve user from humhub')
const humhubUser = await humhubClient.userByEmail(user.emailContact.email)
const humhubUsers = new Map<string, GetUser>()
if (humhubUser) {
humhubUsers.set(user.emailContact.email, humhubUser)
}
logger.debug('update user at humhub')
const result = await syncUser(user, humhubUsers)
logger.info('finished sync user with humhub', {
localId: user.id,
externId: humhubUser?.id,
result,
})
}