mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
refactor, temp fix for username from initals maybe double
This commit is contained in:
parent
6b68e78b86
commit
7bbdd8d3d4
23
backend/src/apis/humhub/model/AbstractUser.ts
Normal file
23
backend/src/apis/humhub/model/AbstractUser.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { User } from '@entity/User'
|
||||
|
||||
import { PublishNameLogic } from '@/data/PublishName.logic'
|
||||
import { PublishNameType } from '@/graphql/enum/PublishNameType'
|
||||
|
||||
import { Account } from './Account'
|
||||
import { Profile } from './Profile'
|
||||
|
||||
export abstract class AbstractUser {
|
||||
public constructor(user: User) {
|
||||
this.account = new Account(user)
|
||||
this.profile = new Profile(user)
|
||||
// temp fix for prevent double usernames in humhub, if the username ist created from initials
|
||||
const publishNameLogic = new PublishNameLogic(user)
|
||||
if (publishNameLogic.isUsernameFromInitials(user.humhubPublishName as PublishNameType)) {
|
||||
this.profile.firstname = this.account.username
|
||||
this.account.username = user.gradidoID
|
||||
}
|
||||
}
|
||||
|
||||
account: Account
|
||||
profile: Profile
|
||||
}
|
||||
@ -1,19 +1,15 @@
|
||||
import { User } from '@entity/User'
|
||||
|
||||
import { Account } from './Account'
|
||||
import { Profile } from './Profile'
|
||||
import { AbstractUser } from './AbstractUser'
|
||||
|
||||
export class GetUser {
|
||||
export class GetUser extends AbstractUser {
|
||||
public constructor(user: User, id: number) {
|
||||
super(user)
|
||||
this.id = id
|
||||
this.account = new Account(user)
|
||||
this.profile = new Profile(user)
|
||||
}
|
||||
|
||||
id: number
|
||||
guid: string
|
||||
// eslint-disable-next-line camelcase
|
||||
display_name: string
|
||||
account: Account
|
||||
profile: Profile
|
||||
}
|
||||
|
||||
@ -1,16 +1,7 @@
|
||||
import { User } from '@entity/User'
|
||||
|
||||
import { Account } from './Account'
|
||||
import { AbstractUser } from './AbstractUser'
|
||||
import { Password } from './Password'
|
||||
import { Profile } from './Profile'
|
||||
|
||||
export class PostUser {
|
||||
public constructor(user: User) {
|
||||
this.account = new Account(user)
|
||||
this.profile = new Profile(user)
|
||||
}
|
||||
|
||||
account: Account
|
||||
profile: Profile
|
||||
// only add password as filed, rest the same as AbstractUser
|
||||
export class PostUser extends AbstractUser {
|
||||
password: Password
|
||||
}
|
||||
|
||||
@ -67,17 +67,25 @@ export class PublishNameLogic {
|
||||
* else return user.firstName[0,2] + user.lastName[0,2] for publishNameType = [PUBLISH_NAME_ALIAS_OR_INITALS, PUBLISH_NAME_INITIALS]
|
||||
*/
|
||||
public getUsername(publishNameType: PublishNameType): string {
|
||||
if (
|
||||
[
|
||||
PublishNameType.PUBLISH_NAME_ALIAS_OR_INITALS,
|
||||
PublishNameType.PUBLISH_NAME_INITIALS,
|
||||
].includes(publishNameType)
|
||||
) {
|
||||
return publishNameType === PublishNameType.PUBLISH_NAME_ALIAS_OR_INITALS && this.hasAlias()
|
||||
? this.filterOutInvalidChar(this.user.alias)
|
||||
: this.firstUpperCaseSecondLowerCase(this.filterOutInvalidChar(this.user.firstName)) +
|
||||
this.firstUpperCaseSecondLowerCase(this.filterOutInvalidChar(this.user.lastName))
|
||||
if (this.isUsernameFromInitials(publishNameType)) {
|
||||
return this.filterOutInvalidChar(
|
||||
this.firstUpperCaseSecondLowerCase(this.user.firstName) +
|
||||
this.firstUpperCaseSecondLowerCase(this.user.lastName),
|
||||
)
|
||||
} else if (this.isUsernameFromAlias(publishNameType)) {
|
||||
return this.filterOutInvalidChar(this.user.alias)
|
||||
}
|
||||
return this.hasAlias() ? this.user.alias : this.user.gradidoID
|
||||
return this.user.gradidoID
|
||||
}
|
||||
|
||||
public isUsernameFromInitials(publishNameType: PublishNameType): boolean {
|
||||
return (
|
||||
PublishNameType.PUBLISH_NAME_INITIALS === publishNameType ||
|
||||
(PublishNameType.PUBLISH_NAME_ALIAS_OR_INITALS === publishNameType && !this.hasAlias())
|
||||
)
|
||||
}
|
||||
|
||||
public isUsernameFromAlias(publishNameType: PublishNameType): boolean {
|
||||
return PublishNameType.PUBLISH_NAME_ALIAS_OR_INITALS === publishNameType && this.hasAlias()
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ import { updateGmsUser } from '@/apis/gms/GmsClient'
|
||||
import { GmsUser } from '@/apis/gms/model/GmsUser'
|
||||
import { HumHubClient } from '@/apis/humhub/HumHubClient'
|
||||
import { GetUser } from '@/apis/humhub/model/GetUser'
|
||||
import { PostUser } from '@/apis/humhub/model/PostUser'
|
||||
import { subscribe } from '@/apis/KlicktippController'
|
||||
import { encode } from '@/auth/JWT'
|
||||
import { RIGHTS } from '@/auth/RIGHTS'
|
||||
@ -170,9 +171,9 @@ export class UserResolver {
|
||||
let humhubUserPromise: Promise<IRestResponse<GetUser>> | undefined
|
||||
const klicktippStatePromise = getKlicktippState(dbUser.emailContact.email)
|
||||
if (CONFIG.HUMHUB_ACTIVE && dbUser.humhubAllowed) {
|
||||
const publishNameLogic = new PublishNameLogic(dbUser)
|
||||
const getHumhubUser = new PostUser(dbUser)
|
||||
humhubUserPromise = HumHubClient.getInstance()?.userByUsernameAsync(
|
||||
publishNameLogic.getUsername(dbUser.humhubPublishName as PublishNameType),
|
||||
getHumhubUser.account.username,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user