mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
syncronize user on change with humhub
This commit is contained in:
parent
24224e9638
commit
6cb7c783f0
@ -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()
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
42
backend/src/graphql/resolver/util/syncHumhub.ts
Normal file
42
backend/src/graphql/resolver/util/syncHumhub.ts
Normal 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,
|
||||
})
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user