separat enum for multi purpose publish name type

This commit is contained in:
einhornimmond 2024-04-15 18:54:31 +02:00
parent 426488ff3e
commit cbf8439d6e
11 changed files with 280 additions and 38 deletions

View File

@ -3,6 +3,7 @@ import { ArgsType, Field, InputType, Int } from 'type-graphql'
import { GmsPublishLocationType } from '@enum/GmsPublishLocationType'
import { GmsPublishNameType } from '@enum/GmsPublishNameType'
import { PublishNameType } from '@enum/PublishNameType'
import { Location } from '@model/Location'
import { isValidLocation } from '@/graphql/validator/Location'
@ -58,9 +59,9 @@ export class UpdateUserInfosArgs {
@IsEnum(GmsPublishNameType)
gmsPublishName?: GmsPublishNameType | null
@Field(() => GmsPublishNameType, { nullable: true })
@IsEnum(GmsPublishNameType)
humhubPublishName?: GmsPublishNameType | null
@Field(() => PublishNameType, { nullable: true })
@IsEnum(PublishNameType)
humhubPublishName?: PublishNameType | null
@Field(() => Location, { nullable: true })
@isValidLocation()

View File

@ -0,0 +1,19 @@
import { registerEnumType } from 'type-graphql'
/**
* Enum for decide which parts from first- and last-name are allowed to be published in an extern service
*/
export enum PublishNameType {
PUBLISH_NAME_NONE = 0,
PUBLISH_NAME_INITIALS = 1,
PUBLISH_NAME_FIRST = 2,
PUBLISH_NAME_FIRST_INITIAL = 3,
PUBLISH_NAME_LAST = 4,
PUBLISH_NAME_INITIAL_LAST = 5,
PUBLISH_NAME_FULL = 6,
}
registerEnumType(PublishNameType, {
name: 'PublishNameType', // this one is mandatory
description: 'Type of first- and last-name publishing for extern service', // this one is optional
})

View File

@ -3,6 +3,7 @@ import { ObjectType, Field, Int } from 'type-graphql'
import { GmsPublishLocationType } from '@enum/GmsPublishLocationType'
import { GmsPublishNameType } from '@enum/GmsPublishNameType'
import { PublishNameType } from '@enum/PublishNameType'
import { KlickTipp } from './KlickTipp'
@ -91,8 +92,8 @@ export class User {
@Field(() => GmsPublishNameType, { nullable: true })
gmsPublishName: GmsPublishNameType | null
@Field(() => GmsPublishNameType, { nullable: true })
humhubPublishName: GmsPublishNameType | null
@Field(() => PublishNameType, { nullable: true })
humhubPublishName: PublishNameType | null
@Field(() => GmsPublishLocationType, { nullable: true })
gmsPublishLocation: GmsPublishLocationType | null

View File

@ -0,0 +1,84 @@
import { mount } from '@vue/test-utils'
import UserGMSNamingFormat from './UserGMSNamingFormat.vue'
import { toastErrorSpy } from '@test/testSetup'
const mockAPIcall = jest.fn()
const storeCommitMock = jest.fn()
const localVue = global.localVue
describe('UserNamingFormat', () => {
let wrapper
beforeEach(() => {
wrapper = mount(UserGMSNamingFormat, {
mocks: {
$t: (key) => key, // Mocking the translation function
$store: {
state: {
gmsPublishName: null,
},
commit: storeCommitMock,
},
$apollo: {
mutate: mockAPIcall,
},
},
localVue,
propsData: {
selectedOption: 'GMS_PUBLISH_NAME_ALIAS_OR_INITALS',
initialValue: 'GMS_PUBLISH_NAME_ALIAS_OR_INITALS',
attrName: 'gmsPublishName',
successMessage: 'success message',
},
})
})
afterEach(() => {
wrapper.destroy()
})
it('renders the correct dropdown options', () => {
const dropdownItems = wrapper.findAll('.dropdown-item')
expect(dropdownItems.length).toBe(5)
const labels = dropdownItems.wrappers.map((item) => item.text())
expect(labels).toEqual([
'settings.GMS.publish-name.alias-or-initials',
'settings.GMS.publish-name.initials',
'settings.GMS.publish-name.first',
'settings.GMS.publish-name.first-initial',
'settings.GMS.publish-name.name-full',
])
})
it('updates selected option on click', async () => {
const dropdownItem = wrapper.findAll('.dropdown-item').at(3) // Click the fourth item
await dropdownItem.trigger('click')
expect(wrapper.emitted().valueChanged).toBeTruthy()
expect(wrapper.emitted().valueChanged.length).toBe(1)
expect(wrapper.emitted().valueChanged[0]).toEqual(['GMS_PUBLISH_NAME_FIRST_INITIAL'])
})
it('does not update when clicking on already selected option', async () => {
const dropdownItem = wrapper.findAll('.dropdown-item').at(0) // Click the first item (which is already selected)
await dropdownItem.trigger('click')
expect(wrapper.emitted().valueChanged).toBeFalsy()
})
describe('update with error', () => {
beforeEach(async () => {
mockAPIcall.mockRejectedValue({
message: 'Ouch',
})
const dropdownItem = wrapper.findAll('.dropdown-item').at(2) // Click the third item
await dropdownItem.trigger('click')
})
it('toasts an error message', () => {
expect(toastErrorSpy).toBeCalledWith('Ouch')
})
})
})

View File

@ -0,0 +1,92 @@
<template>
<div class="user-g-m-s-naming-format">
<b-dropdown v-model="selectedOption">
<template slot="button-content">{{ selectedOptionLabel }}</template>
<b-dropdown-item
v-for="option in dropdownOptions"
@click.prevent="update(option)"
:key="option.value"
:value="option.value"
:title="option.title"
>
{{ option.label }}
</b-dropdown-item>
</b-dropdown>
</div>
</template>
<script>
import { updateUserInfos } from '@/graphql/mutations'
export default {
name: 'UserGMSNamingFormat',
props: {
initialValue: { type: String, default: 'GMS_PUBLISH_NAME_ALIAS_OR_INITALS' },
attrName: { type: String },
successMessage: { type: String },
},
data() {
return {
selectedOption: this.initialValue,
dropdownOptions: [
{
label: this.$t('settings.GMS.publish-name.alias-or-initials'),
title: this.$t('settings.GMS.publish-name.alias-or-initials-tooltip'),
value: 'GMS_PUBLISH_NAME_ALIAS_OR_INITALS',
},
{
label: this.$t('settings.GMS.publish-name.initials'),
title: this.$t('settings.GMS.publish-name.initials-tooltip'),
value: 'GMS_PUBLISH_NAME_INITIALS',
},
{
label: this.$t('settings.GMS.publish-name.first'),
title: this.$t('settings.GMS.publish-name.first-tooltip'),
value: 'GMS_PUBLISH_NAME_FIRST',
},
{
label: this.$t('settings.GMS.publish-name.first-initial'),
title: this.$t('settings.GMS.publish-name.first-initial-tooltip'),
value: 'GMS_PUBLISH_NAME_FIRST_INITIAL',
},
{
label: this.$t('settings.GMS.publish-name.name-full'),
title: this.$t('settings.GMS.publish-name.name-full-tooltip'),
value: 'GMS_PUBLISH_NAME_FULL',
},
],
}
},
computed: {
selectedOptionLabel() {
return this.dropdownOptions.find((option) => option.value === this.selectedOption).label
},
},
methods: {
async update(option) {
if (option.value === this.selectedOption) {
return
}
try {
const variables = []
variables[this.attrName] = option.value
await this.$apollo.mutate({
mutation: updateUserInfos,
variables,
})
this.toastSuccess(this.successMessage)
this.selectedOption = option.value
this.$store.commit(this.attrName, option.value)
this.$emit('valueChanged', option.value)
} catch (error) {
this.toastError(error.message)
}
},
},
}
</script>
<style>
.user-g-m-s-naming-format > .dropdown,
.user-g-m-s-naming-format > .dropdown > .dropdown-toggle > ul.dropdown-menu {
width: 100%;
}
</style>

View File

@ -26,9 +26,9 @@ describe('UserNamingFormat', () => {
},
localVue,
propsData: {
selectedOption: 'GMS_PUBLISH_NAME_ALIAS_OR_INITALS',
initialValue: 'GMS_PUBLISH_NAME_ALIAS_OR_INITALS',
attrName: 'gmsPublishName',
selectedOption: 'PUBLISH_NAME_NONE',
initialValue: 'PUBLISH_NAME_NONE',
attrName: 'publishName',
successMessage: 'success message',
},
})
@ -40,15 +40,17 @@ describe('UserNamingFormat', () => {
it('renders the correct dropdown options', () => {
const dropdownItems = wrapper.findAll('.dropdown-item')
expect(dropdownItems.length).toBe(5)
expect(dropdownItems.length).toBe(7)
const labels = dropdownItems.wrappers.map((item) => item.text())
expect(labels).toEqual([
'settings.GMS.publish-name.alias-or-initials',
'settings.GMS.publish-name.initials',
'settings.GMS.publish-name.first',
'settings.GMS.publish-name.first-initial',
'settings.GMS.publish-name.name-full',
'settings.publish-name.none',
'settings.publish-name.initials',
'settings.publish-name.first',
'settings.publish-name.first-initial',
'settings.publish-name.last',
'settings.publish-name.last-initial',
'settings.publish-name.full',
])
})
@ -58,7 +60,7 @@ describe('UserNamingFormat', () => {
expect(wrapper.emitted().valueChanged).toBeTruthy()
expect(wrapper.emitted().valueChanged.length).toBe(1)
expect(wrapper.emitted().valueChanged[0]).toEqual(['GMS_PUBLISH_NAME_FIRST_INITIAL'])
expect(wrapper.emitted().valueChanged[0]).toEqual(['PUBLISH_NAME_FIRST_INITIAL'])
})
it('does not update when clicking on already selected option', async () => {

View File

@ -20,7 +20,7 @@ import { updateUserInfos } from '@/graphql/mutations'
export default {
name: 'UserNamingFormat',
props: {
initialValue: { type: String, default: 'GMS_PUBLISH_NAME_ALIAS_OR_INITALS' },
initialValue: { type: String, default: 'PUBLISH_NAME_NONE' },
attrName: { type: String },
successMessage: { type: String },
},
@ -29,29 +29,39 @@ export default {
selectedOption: this.initialValue,
dropdownOptions: [
{
label: this.$t('settings.GMS.publish-name.alias-or-initials'),
title: this.$t('settings.GMS.publish-name.alias-or-initials-tooltip'),
value: 'GMS_PUBLISH_NAME_ALIAS_OR_INITALS',
label: this.$t('settings.publish-name.none'),
title: this.$t('settings.publish-name.none-tooltip'),
value: 'PUBLISH_NAME_NONE',
},
{
label: this.$t('settings.GMS.publish-name.initials'),
title: this.$t('settings.GMS.publish-name.initials-tooltip'),
value: 'GMS_PUBLISH_NAME_INITIALS',
label: this.$t('settings.publish-name.initials'),
title: this.$t('settings.publish-name.initials-tooltip'),
value: 'PUBLISH_NAME_INITIALS',
},
{
label: this.$t('settings.GMS.publish-name.first'),
title: this.$t('settings.GMS.publish-name.first-tooltip'),
value: 'GMS_PUBLISH_NAME_FIRST',
label: this.$t('settings.publish-name.first'),
title: this.$t('settings.publish-name.first-tooltip'),
value: 'PUBLISH_NAME_FIRST',
},
{
label: this.$t('settings.GMS.publish-name.first-initial'),
title: this.$t('settings.GMS.publish-name.first-initial-tooltip'),
value: 'GMS_PUBLISH_NAME_FIRST_INITIAL',
label: this.$t('settings.publish-name.first-initial'),
title: this.$t('settings.publish-name.first-initial-tooltip'),
value: 'PUBLISH_NAME_FIRST_INITIAL',
},
{
label: this.$t('settings.GMS.publish-name.name-full'),
title: this.$t('settings.GMS.publish-name.name-full-tooltip'),
value: 'GMS_PUBLISH_NAME_FULL',
label: this.$t('settings.publish-name.last'),
title: this.$t('settings.publish-name.last-tooltip'),
value: 'PUBLISH_NAME_LAST',
},
{
label: this.$t('settings.publish-name.last-initial'),
title: this.$t('settings.publish-name.last-initial-tooltip'),
value: 'PUBLISH_NAME_INITIAL_LAST',
},
{
label: this.$t('settings.publish-name.full'),
title: this.$t('settings.publish-name.full-tooltip'),
value: 'PUBLISH_NAME_FULL',
},
],
}

View File

@ -37,7 +37,7 @@ export const updateUserInfos = gql`
$gmsAllowed: Boolean
$humhubAllowed: Boolean
$gmsPublishName: GmsPublishNameType
$humhubPublishName: GmsPublishNameType
$humhubPublishName: PublishNameType
$gmsLocation: Location
$gmsPublishLocation: GmsPublishLocationType
) {

View File

@ -330,7 +330,6 @@
"humhub": {
"disabled": "Daten werden nicht in die Gradido Community exportiert",
"enabled": "Daten werden in die Gradido Community exportiert",
"export-consequences": "In der Gradido Community können dich alle Benutzer mit deinem Vor- und Nachnamen finden.",
"naming-format": "Namensformat in der Gradido Community",
"publish-name": {
"updated": "Namensformat für die Gradido Community aktualisiert."
@ -374,6 +373,22 @@
},
"subtitle": "Wenn du dein Passwort vergessen hast, kannst du es hier zurücksetzen."
},
"publish-name": {
"none": "Keine",
"none-tooltip": "Vorname und Nachname bleiben leer",
"first": "Vorname",
"first-tooltip": "Nur der Vornamen, z.B. Max",
"first-initial": "Vorname und Initiale",
"first-initial-tooltip": "Vornamen plus Anfangsbuchstabe des Nachnamens, z.B. Max M.",
"last": "Nachname",
"last-tooltip": "Nur der Nachname, z.B. Mustermann",
"last-initial": "Initiale und Nachname",
"last-initial-tooltip": "Anfangsbuchstabe des Vornamen plus Nachname, z.B. M. Mustermann",
"initials": "Initialen",
"initials-tooltip": "Nur die Initialen von Vor- und Nachname, z.B. M. M.",
"full": "Ganzer Name",
"full-tooltip": "Vollständiger Name: Vorname plus Nachname, z.B. Max Mustermann"
},
"showAmountGDD": "Dein GDD Betrag ist sichtbar.",
"showAmountGDT": "Dein GDT Betrag ist sichtbar.",
"username": {

View File

@ -330,7 +330,6 @@
"humhub": {
"disabled": "Data not exported into the Gradido Community",
"enabled": "Data exported into the Gradido Community",
"export-consequences": "In the Gradido Community, all users can find you by your first and last name.",
"naming-format": "Format of name in the Gradido Community",
"publish-name": {
"updated": "Format of name for the Gradido Community updated."
@ -374,6 +373,22 @@
},
"subtitle": "If you have forgotten your password, you can reset it here."
},
"publish-name": {
"none": "None",
"none-tooltip": "first name and last name are empty",
"first": "first name",
"first-tooltip": "the first name only",
"first-initial": "first name and initial",
"first-initial-tooltip": "first name plus initial of last name",
"last": "last name",
"last-tooltip": "last name only",
"last-initial": "initial and last name",
"last-initial-tooltip": "First letter of the first name plus last name",
"initials": "initials",
"initials-tooltip": "Initials of first name and last name",
"full": "full name",
"full-tooltip": "full name: firstname plus lastname"
},
"showAmountGDD": "Your GDD amount is visible.",
"showAmountGDT": "Your GDT amount is visible.",
"username": {

View File

@ -107,7 +107,7 @@
{{ $t('settings.GMS.naming-format') }}
</b-col>
<b-col cols="12" md="6" lg="6">
<user-naming-format
<user-g-m-s-naming-format
:initialValue="$store.state.gmsPublishName"
:attrName="'gmsPublishName'"
:successMessage="$t('settings.GMS.publish-name.updated')"
@ -134,7 +134,6 @@
</div>
<div v-if="isHumhub">
<div class="h3">{{ $t('Humhub') }}</div>
{{ $t('settings.humhub.export-consequences') }}
<b-row class="mb-3">
<b-col cols="12" md="6" lg="6">
{{ $t('settings.humhub.switch') }}
@ -181,6 +180,7 @@
</template>
<script>
import UserNamingFormat from '@/components/UserSettings/UserNamingFormat'
import UserGMSNamingFormat from '@/components/UserSettings/UserGMSNamingFormat'
import UserGMSLocationFormat from '@/components/UserSettings/UserGMSLocationFormat'
import UserGMSLocation from '@/components/UserSettings/UserGMSLocation'
import UserName from '@/components/UserSettings/UserName.vue'
@ -195,6 +195,7 @@ export default {
name: 'Profile',
components: {
UserNamingFormat,
UserGMSNamingFormat,
UserGMSLocationFormat,
UserGMSLocation,
UserName,
@ -220,9 +221,11 @@ export default {
humhubAllowed,
} = state
const username = this.$store.state.username || ''
return {
darkMode,
username: '',
username,
firstName,
lastName,
email,
@ -246,7 +249,7 @@ export default {
return CONFIG.GMS_ACTIVE
},
isHumhub() {
return CONFIG.HUMHUB_ACTIVE
return CONFIG.HUMHUB_ACTIVE && this.username
},
},
// TODO: watch: {