mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
first draft for update gmsUser
This commit is contained in:
parent
eedd9fa3ac
commit
cf13a9a7ec
@ -117,30 +117,69 @@ export async function userByUuid(uuid: string): Promise<GmsUser[] | string | und
|
||||
*/
|
||||
|
||||
export async function createGmsUser(apiKey: string, user: GmsUser): Promise<boolean> {
|
||||
const baseUrl = CONFIG.GMS_URL.endsWith('/') ? CONFIG.GMS_URL : CONFIG.GMS_URL.concat('/')
|
||||
const service = 'community-user'
|
||||
const config = {
|
||||
headers: {
|
||||
accept: 'application/json',
|
||||
language: 'en',
|
||||
timezone: 'UTC',
|
||||
connection: 'keep-alive',
|
||||
authorization: apiKey,
|
||||
},
|
||||
}
|
||||
try {
|
||||
const result = await axios.post(baseUrl.concat(service), user, config)
|
||||
logger.debug('POST-Response of community-user:', result)
|
||||
if (result.status !== 200) {
|
||||
throw new LogError('HTTP Status Error in community-user:', result.status, result.statusText)
|
||||
if (CONFIG.GMS_ACTIVE) {
|
||||
const baseUrl = CONFIG.GMS_URL.endsWith('/') ? CONFIG.GMS_URL : CONFIG.GMS_URL.concat('/')
|
||||
const service = 'community-user'
|
||||
const config = {
|
||||
headers: {
|
||||
accept: 'application/json',
|
||||
language: 'en',
|
||||
timezone: 'UTC',
|
||||
connection: 'keep-alive',
|
||||
authorization: apiKey,
|
||||
},
|
||||
}
|
||||
logger.debug('responseData:', result.data.responseData)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
// const gmsUser = JSON.parse(result.data.responseData)
|
||||
// logger.debug('gmsUser:', gmsUser)
|
||||
return true
|
||||
} catch (error: any) {
|
||||
logger.error('Error in Get community-user:', error)
|
||||
throw new LogError(error.message)
|
||||
try {
|
||||
const result = await axios.post(baseUrl.concat(service), user, config)
|
||||
logger.debug('POST-Response of community-user:', result)
|
||||
if (result.status !== 200) {
|
||||
throw new LogError('HTTP Status Error in community-user:', result.status, result.statusText)
|
||||
}
|
||||
logger.debug('responseData:', result.data.responseData)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
// const gmsUser = JSON.parse(result.data.responseData)
|
||||
// logger.debug('gmsUser:', gmsUser)
|
||||
return true
|
||||
} catch (error: any) {
|
||||
logger.error('Error in post community-user:', error)
|
||||
throw new LogError(error.message)
|
||||
}
|
||||
} else {
|
||||
logger.info('GMS-Communication disabled per ConfigKey GMS_ACTIVE=false!')
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateGmsUser(apiKey: string, user: GmsUser): Promise<boolean> {
|
||||
if (CONFIG.GMS_ACTIVE) {
|
||||
const baseUrl = CONFIG.GMS_URL.endsWith('/') ? CONFIG.GMS_URL : CONFIG.GMS_URL.concat('/')
|
||||
const service = 'community-user'
|
||||
const config = {
|
||||
headers: {
|
||||
accept: 'application/json',
|
||||
language: 'en',
|
||||
timezone: 'UTC',
|
||||
connection: 'keep-alive',
|
||||
authorization: apiKey,
|
||||
},
|
||||
}
|
||||
try {
|
||||
const result = await axios.patch(baseUrl.concat(service), user, config)
|
||||
logger.debug('PATCH-Response of community-user:', result)
|
||||
if (result.status !== 200) {
|
||||
throw new LogError('HTTP Status Error in community-user:', result.status, result.statusText)
|
||||
}
|
||||
logger.debug('responseData:', result.data.responseData)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
// const gmsUser = JSON.parse(result.data.responseData)
|
||||
// logger.debug('gmsUser:', gmsUser)
|
||||
return true
|
||||
} catch (error: any) {
|
||||
logger.error('Error in patch community-user:', error)
|
||||
throw new LogError(error.message)
|
||||
}
|
||||
} else {
|
||||
logger.info('GMS-Communication disabled per ConfigKey GMS_ACTIVE=false!')
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ export class GmsUser {
|
||||
constructor(user: dbUser) {
|
||||
this.userUuid = user.gradidoID
|
||||
// this.communityUuid = user.communityUuid
|
||||
this.language = user.language
|
||||
this.email = this.getGmsEmail(user)
|
||||
this.countryCode = this.getGmsCountryCode(user)
|
||||
this.mobile = this.getGmsPhone(user)
|
||||
|
||||
@ -30,6 +30,8 @@ import { SearchAdminUsersResult } from '@model/AdminUser'
|
||||
import { User } from '@model/User'
|
||||
import { UserAdmin, SearchUsersResult } from '@model/UserAdmin'
|
||||
|
||||
import { updateGmsUser } from '@/apis/gms/GmsClient'
|
||||
import { GmsUser } from '@/apis/gms/model/GmsUser'
|
||||
import { subscribe } from '@/apis/KlicktippController'
|
||||
import { encode } from '@/auth/JWT'
|
||||
import { RIGHTS } from '@/auth/RIGHTS'
|
||||
@ -69,6 +71,7 @@ import { randombytes_random } from 'sodium-native'
|
||||
|
||||
import { FULL_CREATION_AVAILABLE } from './const/const'
|
||||
import { getHomeCommunity } from './util/communities'
|
||||
import { compareGmsRelevantUserSettings } from './util/compareGmsRelevantUserSettings'
|
||||
import { getUserCreations } from './util/creations'
|
||||
import { findUserByIdentifier } from './util/findUserByIdentifier'
|
||||
import { findUsers } from './util/findUsers'
|
||||
@ -573,6 +576,8 @@ export class UserResolver {
|
||||
}
|
||||
|
||||
const user = getUser(context)
|
||||
const backupOriginalUser = user
|
||||
|
||||
// try {
|
||||
if (firstName) {
|
||||
user.firstName = firstName
|
||||
@ -649,6 +654,17 @@ export class UserResolver {
|
||||
logger.info('updateUserInfos() successfully finished...')
|
||||
await EVENT_USER_INFO_UPDATE(user)
|
||||
|
||||
// validate if user settings are changed with relevance to update gms-user
|
||||
if (compareGmsRelevantUserSettings(user, backupOriginalUser)) {
|
||||
logger.debug(`changed user-settings relevant for gms-user update...`)
|
||||
const homeCom = await getHomeCommunity()
|
||||
if (homeCom.gmsApiKey !== null) {
|
||||
logger.debug(`gms-user update...`, user)
|
||||
await updateGmsUser(homeCom.gmsApiKey, new GmsUser(user))
|
||||
logger.debug(`gms-user update successfully.`)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
import { Point } from '@dbTools/typeorm'
|
||||
import { User as DbUser } from '@entity/User'
|
||||
|
||||
import { LogError } from '@/server/LogError'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
|
||||
import { Point2Location } from './Location2Point'
|
||||
|
||||
export function compareGmsRelevantUserSettings(orgUser: DbUser, changedUser: DbUser): boolean {
|
||||
if (!orgUser && !changedUser) {
|
||||
throw new LogError('comparison without any user is impossible')
|
||||
}
|
||||
logger.debug('compareGmsRelevantUserSettings:', orgUser, changedUser)
|
||||
if (orgUser.alias !== changedUser.alias) {
|
||||
return true
|
||||
}
|
||||
if (orgUser.firstName !== changedUser.firstName || orgUser.lastName !== changedUser.lastName) {
|
||||
return true
|
||||
}
|
||||
if (orgUser.gmsAllowed !== changedUser.gmsAllowed) {
|
||||
return true
|
||||
}
|
||||
if (orgUser.gmsPublishLocation !== changedUser.gmsPublishLocation) {
|
||||
return true
|
||||
}
|
||||
if (orgUser.gmsPublishName !== changedUser.gmsPublishName) {
|
||||
return true
|
||||
}
|
||||
if (orgUser.language !== changedUser.language) {
|
||||
return true
|
||||
}
|
||||
if (orgUser.location === null && changedUser.location !== null) {
|
||||
return true
|
||||
}
|
||||
if (orgUser.location !== null && changedUser.location === null) {
|
||||
return true
|
||||
}
|
||||
if (orgUser.location !== null && changedUser.location !== null) {
|
||||
const orgLocation = Point2Location(orgUser.location as Point)
|
||||
const changedLocation = Point2Location(changedUser.location as Point)
|
||||
if (
|
||||
orgLocation.latitude !== changedLocation.latitude ||
|
||||
orgLocation.longitude !== changedLocation.longitude
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user