diff --git a/backend/src/federation/client/1_0/model/SendCoinsArgs.ts b/backend/src/federation/client/1_0/model/SendCoinsArgs.ts index 73e166308..ae9a01f58 100644 --- a/backend/src/federation/client/1_0/model/SendCoinsArgs.ts +++ b/backend/src/federation/client/1_0/model/SendCoinsArgs.ts @@ -27,6 +27,6 @@ export class SendCoinsArgs { @Field(() => String) senderUserName: string - @Field(() => String) - senderAlias: string + @Field(() => String, { nullable: true }) + senderAlias?: string | null } diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index 1dbff7896..8d35708a6 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -38,7 +38,7 @@ import { calculateBalance } from '@/util/validate' import { virtualLinkTransaction, virtualDecayTransaction } from '@/util/virtualTransactions' import { BalanceResolver } from './BalanceResolver' -import { getCommunityName, isCommunityAuthenticated, isHomeCommunity } from './util/communities' +import { getCommunity, getCommunityName, isHomeCommunity } from './util/communities' import { findUserByIdentifier } from './util/findUserByIdentifier' import { getLastTransaction } from './util/getLastTransaction' import { getTransactionList } from './util/getTransactionList' @@ -445,13 +445,17 @@ export class TransactionResolver { if (!CONFIG.FEDERATION_XCOM_SENDCOINS_ENABLED) { throw new LogError('X-Community sendCoins disabled per configuration!') } - if (!(await isCommunityAuthenticated(recipientCommunityIdentifier))) { + const recipCom = await getCommunity(recipientCommunityIdentifier) + logger.debug('recipient commuity: ', recipCom) + if (recipCom === null) { + throw new LogError( + 'no recipient commuity found for identifier:', + recipientCommunityIdentifier, + ) + } + if (recipCom !== null && recipCom.authenticatedAt === null) { throw new LogError('recipient commuity is connected, but still not authenticated yet!') } - const recipCom = await DbCommunity.findOneOrFail({ - where: { communityUuid: recipientCommunityIdentifier }, - }) - logger.debug('recipient commuity: ', recipCom) let pendingResult: SendCoinsResult let committingResult: SendCoinsResult const creationDate = new Date() diff --git a/federation/src/graphql/api/1_0/model/SendCoinsArgs.ts b/federation/src/graphql/api/1_0/model/SendCoinsArgs.ts index 1337bbc6c..e15f40ed3 100644 --- a/federation/src/graphql/api/1_0/model/SendCoinsArgs.ts +++ b/federation/src/graphql/api/1_0/model/SendCoinsArgs.ts @@ -27,6 +27,6 @@ export class SendCoinsArgs { @Field(() => String) senderUserName: string - @Field(() => String) - senderAlias: string + @Field(() => String, { nullable: true }) + senderAlias?: string | null } diff --git a/federation/src/graphql/api/1_0/resolver/SendCoinsResolver.ts b/federation/src/graphql/api/1_0/resolver/SendCoinsResolver.ts index a05ab2c7d..98f8af422 100644 --- a/federation/src/graphql/api/1_0/resolver/SendCoinsResolver.ts +++ b/federation/src/graphql/api/1_0/resolver/SendCoinsResolver.ts @@ -35,11 +35,13 @@ export class SendCoinsResolver { args.senderCommunityUuid, args.senderUserUuid, args.senderUserName, + args.senderAlias, ) const result = new SendCoinsResult() // first check if receiver community is correct const homeCom = await DbCommunity.findOneBy({ communityUuid: args.recipientCommunityUuid, + foreign: false, }) if (!homeCom) { throw new LogError( @@ -50,7 +52,10 @@ export class SendCoinsResolver { let receiverUser try { // second check if receiver user exists in this community - receiverUser = await findUserByIdentifier(args.recipientUserIdentifier) + receiverUser = await findUserByIdentifier( + args.recipientUserIdentifier, + args.recipientCommunityUuid, + ) } catch (err) { logger.error('Error in findUserByIdentifier:', err) throw new LogError( diff --git a/federation/src/graphql/util/findUserByIdentifier.ts b/federation/src/graphql/util/findUserByIdentifier.ts index 96c9eb458..6b7f1bccc 100644 --- a/federation/src/graphql/util/findUserByIdentifier.ts +++ b/federation/src/graphql/util/findUserByIdentifier.ts @@ -6,12 +6,18 @@ import { LogError } from '@/server/LogError' import { VALID_ALIAS_REGEX } from './validateAlias' -export const findUserByIdentifier = async (identifier: string): Promise => { +export const findUserByIdentifier = async ( + identifier: string, + communityIdentifier?: string, +): Promise => { let user: DbUser | null if (validate(identifier) && version(identifier) === 4) { - user = await DbUser.findOne({ where: { gradidoID: identifier }, relations: ['emailContact'] }) + user = await DbUser.findOne({ + where: { gradidoID: identifier, communityUuid: communityIdentifier }, + relations: ['emailContact'], + }) if (!user) { - throw new LogError('No user found to given identifier', identifier) + throw new LogError('No user found to given identifier(s)', identifier, communityIdentifier) } } else if (/^.{2,}@.{2,}\..{2,}$/.exec(identifier)) { const userContact = await DbUserContact.findOne({ @@ -27,12 +33,22 @@ export const findUserByIdentifier = async (identifier: string): Promise if (!userContact.user) { throw new LogError('No user to given contact', identifier) } + if (userContact.user.communityUuid !== communityIdentifier) { + throw new LogError( + 'Found user to given contact, but belongs to other community', + identifier, + communityIdentifier, + ) + } user = userContact.user user.emailContact = userContact } else if (VALID_ALIAS_REGEX.exec(identifier)) { - user = await DbUser.findOne({ where: { alias: identifier }, relations: ['emailContact'] }) + user = await DbUser.findOne({ + where: { alias: identifier, communityUuid: communityIdentifier }, + relations: ['emailContact'], + }) if (!user) { - throw new LogError('No user found to given identifier', identifier) + throw new LogError('No user found to given identifier(s)', identifier, communityIdentifier) } } else { throw new LogError('Unknown identifier type', identifier)