From 7bbdd8d3d407ec584fb2648eea972c38d75bec61 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Mon, 16 Dec 2024 14:26:24 +0100 Subject: [PATCH 1/4] refactor, temp fix for username from initals maybe double --- backend/src/apis/humhub/model/AbstractUser.ts | 23 ++++++++++++++ backend/src/apis/humhub/model/GetUser.ts | 10 ++----- backend/src/apis/humhub/model/PostUser.ts | 15 ++-------- backend/src/data/PublishName.logic.ts | 30 ++++++++++++------- backend/src/graphql/resolver/UserResolver.ts | 5 ++-- 5 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 backend/src/apis/humhub/model/AbstractUser.ts diff --git a/backend/src/apis/humhub/model/AbstractUser.ts b/backend/src/apis/humhub/model/AbstractUser.ts new file mode 100644 index 000000000..8f876f053 --- /dev/null +++ b/backend/src/apis/humhub/model/AbstractUser.ts @@ -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 +} diff --git a/backend/src/apis/humhub/model/GetUser.ts b/backend/src/apis/humhub/model/GetUser.ts index 7d9814fc3..8f50c8676 100644 --- a/backend/src/apis/humhub/model/GetUser.ts +++ b/backend/src/apis/humhub/model/GetUser.ts @@ -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 } diff --git a/backend/src/apis/humhub/model/PostUser.ts b/backend/src/apis/humhub/model/PostUser.ts index a164440fd..b63c038cf 100644 --- a/backend/src/apis/humhub/model/PostUser.ts +++ b/backend/src/apis/humhub/model/PostUser.ts @@ -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 } diff --git a/backend/src/data/PublishName.logic.ts b/backend/src/data/PublishName.logic.ts index d3643d633..e49c3e73a 100644 --- a/backend/src/data/PublishName.logic.ts +++ b/backend/src/data/PublishName.logic.ts @@ -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() } } diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 0302c7860..4e1504b02 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -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> | 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, ) } From 3a8c70bcf6dba714202ebe654dd46b6165c39dec Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Mon, 16 Dec 2024 14:54:42 +0100 Subject: [PATCH 2/4] fix test --- backend/src/graphql/resolver/UserResolver.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index c0a707577..0a22172c6 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -112,6 +112,7 @@ beforeAll(async () => { mutate = testEnv.mutate query = testEnv.query con = testEnv.con + CONFIG.HUMHUB_ACTIVE = false await cleanDB() }) From f4bdddaa786de3a52105b19f5b85bb86312a8412 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Wed, 4 Dec 2024 20:14:21 +0100 Subject: [PATCH 3/4] fix gdt pagination --- frontend/src/components/GdtTransactionList.vue | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/GdtTransactionList.vue b/frontend/src/components/GdtTransactionList.vue index 046482753..e6b4aa506 100644 --- a/frontend/src/components/GdtTransactionList.vue +++ b/frontend/src/components/GdtTransactionList.vue @@ -29,7 +29,7 @@ @@ -61,13 +60,16 @@ export default { }, data() { return { - currentPage: this.value, + currentPage: this.modelValue, link: 'https://gradido.net/' + this.$store.state.language + '/memberships/', } }, watch: { - currentPage() { - if (this.modelValue !== this.currentPage) this.$emit('input', this.currentPage) + modelValue(newValue) { + this.currentPage = newValue + }, + currentPage(newValue) { + if (this.modelValue !== newValue) this.$emit('update:modelValue', newValue) }, }, } From 7978d2f65ea14e7928f54f815e5198ce1cf437d2 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Mon, 16 Dec 2024 15:07:08 +0100 Subject: [PATCH 4/4] fix test --- frontend/src/components/GdtTransactionList.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/GdtTransactionList.spec.js b/frontend/src/components/GdtTransactionList.spec.js index b1b84f1f5..a8781419d 100644 --- a/frontend/src/components/GdtTransactionList.spec.js +++ b/frontend/src/components/GdtTransactionList.spec.js @@ -122,7 +122,7 @@ describe('GdtTransactionList', () => { it('emits input event after currentPage changes', async () => { await wrapper.findComponent({ name: 'BPagination' }).vm.$emit('update:modelValue', 2) await nextTick() - expect(wrapper.emitted('input')).toEqual([[2]]) + expect(wrapper.emitted('update:modelValue')).toEqual([[2]]) }) describe('pagination buttons', () => {