check firstname length for humhub

This commit is contained in:
einhornimmond 2025-04-24 15:27:30 +02:00
parent 456725aeae
commit 21be12f3b0
2 changed files with 17 additions and 1 deletions

View File

@ -88,7 +88,7 @@ async function main() {
const humhubUsers = await loadUsersFromHumHub(humHubClient)
let dbUserCount = 0
const executedHumhubActionsCount = [0, 0, 0, 0]
const executedHumhubActionsCount = [0, 0, 0, 0, 0]
do {
try {
@ -121,6 +121,7 @@ async function main() {
updatedCount: executedHumhubActionsCount[ExecutedHumhubAction.UPDATE],
skippedCount: executedHumhubActionsCount[ExecutedHumhubAction.SKIP],
deletedCount: executedHumhubActionsCount[ExecutedHumhubAction.DELETE],
validationErrorCount: executedHumhubActionsCount[ExecutedHumhubAction.VALIDATION_ERROR],
})
}

View File

@ -1,6 +1,7 @@
import { User } from '@entity/User'
import { LogError } from '@/server/LogError'
import { backendLogger as logger } from '@/server/logger'
import { isHumhubUserIdenticalToDbUser } from './compareHumhubUserDbUser'
import { HumHubClient } from './HumHubClient'
@ -12,7 +13,18 @@ export enum ExecutedHumhubAction {
CREATE,
SKIP,
DELETE,
VALIDATION_ERROR,
}
// todo: replace with full validation (schema)
function isValid(postUser: PostUser, userId: number): boolean {
if (postUser.profile.firstname.length > 20) {
logger.error('firstname too long for humhub, for user with id:', userId)
return false
}
return true
}
/**
* Trigger action according to conditions
* | User exist on humhub | export to humhub allowed | changes in user data | ACTION
@ -30,6 +42,9 @@ export async function syncUser(
humhubUsers: Map<string, GetUser>,
): Promise<ExecutedHumhubAction> {
const postUser = new PostUser(user)
if (!isValid(postUser, user.id)) {
return ExecutedHumhubAction.VALIDATION_ERROR
}
const humhubUser = humhubUsers.get(postUser.account.username)
const humHubClient = HumHubClient.getInstance()
if (!humHubClient) {