mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 01:46:07 +00:00
correct handling of receiverCommunity updates
This commit is contained in:
parent
25c4c7362f
commit
e9d2eae51a
@ -1,37 +0,0 @@
|
||||
import { MaxLength, MinLength } from 'class-validator'
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
import { Field, ArgsType, InputType } from 'type-graphql'
|
||||
|
||||
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from '@/graphql/resolver/const/const'
|
||||
import { IsPositiveDecimal } from '@/graphql/validator/Decimal'
|
||||
|
||||
@InputType()
|
||||
@ArgsType()
|
||||
export class RedeemJwtArgs {
|
||||
@Field(() => String, { nullable: false })
|
||||
gradidoID!: string
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
firstName?: string
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
alias?: string
|
||||
|
||||
@Field(() => String, { nullable: false })
|
||||
communityUuid!: string
|
||||
|
||||
@Field(() => String, { nullable: false })
|
||||
communityName!: string
|
||||
|
||||
@Field(() => String, { nullable: false })
|
||||
code!: string
|
||||
|
||||
@Field(() => Decimal, { nullable: false })
|
||||
@IsPositiveDecimal()
|
||||
amount!: Decimal
|
||||
|
||||
@Field(() => String, { nullable: false })
|
||||
@MaxLength(MEMO_MAX_CHARS)
|
||||
@MinLength(MEMO_MIN_CHARS)
|
||||
memo!: string
|
||||
}
|
||||
@ -403,8 +403,9 @@ export class TransactionLinkResolver {
|
||||
@Mutation(() => String)
|
||||
async createRedeemJwt(
|
||||
@Arg('gradidoID') gradidoID: string,
|
||||
@Arg('communityUuid') communityUuid: string,
|
||||
@Arg('communityName') communityName: string,
|
||||
@Arg('senderCommunityUuid') senderCommunityUuid: string,
|
||||
@Arg('senderCommunityName') senderCommunityName: string,
|
||||
@Arg('receiverCommunityUuid') receiverCommunityUuid: string,
|
||||
@Arg('code') code: string,
|
||||
@Arg('amount') amount: string,
|
||||
@Arg('memo') memo: string,
|
||||
@ -413,8 +414,9 @@ export class TransactionLinkResolver {
|
||||
): Promise<string> {
|
||||
logger.debug('TransactionLinkResolver.queryRedeemJwt... args=', {
|
||||
gradidoID,
|
||||
communityUuid,
|
||||
communityName,
|
||||
senderCommunityUuid,
|
||||
senderCommunityName,
|
||||
receiverCommunityUuid,
|
||||
code,
|
||||
amount,
|
||||
memo,
|
||||
@ -423,18 +425,20 @@ export class TransactionLinkResolver {
|
||||
})
|
||||
|
||||
const disbursementJwtPayloadType = new DisbursementJwtPayloadType(
|
||||
communityUuid,
|
||||
senderCommunityUuid,
|
||||
gradidoID,
|
||||
alias ?? firstName ?? '',
|
||||
code,
|
||||
amount,
|
||||
memo,
|
||||
)
|
||||
// encode/sign the jwt with the private key of the sender/home community
|
||||
const homeCom = await getHomeCommunity()
|
||||
if (!homeCom.privateKey) {
|
||||
throw new LogError('Home community private key is not set')
|
||||
}
|
||||
const redeemJwt = await encode(disbursementJwtPayloadType, homeCom.privateKey)
|
||||
// TODO: encrypt the payload with the public key of the target community
|
||||
return redeemJwt
|
||||
}
|
||||
|
||||
|
||||
@ -16,11 +16,11 @@
|
||||
<BCol class="fw-bold">
|
||||
<community-switch
|
||||
:disabled="isBalanceDisabled"
|
||||
:model-value="targetCommunity"
|
||||
@update:model-value="setTargetCommunity"
|
||||
:model-value="currentReceiverCommunity"
|
||||
@update:model-value="setReceiverCommunity"
|
||||
/>
|
||||
</BCol>
|
||||
<BCol v-if="isForeignCommunitySelected" sm="12" md="6" class="mt-4 mt-lg-0">
|
||||
<BCol v-if="isForeignCommunitySelected" sm="12" md="6" class="mt-2 mt-lg-0">
|
||||
<p>{{ $t('gdd_per_link.switchCommunity') }}</p>
|
||||
<BButton variant="gradido" @click="onSwitch">
|
||||
{{ $t('gdd_per_link.to-switch') }}
|
||||
@ -47,25 +47,69 @@ const props = defineProps({
|
||||
linkData: { type: Object, required: true },
|
||||
redeemCode: { type: String, required: true },
|
||||
isContributionLink: { type: Boolean, default: false },
|
||||
targetCommunity: {
|
||||
receiverCommunity: {
|
||||
type: Object,
|
||||
required: true,
|
||||
default: () => ({ uuid: '', name: CONFIG.COMMUNITY_NAME }),
|
||||
required: false,
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:targetCommunity'])
|
||||
const senderCommunity = computed(() => extractHomeCommunityFromLinkData(props.linkData))
|
||||
const currentReceiverCommunity = computed(
|
||||
() =>
|
||||
props.receiverCommunity || {
|
||||
uuid: senderCommunity.value.uuid,
|
||||
name: senderCommunity.value.name,
|
||||
url: senderCommunity.value.url,
|
||||
foreign: senderCommunity.value.foreign,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits(['update:receiverCommunity'])
|
||||
|
||||
const isForeignCommunitySelected = computed(() => {
|
||||
if (props.targetCommunity.name !== CONFIG.COMMUNITY_NAME) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
console.log(
|
||||
'RedeemCommunitySelection.isForeignCommunitySelected...receiverCommunity=',
|
||||
currentReceiverCommunity.value,
|
||||
)
|
||||
return currentReceiverCommunity.value.foreign
|
||||
})
|
||||
|
||||
function setTargetCommunity(community) {
|
||||
console.log('RedeemCommunitySelection.setTargetCommunity...community=', community)
|
||||
emit('update:targetCommunity', community)
|
||||
function setReceiverCommunity(community) {
|
||||
console.log('RedeemCommunitySelection.setReceiverCommunity...community=', community)
|
||||
emit('update:receiverCommunity', {
|
||||
uuid: community.uuid,
|
||||
name: community.name,
|
||||
url: community.url,
|
||||
foreign: community.foreign,
|
||||
})
|
||||
}
|
||||
|
||||
function extractHomeCommunityFromLinkData(linkData) {
|
||||
console.log('RedeemCommunitySelection.extractHomeCommunityFromLinkData...linkData=', linkData)
|
||||
if (linkData.communities.length === 0) {
|
||||
return {
|
||||
uuid: '',
|
||||
name: CONFIG.COMMUNITY_NAME,
|
||||
url: CONFIG.COMMUNITY_URL,
|
||||
foreign: false,
|
||||
}
|
||||
}
|
||||
const communities = linkData.communities
|
||||
console.log(
|
||||
'RedeemCommunitySelection.extractHomeCommunityFromLinkData...communities=',
|
||||
communities,
|
||||
)
|
||||
const homeCommunity = communities.find((c) => c.foreign === false)
|
||||
console.log(
|
||||
'RedeemCommunitySelection.extractHomeCommunityFromLinkData...homeCommunity=',
|
||||
homeCommunity,
|
||||
)
|
||||
return {
|
||||
uuid: homeCommunity.uuid,
|
||||
name: homeCommunity.name,
|
||||
url: homeCommunity.url,
|
||||
foreign: homeCommunity.foreign,
|
||||
}
|
||||
}
|
||||
|
||||
const { mutate: createRedeemJwt } = useMutation(createRedeemJwtMutation)
|
||||
@ -76,8 +120,9 @@ async function onSwitch(event) {
|
||||
if (isForeignCommunitySelected.value) {
|
||||
console.log('RedeemCommunitySelection.onSwitch vor createRedeemJwt params:', {
|
||||
gradidoID: props.linkData.user.gradidoID,
|
||||
communityUuid: props.targetCommunity.uuid,
|
||||
communityName: props.targetCommunity.name,
|
||||
senderCommunityUuid: senderCommunity.value.uuid,
|
||||
senderCommunityName: senderCommunity.value.name,
|
||||
receiverCommunityUuid: currentReceiverCommunity.value.uuid,
|
||||
code: props.redeemCode,
|
||||
amount: props.linkData.amount,
|
||||
memo: props.linkData.memo,
|
||||
@ -87,8 +132,9 @@ async function onSwitch(event) {
|
||||
try {
|
||||
const { data } = await createRedeemJwt({
|
||||
gradidoID: props.linkData.user.gradidoID,
|
||||
communityUuid: props.targetCommunity.uuid,
|
||||
communityName: props.targetCommunity.name,
|
||||
senderCommunityUuid: senderCommunity.value.uuid,
|
||||
senderCommunityName: senderCommunity.value.name,
|
||||
receiverCommunityUuid: currentReceiverCommunity.value.uuid,
|
||||
code: props.redeemCode,
|
||||
amount: props.linkData.amount,
|
||||
memo: props.linkData.memo,
|
||||
@ -99,7 +145,7 @@ async function onSwitch(event) {
|
||||
if (!data?.createRedeemJwt) {
|
||||
throw new Error('Failed to get redeem token')
|
||||
}
|
||||
const targetUrl = props.targetCommunity.url.replace(/\/api\/?$/, '')
|
||||
const targetUrl = currentReceiverCommunity.value.url.replace(/\/api\/?$/, '')
|
||||
window.location.href = targetUrl + '/redeem/' + data.createRedeemJwt
|
||||
} catch (error) {
|
||||
console.error('RedeemCommunitySelection.onSwitch error:', error)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="redeem-select-community">
|
||||
<redeem-community-selection
|
||||
v-model:target-community="yourTargetCommunity"
|
||||
v-model:receiver-community="receiverCommunity"
|
||||
:link-data="props.linkData"
|
||||
:redeem-code="props.redeemCode"
|
||||
:is-contribution-link="props.isContributionLink"
|
||||
@ -15,13 +15,13 @@
|
||||
<BRow>
|
||||
<BCol sm="12" md="6">
|
||||
<p>{{ $t('gdd_per_link.no-account') }}</p>
|
||||
<BButton variant="primary" :to="register()">
|
||||
<BButton variant="primary" :disabled="isForeignCommunitySelected" :to="register()">
|
||||
{{ $t('gdd_per_link.to-register') }}
|
||||
</BButton>
|
||||
</BCol>
|
||||
<BCol sm="12" md="6" class="mt-4 mt-lg-0">
|
||||
<p>{{ $t('gdd_per_link.has-account') }}</p>
|
||||
<BButton variant="gradido" :to="login()">
|
||||
<BButton variant="gradido" :disabled="isForeignCommunitySelected" :to="login()">
|
||||
{{ $t('gdd_per_link.to-login') }}
|
||||
</BButton>
|
||||
</BCol>
|
||||
@ -31,7 +31,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { ref, computed } from 'vue'
|
||||
import CONFIG from '@/config'
|
||||
import { useAuthLinks } from '@/composables/useAuthLinks'
|
||||
|
||||
@ -42,8 +42,14 @@ const props = defineProps({
|
||||
isContributionLink: { type: Boolean, default: false },
|
||||
})
|
||||
|
||||
const yourTargetCommunity = ref({
|
||||
const receiverCommunity = ref({
|
||||
uuid: '',
|
||||
name: CONFIG.COMMUNITY_NAME,
|
||||
url: CONFIG.COMMUNITY_URL,
|
||||
foreign: false,
|
||||
})
|
||||
|
||||
const isForeignCommunitySelected = computed(() => {
|
||||
return receiverCommunity.value.foreign === true
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -202,8 +202,9 @@ export const logout = gql`
|
||||
export const createRedeemJwtMutation = gql`
|
||||
mutation (
|
||||
$gradidoID: String!
|
||||
$communityUuid: String!
|
||||
$communityName: String!
|
||||
$senderCommunityUuid: String!
|
||||
$senderCommunityName: String!
|
||||
$receiverCommunityUuid: String!
|
||||
$code: String!
|
||||
$amount: String!
|
||||
$memo: String!
|
||||
@ -212,8 +213,9 @@ export const createRedeemJwtMutation = gql`
|
||||
) {
|
||||
createRedeemJwt(
|
||||
gradidoID: $gradidoID
|
||||
communityUuid: $communityUuid
|
||||
communityName: $communityName
|
||||
senderCommunityUuid: $senderCommunityUuid
|
||||
senderCommunityName: $senderCommunityName
|
||||
receiverCommunityUuid: $receiverCommunityUuid
|
||||
code: $code
|
||||
amount: $amount
|
||||
memo: $memo
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user