Merge pull request #3216 from gradido/frontend_community_switch_tunnel_user

feat(frontend): tunnel community UUId to send
This commit is contained in:
einhornimmond 2023-10-16 15:47:27 +02:00 committed by GitHub
commit 73aebe94a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 21 deletions

View File

@ -1,12 +1,15 @@
import { IsNull, Not } from '@dbTools/typeorm'
import { Community as DbCommunity } from '@entity/Community'
import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity'
import { Resolver, Query, Authorized } from 'type-graphql'
import { Resolver, Query, Authorized, Arg } from 'type-graphql'
import { Community } from '@model/Community'
import { FederatedCommunity } from '@model/FederatedCommunity'
import { RIGHTS } from '@/auth/RIGHTS'
import { LogError } from '@/server/LogError'
import { getCommunity } from './util/communities'
@Resolver()
export class CommunityResolver {
@ -36,4 +39,14 @@ export class CommunityResolver {
})
return dbCommunities.map((dbCom: DbCommunity) => new Community(dbCom))
}
@Authorized([RIGHTS.COMMUNITIES])
@Query(() => Community)
async community(@Arg('communityUuid') communityUuid: string): Promise<Community> {
const community = await getCommunity(communityUuid)
if (!community) {
throw new LogError('community not found', communityUuid)
}
return new Community(community)
}
}

View File

@ -51,3 +51,9 @@ export async function getCommunityName(communityIdentifier: string): Promise<str
return ''
}
}
export async function getCommunity(communityUuid: string): Promise<DbCommunity | null> {
return await DbCommunity.findOne({
where: [{ communityUuid }],
})
}

View File

@ -4,7 +4,7 @@ import flushPromises from 'flush-promises'
import { SEND_TYPES } from '@/pages/Send'
import { createMockClient } from 'mock-apollo-client'
import VueApollo from 'vue-apollo'
import { user as userQuery, selectCommunities as selectCommunitiesQuery } from '@/graphql/queries'
import { userAndCommunity, selectCommunities as selectCommunitiesQuery } from '@/graphql/queries'
const mockClient = createMockClient()
const apolloProvider = new VueApollo({
@ -47,18 +47,23 @@ describe('TransactionForm', () => {
})
}
const userQueryMock = jest.fn()
const userAndCommunityMock = jest.fn()
mockClient.setRequestHandler(
userQuery,
userQueryMock.mockRejectedValueOnce({ message: 'Query user name fails!' }).mockResolvedValue({
data: {
user: {
firstName: 'Bibi',
lastName: 'Bloxberg',
userAndCommunity,
userAndCommunityMock
.mockRejectedValueOnce({ message: 'Query user name fails!' })
.mockResolvedValue({
data: {
user: {
firstName: 'Bibi',
lastName: 'Bloxberg',
},
community: {
name: 'Gradido Entwicklung',
},
},
},
}),
}),
)
mockClient.setRequestHandler(
@ -416,7 +421,7 @@ Die ganze Welt bezwingen.“`)
})
it('queries the username', () => {
expect(userQueryMock).toBeCalledWith({
expect(userAndCommunityMock).toBeCalledWith({
identifier: 'gradido-ID',
})
})

View File

@ -55,10 +55,17 @@
</b-row>
<b-row>
<b-col class="font-weight-bold">
<community-switch
v-model="form.targetCommunity"
:disabled="isBalanceDisabled"
/>
<div v-if="!communityUuid">
<community-switch
v-model="form.targetCommunity"
:disabled="isBalanceDisabled"
/>
</div>
<div v-else class="mb-4">
<b-row>
<b-col class="font-weight-bold">{{ recipientCommunity.name }}</b-col>
</b-row>
</div>
</b-col>
</b-row>
</b-col>
@ -143,7 +150,7 @@ import InputIdentifier from '@/components/Inputs/InputIdentifier'
import InputAmount from '@/components/Inputs/InputAmount'
import InputTextarea from '@/components/Inputs/InputTextarea'
import CommunitySwitch from '@/components/CommunitySwitch.vue'
import { user as userQuery } from '@/graphql/queries'
import { userAndCommunity } from '@/graphql/queries'
import { isEmpty } from 'lodash'
import { COMMUNITY_NAME } from '@/config'
@ -178,6 +185,7 @@ export default {
},
radioSelected: this.selected,
userName: '',
recipientCommunity: { uuid: '', name: '' },
}
},
methods: {
@ -186,6 +194,10 @@ export default {
},
onSubmit() {
if (this.gradidoID) this.form.identifier = this.gradidoID
if (this.communityUuid) {
this.recipientCommunity.uuid = this.communityUuid
this.form.targetCommunity = this.recipientCommunity
}
this.$emit('set-transaction', {
selected: this.radioSelected,
identifier: this.form.identifier,
@ -209,17 +221,21 @@ export default {
apollo: {
UserName: {
query() {
return userQuery
return userAndCommunity
},
fetchPolicy: 'network-only',
variables() {
return { identifier: this.gradidoID }
return {
identifier: this.gradidoID,
communityUuid: this.communityUuid,
}
},
skip() {
return !this.gradidoID
},
update({ user }) {
update({ user, community }) {
this.userName = `${user.firstName} ${user.lastName}`
this.recipientCommunity.name = community.name
},
error({ message }) {
this.toastError(message)
@ -247,6 +263,9 @@ export default {
gradidoID() {
return this.$route.query && this.$route.query.gradidoID
},
communityUuid() {
return this.$route.query && this.$route.query.communityUuid
},
},
mounted() {
if (this.form.identifier !== '') this.$refs.formValidator.validate()

View File

@ -284,3 +284,15 @@ export const user = gql`
}
}
`
export const userAndCommunity = gql`
query($identifier: String!, $communityUuid: String!) {
user(identifier: $identifier) {
firstName
lastName
}
community(communityUuid: $communityUuid) {
name
}
}
`

View File

@ -172,7 +172,7 @@ export default {
throw new Error(`undefined transactionData.selected : ${this.transactionData.selected}`)
}
this.loading = false
this.$router.push({ query: { gradidoID: undefined } })
this.$router.push({ query: { gradidoID: undefined, communityUuid: undefined } })
},
onBack() {
this.currentTransactionStep = TRANSACTION_STEPS.transactionForm