From affd8a6859cbc2082b888d7403976f87def32edb Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 5 Apr 2022 14:50:08 +0200 Subject: [PATCH 01/28] update browser list for unit tests --- backend/yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/yarn.lock b/backend/yarn.lock index 4134e1d37..3ba20211a 100644 --- a/backend/yarn.lock +++ b/backend/yarn.lock @@ -1704,9 +1704,9 @@ camelcase@^6.2.0: integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg== caniuse-lite@^1.0.30001264: - version "1.0.30001265" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001265.tgz#0613c9e6c922e422792e6fcefdf9a3afeee4f8c3" - integrity sha512-YzBnspggWV5hep1m9Z6sZVLOt7vrju8xWooFAgN6BA5qvy98qPAPb7vNUzypFaoh2pb3vlfzbDO8tB57UPGbtw== + version "1.0.30001325" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001325.tgz" + integrity sha512-sB1bZHjseSjDtijV1Hb7PB2Zd58Kyx+n/9EotvZ4Qcz2K3d0lWB8dB4nb8wN/TsOGFq3UuAm0zQZNQ4SoR7TrQ== chalk@^2.0.0: version "2.4.2" From f3948b39beb4377fe8adfbb66049cbe620a3fc23 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 5 Apr 2022 14:50:45 +0200 Subject: [PATCH 02/28] pass context object to hasElopage query --- backend/src/graphql/resolver/UserResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index cacee6fc8..44dce67cd 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -250,7 +250,7 @@ export class UserResolver { user.language = dbUser.language // Elopage Status & Stored PublisherId - user.hasElopage = await this.hasElopage({ pubKey: dbUser.pubKey.toString('hex') }) + user.hasElopage = await this.hasElopage(context) if (!user.hasElopage && publisherId) { user.publisherId = publisherId // TODO: Check if we can use updateUserInfos From bccc5d1ddbeaf76f3bc4a761ebba2dae66f9ede0 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 6 Apr 2022 15:22:32 +0200 Subject: [PATCH 03/28] backend remove startblock from balance object --- backend/src/graphql/model/Balance.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/backend/src/graphql/model/Balance.ts b/backend/src/graphql/model/Balance.ts index 6a93a5b63..619d9b242 100644 --- a/backend/src/graphql/model/Balance.ts +++ b/backend/src/graphql/model/Balance.ts @@ -1,6 +1,5 @@ import { ObjectType, Field } from 'type-graphql' import Decimal from 'decimal.js-light' -import CONFIG from '@/config' @ObjectType() export class Balance { @@ -11,7 +10,6 @@ export class Balance { balanceGDT: number | null count: number linkCount: number - decayStartBlock?: Date lastBookedDate?: Date | null }) { this.balance = data.balance @@ -20,7 +18,6 @@ export class Balance { this.balanceGDT = data.balanceGDT || null this.count = data.count this.linkCount = data.linkCount - this.decayStartBlock = data.decayStartBlock || CONFIG.DECAY_START_TIME this.lastBookedDate = data.lastBookedDate || null } @@ -46,9 +43,6 @@ export class Balance { @Field(() => Number) linkCount: number - @Field(() => Date) - decayStartBlock: Date - // may be null as there may be no transaction @Field(() => Date, { nullable: true }) lastBookedDate: Date | null From ebb6c926d817c2fcb0bbe7057b978c9660bb6486 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 6 Apr 2022 15:22:57 +0200 Subject: [PATCH 04/28] define decay start block in config statically --- frontend/src/config/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/config/index.js b/frontend/src/config/index.js index 3f62012ad..d29c4dc09 100644 --- a/frontend/src/config/index.js +++ b/frontend/src/config/index.js @@ -5,6 +5,7 @@ const pkg = require('../../package') const constants = { + DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0 CONFIG_VERSION: { DEFAULT: 'DEFAULT', EXPECTED: 'v1.2022-03-18', From 35828050984e7afdaf40680a66ae256a243f1930 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 6 Apr 2022 15:23:47 +0200 Subject: [PATCH 05/28] reference config decay start time when figuring out if its the decay start block --- .../src/components/DecayInformations/DecayInformation.vue | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/DecayInformations/DecayInformation.vue b/frontend/src/components/DecayInformations/DecayInformation.vue index ae76a5bb4..690f6532b 100644 --- a/frontend/src/components/DecayInformations/DecayInformation.vue +++ b/frontend/src/components/DecayInformations/DecayInformation.vue @@ -14,6 +14,7 @@ import DecayInformationLong from '../DecayInformations/DecayInformation-Long' import DecayInformationBeforeStartblock from '../DecayInformations/DecayInformation-BeforeStartblock' import DecayInformationDecayStartblock from '../DecayInformations/DecayInformation-DecayStartblock' +import CONFIG from '@/config' export default { components: { @@ -34,14 +35,10 @@ export default { type: String, required: true, }, - decayStartBlock: { - type: Date, - required: true, - }, }, computed: { isStartBlock() { - return new Date(this.decay.start).getTime() === this.decayStartBlock.getTime() + return new Date(this.decay.start).getTime() === CONFIG.DECAY_START_TIME.getTime() }, }, } From d5d90c70509791b0c8c57372baee95a1824ba332 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 6 Apr 2022 15:24:17 +0200 Subject: [PATCH 06/28] remove decayStartBlock from all component interfaces --- .../DecayInformation-DecayStartblock.vue | 1 - frontend/src/components/GddTransactionList.vue | 4 ---- .../components/Transactions/TransactionCreation.vue | 11 +---------- .../components/Transactions/TransactionReceive.vue | 11 +---------- .../src/components/Transactions/TransactionSend.vue | 11 +---------- frontend/src/graphql/queries.js | 1 - frontend/src/layouts/DashboardLayout_gdd.vue | 3 --- frontend/src/pages/Overview.vue | 2 -- frontend/src/pages/Transactions.vue | 2 -- 9 files changed, 3 insertions(+), 43 deletions(-) diff --git a/frontend/src/components/DecayInformations/DecayInformation-DecayStartblock.vue b/frontend/src/components/DecayInformations/DecayInformation-DecayStartblock.vue index 5802bfb4b..3d42f11f8 100644 --- a/frontend/src/components/DecayInformations/DecayInformation-DecayStartblock.vue +++ b/frontend/src/components/DecayInformations/DecayInformation-DecayStartblock.vue @@ -50,7 +50,6 @@ export default { name: 'DecayInformation-StartBlock', props: { balanceDate: { type: String }, - decayStartBlock: { type: Date }, amount: { type: String, }, diff --git a/frontend/src/components/GddTransactionList.vue b/frontend/src/components/GddTransactionList.vue index 4498034e9..34f7c24ab 100644 --- a/frontend/src/components/GddTransactionList.vue +++ b/frontend/src/components/GddTransactionList.vue @@ -26,7 +26,6 @@ @@ -36,7 +35,6 @@ @@ -46,7 +44,6 @@ @@ -105,7 +102,6 @@ export default { } }, props: { - decayStartBlock: { type: Date }, transactions: { default: () => [] }, pageSize: { type: Number, default: 25 }, timestamp: { type: Number, default: 0 }, diff --git a/frontend/src/components/Transactions/TransactionCreation.vue b/frontend/src/components/Transactions/TransactionCreation.vue index dce11307b..694d907ed 100644 --- a/frontend/src/components/Transactions/TransactionCreation.vue +++ b/frontend/src/components/Transactions/TransactionCreation.vue @@ -27,12 +27,7 @@ - + @@ -82,10 +77,6 @@ export default { type: String, required: true, }, - decayStartBlock: { - type: Date, - required: true, - }, previousBookedBalance: { type: String, required: true, diff --git a/frontend/src/components/Transactions/TransactionReceive.vue b/frontend/src/components/Transactions/TransactionReceive.vue index 32e40f71e..8899b3807 100644 --- a/frontend/src/components/Transactions/TransactionReceive.vue +++ b/frontend/src/components/Transactions/TransactionReceive.vue @@ -33,12 +33,7 @@ - + @@ -87,10 +82,6 @@ export default { typeId: { type: String, }, - decayStartBlock: { - type: Date, - required: true, - }, transactionLinkId: { type: Number, required: false, diff --git a/frontend/src/components/Transactions/TransactionSend.vue b/frontend/src/components/Transactions/TransactionSend.vue index a1ea3c88e..f9125b89c 100644 --- a/frontend/src/components/Transactions/TransactionSend.vue +++ b/frontend/src/components/Transactions/TransactionSend.vue @@ -33,12 +33,7 @@ - + @@ -88,10 +83,6 @@ export default { type: String, required: true, }, - decayStartBlock: { - type: Date, - required: true, - }, transactionLinkId: { type: Number, required: false, diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index b8622ef2d..dce22fbd9 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -52,7 +52,6 @@ export const transactionsQuery = gql` balanceGDT count linkCount - decayStartBlock lastBookedDate } transactions { diff --git a/frontend/src/layouts/DashboardLayout_gdd.vue b/frontend/src/layouts/DashboardLayout_gdd.vue index de2c68bf0..8b84ac10d 100755 --- a/frontend/src/layouts/DashboardLayout_gdd.vue +++ b/frontend/src/layouts/DashboardLayout_gdd.vue @@ -26,7 +26,6 @@ :transactionCount="transactionCount" :transactionLinkCount="transactionLinkCount" :pending="pending" - :decayStartBlock="decayStartBlock" @update-transactions="updateTransactions" @set-tunneled-email="setTunneledEmail" > @@ -63,7 +62,6 @@ export default { transactionLinkCount: 0, pending: true, visible: false, - decayStartBlock: new Date(), tunneledEmail: null, } }, @@ -110,7 +108,6 @@ export default { this.balance = Number(transactionList.balance.balance) this.transactionCount = transactionList.balance.count this.transactionLinkCount = transactionList.balance.linkCount - this.decayStartBlock = new Date(transactionList.balance.decayStartBlock) this.pending = false }) .catch((error) => { diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index 9723f6ade..194de793a 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -18,7 +18,6 @@ :transactions="transactions" :pageSize="5" :timestamp="timestamp" - :decayStartBlock="decayStartBlock" :transaction-count="transactionCount" :transactionLinkCount="transactionLinkCount" :pending="pending" @@ -49,7 +48,6 @@ export default { props: { balance: { type: Number, default: 0 }, GdtBalance: { type: Number, default: 0 }, - decayStartBlock: { type: Date }, transactions: { default: () => [], }, diff --git a/frontend/src/pages/Transactions.vue b/frontend/src/pages/Transactions.vue index 9b2ad6fdf..8efc2026f 100644 --- a/frontend/src/pages/Transactions.vue +++ b/frontend/src/pages/Transactions.vue @@ -10,7 +10,6 @@ :transactionLinkCount="transactionLinkCount" :transactions="transactions" :show-pagination="true" - :decayStartBlock="decayStartBlock" @update-transactions="updateTransactions" v-on="$listeners" /> @@ -45,7 +44,6 @@ export default { }, transactionCount: { type: Number, default: 0 }, transactionLinkCount: { type: Number, default: 0 }, - decayStartBlock: { type: Date }, }, data() { return { From ab7b2a7028ccf75c39abe7b8029b0fd8799be080 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 7 Apr 2022 13:06:47 +0200 Subject: [PATCH 07/28] test for correct startblock date in frontend --- frontend/src/config/index.spec.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 frontend/src/config/index.spec.js diff --git a/frontend/src/config/index.spec.js b/frontend/src/config/index.spec.js new file mode 100644 index 000000000..3c4c7865e --- /dev/null +++ b/frontend/src/config/index.spec.js @@ -0,0 +1,9 @@ +import CONFIG from './index' + +describe('config/index', () => { + describe('decay start block', () => { + it('has the correct date set', () => { + expect(CONFIG.DECAY_START_TIME).toEqual(new Date('2021-05-13 17:46:31')) + }) + }) +}) From 94382d98348aca6561393ae7b98843e4fb6a40c9 Mon Sep 17 00:00:00 2001 From: ogerly Date: Sun, 10 Apr 2022 12:51:05 +0200 Subject: [PATCH 08/28] better date format for reddem valid date --- frontend/src/components/TransactionRows/DateRow.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/src/components/TransactionRows/DateRow.vue b/frontend/src/components/TransactionRows/DateRow.vue index 7f93656f7..365686418 100644 --- a/frontend/src/components/TransactionRows/DateRow.vue +++ b/frontend/src/components/TransactionRows/DateRow.vue @@ -30,9 +30,7 @@ export default { }, computed: { dateString() { - return this.diffNow - ? this.$moment(this.date).locale(this.$i18n.locale).fromNow() - : this.$d(new Date(this.date), 'long') + return this.$d(new Date(this.date), 'long') }, }, } From 50be004ce4608cdff774f1522f0803051ea9a227 Mon Sep 17 00:00:00 2001 From: ogerly Date: Sun, 10 Apr 2022 14:47:43 +0200 Subject: [PATCH 09/28] add jest.fn((d) --- .../components/DecayInformations/CollapseLinksList.spec.js | 1 + .../components/TransactionLinks/TransactionLink.spec.js | 1 + frontend/src/components/TransactionRows/DateRow.vue | 7 +------ .../components/Transactions/TransactionLinkSummary.spec.js | 1 + 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/DecayInformations/CollapseLinksList.spec.js b/frontend/src/components/DecayInformations/CollapseLinksList.spec.js index b533c6aa1..4fc527e39 100644 --- a/frontend/src/components/DecayInformations/CollapseLinksList.spec.js +++ b/frontend/src/components/DecayInformations/CollapseLinksList.spec.js @@ -9,6 +9,7 @@ const mocks = { }, $tc: jest.fn((tc) => tc), $t: jest.fn((t) => t), + $d: jest.fn((d) => d), } const propsData = { diff --git a/frontend/src/components/TransactionLinks/TransactionLink.spec.js b/frontend/src/components/TransactionLinks/TransactionLink.spec.js index f019a0ee1..4a2bb7b3c 100644 --- a/frontend/src/components/TransactionLinks/TransactionLink.spec.js +++ b/frontend/src/components/TransactionLinks/TransactionLink.spec.js @@ -13,6 +13,7 @@ const mocks = { locale: 'en', }, $t: jest.fn((t) => t), + $d: jest.fn((d) => d), $tc: jest.fn((tc) => tc), $apollo: { mutate: mockAPIcall, diff --git a/frontend/src/components/TransactionRows/DateRow.vue b/frontend/src/components/TransactionRows/DateRow.vue index 365686418..5f526caaf 100644 --- a/frontend/src/components/TransactionRows/DateRow.vue +++ b/frontend/src/components/TransactionRows/DateRow.vue @@ -8,7 +8,7 @@
- {{ dateString }} + {{ $d(new Date(this.date), 'long') }}
@@ -28,10 +28,5 @@ export default { default: false, }, }, - computed: { - dateString() { - return this.$d(new Date(this.date), 'long') - }, - }, } diff --git a/frontend/src/components/Transactions/TransactionLinkSummary.spec.js b/frontend/src/components/Transactions/TransactionLinkSummary.spec.js index 1f2a4388c..078ce6f97 100644 --- a/frontend/src/components/Transactions/TransactionLinkSummary.spec.js +++ b/frontend/src/components/Transactions/TransactionLinkSummary.spec.js @@ -12,6 +12,7 @@ const mocks = { locale: 'en', }, $t: jest.fn((t) => t), + $d: jest.fn((d) => d), $tc: jest.fn((tc) => tc), $apollo: { query: apolloQueryMock, From 6a6edfde627a0100115e32baf43d6d30e6f02e4d Mon Sep 17 00:00:00 2001 From: ogerly Date: Sun, 10 Apr 2022 20:03:53 +0200 Subject: [PATCH 10/28] change text links_sum in locales --- frontend/src/locales/de.json | 2 +- frontend/src/locales/en.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 600b36e65..557570019 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -109,7 +109,7 @@ "link-expired": "Der Link ist nicht mehr gültig. Die Gültigkeit ist am {date} abgelaufen.", "link-overview": "Linkübersicht", "links_count": "Aktive Links", - "links_sum": "Summe deiner versendeten Gradidos", + "links_sum": "Offene Links und QR-Codes", "no-account": "Du besitzt noch kein Gradido Konto", "no-redeem": "Du darfst deinen eigenen Link nicht einlösen!", "not-copied": "Konnte den Link nicht kopieren: {err}", diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index ef9a14c0a..06342cab9 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -109,7 +109,7 @@ "link-expired": "The link is no longer valid. The validity expired on {date}.", "link-overview": "Link overview", "links_count": "Active links", - "links_sum": "Total of your sent Gradidos", + "links_sum": "Open links and QR codes", "no-account": "You don't have a Gradido account yet", "no-redeem": "You not allowed to redeem your own link!", "not-copied": "Could not copy link: {err}", From f57f67846e7284019c35e3d137662967cd0f420e Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 14:58:00 +0200 Subject: [PATCH 11/28] reconstruct context object --- backend/src/graphql/resolver/UserResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 44dce67cd..f12910b7c 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -250,7 +250,7 @@ export class UserResolver { user.language = dbUser.language // Elopage Status & Stored PublisherId - user.hasElopage = await this.hasElopage(context) + user.hasElopage = await this.hasElopage({ ...context, user: dbUser }) if (!user.hasElopage && publisherId) { user.publisherId = publisherId // TODO: Check if we can use updateUserInfos From 7ec35bbfb238440caea2874b6aaf0b42de31b152 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 15:50:02 +0200 Subject: [PATCH 12/28] define context interface --- backend/src/server/context.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/src/server/context.ts b/backend/src/server/context.ts index 6de2adce4..805be90c6 100644 --- a/backend/src/server/context.ts +++ b/backend/src/server/context.ts @@ -1,9 +1,18 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { Role } from '@/auth/Role' +import { User as dbUser } from '@entity/User' -const context = (args: any) => { +export interface Context { + token: string | null + setHeaders: { key: string, value: string }[] + role?: Role + user?: dbUser +} + +const context = (args: any): Context => { const authorization = args.req.headers.authorization - let token = null + let token: string | null = null if (authorization) { token = authorization.replace(/^Bearer /, '') } From 57298a4d3a77a5b9c4c7f1893cdfe8a96fd30de2 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 15:50:46 +0200 Subject: [PATCH 13/28] use Context interface in user resolver --- backend/src/graphql/directive/isAuthorized.ts | 1 + backend/src/graphql/resolver/UserResolver.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/directive/isAuthorized.ts b/backend/src/graphql/directive/isAuthorized.ts index 84756c45a..5c6d6f6f0 100644 --- a/backend/src/graphql/directive/isAuthorized.ts +++ b/backend/src/graphql/directive/isAuthorized.ts @@ -9,6 +9,7 @@ import { getCustomRepository } from '@dbTools/typeorm' import { UserRepository } from '@repository/User' import { INALIENABLE_RIGHTS } from '@/auth/INALIENABLE_RIGHTS' import { ServerUser } from '@entity/ServerUser' +import { Context } from '@/server/context' const isAuthorized: AuthChecker = async ({ context }, rights) => { context.role = ROLE_UNAUTHORIZED // unauthorized user diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index cacee6fc8..84698fbca 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -2,6 +2,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import fs from 'fs' +import { Context } from '@/server/context' import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql' import { getConnection, getCustomRepository } from '@dbTools/typeorm' import CONFIG from '@/config' @@ -192,9 +193,10 @@ export class UserResolver { @Authorized([RIGHTS.VERIFY_LOGIN]) @Query(() => User) @UseMiddleware(klicktippNewsletterStateMiddleware) - async verifyLogin(@Ctx() context: any): Promise { + async verifyLogin(@Ctx() context: Context): Promise { // TODO refactor and do not have duplicate code with login(see below) const userEntity = context.user + if (!userEntity) throw new Error('No user given!') const user = new User(userEntity) // user.pubkey = userEntity.pubKey.toString('hex') // Elopage Status & Stored PublisherId @@ -218,7 +220,7 @@ export class UserResolver { @UseMiddleware(klicktippNewsletterStateMiddleware) async login( @Args() { email, password, publisherId }: UnsecureLoginArgs, - @Ctx() context: any, + @Ctx() context: Context, ): Promise { email = email.trim().toLowerCase() const dbUser = await DbUser.findOneOrFail({ email }, { withDeleted: true }).catch(() => { @@ -540,9 +542,10 @@ export class UserResolver { passwordNew, coinanimation, }: UpdateUserInfosArgs, - @Ctx() context: any, + @Ctx() context: Context, ): Promise { const userEntity = context.user + if (!userEntity) throw new Error('No user given!') if (firstName) { userEntity.firstName = firstName @@ -619,7 +622,7 @@ export class UserResolver { @Authorized([RIGHTS.HAS_ELOPAGE]) @Query(() => Boolean) - async hasElopage(@Ctx() context: any): Promise { + async hasElopage(@Ctx() context: Context): Promise { const userEntity = context.user if (!userEntity) { return false From e183a9bde030e1f328ffd1f0dc2d95eb76c30d09 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 15:53:00 +0200 Subject: [PATCH 14/28] remove unused modules --- backend/src/graphql/directive/isAuthorized.ts | 1 - backend/src/server/context.ts | 2 +- backend/src/server/plugins.ts | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/directive/isAuthorized.ts b/backend/src/graphql/directive/isAuthorized.ts index 5c6d6f6f0..84756c45a 100644 --- a/backend/src/graphql/directive/isAuthorized.ts +++ b/backend/src/graphql/directive/isAuthorized.ts @@ -9,7 +9,6 @@ import { getCustomRepository } from '@dbTools/typeorm' import { UserRepository } from '@repository/User' import { INALIENABLE_RIGHTS } from '@/auth/INALIENABLE_RIGHTS' import { ServerUser } from '@entity/ServerUser' -import { Context } from '@/server/context' const isAuthorized: AuthChecker = async ({ context }, rights) => { context.role = ROLE_UNAUTHORIZED // unauthorized user diff --git a/backend/src/server/context.ts b/backend/src/server/context.ts index 805be90c6..0958449a4 100644 --- a/backend/src/server/context.ts +++ b/backend/src/server/context.ts @@ -5,7 +5,7 @@ import { User as dbUser } from '@entity/User' export interface Context { token: string | null - setHeaders: { key: string, value: string }[] + setHeaders: { key: string; value: string }[] role?: Role user?: dbUser } diff --git a/backend/src/server/plugins.ts b/backend/src/server/plugins.ts index a407135ea..5902a415f 100644 --- a/backend/src/server/plugins.ts +++ b/backend/src/server/plugins.ts @@ -39,7 +39,6 @@ const apolloLogPlugin = ApolloLogPlugin({ }, }) -const plugins = - process.env.NODE_ENV === 'development' ? [setHeadersPlugin] : [setHeadersPlugin, apolloLogPlugin] +const plugins = process.env.NODE_ENV === 'development' ? [setHeadersPlugin] : [setHeadersPlugin] // , apolloLogPlugin export default plugins From 4d09123b0ee78ff7b3b0e9b0fe07724afd6f90d3 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 15:55:05 +0200 Subject: [PATCH 15/28] remove global no explicit any lint rule --- backend/src/graphql/resolver/UserResolver.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index ee7371739..05e7f09b8 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -1,6 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - import fs from 'fs' import { Context } from '@/server/context' import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql' From 9a390c11dbebbae759669d0de041386b298e030c Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 15:57:59 +0200 Subject: [PATCH 16/28] use Context interface in admin resolver --- backend/src/graphql/resolver/AdminResolver.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 1ed0422ef..481fb9bda 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -1,6 +1,4 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - +import { Context } from '@/server/context' import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx, Int } from 'type-graphql' import { getCustomRepository, @@ -137,7 +135,7 @@ export class AdminResolver { @Mutation(() => Date, { nullable: true }) async deleteUser( @Arg('userId', () => Int) userId: number, - @Ctx() context: any, + @Ctx() context: Context, ): Promise { const user = await dbUser.findOne({ id: userId }) // user exists ? @@ -146,7 +144,7 @@ export class AdminResolver { } // moderator user disabled own account? const moderatorUser = context.user - if (moderatorUser.id === userId) { + if (moderatorUser && moderatorUser.id === userId) { throw new Error('Moderator can not delete his own account!') } // soft-delete user @@ -309,11 +307,11 @@ export class AdminResolver { @Mutation(() => Boolean) async confirmPendingCreation( @Arg('id', () => Int) id: number, - @Ctx() context: any, + @Ctx() context: Context, ): Promise { const pendingCreation = await AdminPendingCreation.findOneOrFail(id) const moderatorUser = context.user - if (moderatorUser.id === pendingCreation.userId) + if (moderatorUser && moderatorUser.id === pendingCreation.userId) throw new Error('Moderator can not confirm own pending creation') const user = await dbUser.findOneOrFail({ id: pendingCreation.userId }, { withDeleted: true }) From e430ceefa3b2bc51ec365c7f4605568394b7128d Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 15:59:23 +0200 Subject: [PATCH 17/28] remove unused lint rule --- backend/src/graphql/resolver/CommunityResolver.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/backend/src/graphql/resolver/CommunityResolver.ts b/backend/src/graphql/resolver/CommunityResolver.ts index 1693574cb..c194cdf1a 100644 --- a/backend/src/graphql/resolver/CommunityResolver.ts +++ b/backend/src/graphql/resolver/CommunityResolver.ts @@ -1,6 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - import { Resolver, Query, Authorized } from 'type-graphql' import { RIGHTS } from '@/auth/RIGHTS' import CONFIG from '@/config' From 8900592b908c452511fa84db1623799b325f5650 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 16:03:12 +0200 Subject: [PATCH 18/28] use Context interface in GDT resolver --- backend/src/graphql/resolver/GdtResolver.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/graphql/resolver/GdtResolver.ts b/backend/src/graphql/resolver/GdtResolver.ts index e2409160b..db3f2d286 100644 --- a/backend/src/graphql/resolver/GdtResolver.ts +++ b/backend/src/graphql/resolver/GdtResolver.ts @@ -1,6 +1,4 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - +import { Context } from '@/server/context' import { Resolver, Query, Args, Ctx, Authorized, Arg } from 'type-graphql' import CONFIG from '@/config' import { GdtEntryList } from '@model/GdtEntryList' @@ -16,9 +14,10 @@ export class GdtResolver { async listGDTEntries( @Args() { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, - @Ctx() context: any, + @Ctx() context: Context, ): Promise { const userEntity = context.user + if (!userEntity) throw new Error('No user given!') try { const resultGDT = await apiGet( @@ -28,15 +27,16 @@ export class GdtResolver { throw new Error(resultGDT.data) } return new GdtEntryList(resultGDT.data) - } catch (err: any) { + } catch (err) { throw new Error('GDT Server is not reachable.') } } @Authorized([RIGHTS.GDT_BALANCE]) @Query(() => Number) - async gdtBalance(@Ctx() context: any): Promise { + async gdtBalance(@Ctx() context: Context): Promise { const { user } = context + if (!user) throw new Error('No user given!') try { const resultGDTSum = await apiPost(`${CONFIG.GDT_API_URL}/GdtEntries/sumPerEmailApi`, { email: user.email, @@ -45,9 +45,9 @@ export class GdtResolver { throw new Error('Call not successful') } return Number(resultGDTSum.data.sum) || 0 - } catch (err: any) { + } catch (err) { // eslint-disable-next-line no-console - console.log('Could not query GDT Server', err) + console.log('Could not query GDT Server') return null } } From 71cb56db0e2b830ba19a0886bd1f19904d11e402 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 16:04:04 +0200 Subject: [PATCH 19/28] no unused lint instruction --- backend/src/graphql/resolver/KlicktippResolver.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/backend/src/graphql/resolver/KlicktippResolver.ts b/backend/src/graphql/resolver/KlicktippResolver.ts index d13f1dd8e..ce9a097e2 100644 --- a/backend/src/graphql/resolver/KlicktippResolver.ts +++ b/backend/src/graphql/resolver/KlicktippResolver.ts @@ -1,6 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - import { Resolver, Query, Authorized, Arg, Mutation, Args } from 'type-graphql' import { getKlickTippUser, From b0606424d42b94ad9a14ccc4a4310abb6521175e Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 16:08:39 +0200 Subject: [PATCH 20/28] Context interface in transaction link resolver --- .../graphql/resolver/TransactionLinkResolver.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index 646a7c296..253e13ec6 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -1,6 +1,4 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - +import { Context } from '@/server/context' import { Resolver, Args, Arg, Authorized, Ctx, Mutation, Query, Int } from 'type-graphql' import { TransactionLink } from '@model/TransactionLink' import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink' @@ -38,9 +36,10 @@ export class TransactionLinkResolver { @Mutation(() => TransactionLink) async createTransactionLink( @Args() { amount, memo }: TransactionLinkArgs, - @Ctx() context: any, + @Ctx() context: Context, ): Promise { const { user } = context + if (!user) throw new Error('No user given!') const createdDate = new Date() const validUntil = transactionLinkExpireDate(createdDate) @@ -72,9 +71,10 @@ export class TransactionLinkResolver { @Mutation(() => Boolean) async deleteTransactionLink( @Arg('id', () => Int) id: number, - @Ctx() context: any, + @Ctx() context: Context, ): Promise { const { user } = context + if (!user) throw new Error('No user given!') const transactionLink = await dbTransactionLink.findOne({ id }) if (!transactionLink) { @@ -113,9 +113,10 @@ export class TransactionLinkResolver { async listTransactionLinks( @Args() { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, - @Ctx() context: any, + @Ctx() context: Context, ): Promise { const { user } = context + if (!user) throw new Error('No user given!') // const now = new Date() const transactionLinks = await dbTransactionLink.find({ where: { @@ -136,9 +137,10 @@ export class TransactionLinkResolver { @Mutation(() => Boolean) async redeemTransactionLink( @Arg('code', () => String) code: string, - @Ctx() context: any, + @Ctx() context: Context, ): Promise { const { user } = context + if (!user) throw new Error('No user given!') const transactionLink = await dbTransactionLink.findOneOrFail({ code }) const linkedUser = await dbUser.findOneOrFail({ id: transactionLink.userId }) From 6cc8410720eab480caae358469e188b4bd5702a6 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 16:15:57 +0200 Subject: [PATCH 21/28] helper function to get user from context --- backend/src/graphql/resolver/GdtResolver.ts | 8 +++----- .../graphql/resolver/TransactionLinkResolver.ts | 14 +++++--------- backend/src/graphql/resolver/UserResolver.ts | 8 +++----- backend/src/server/context.ts | 5 +++++ 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/backend/src/graphql/resolver/GdtResolver.ts b/backend/src/graphql/resolver/GdtResolver.ts index db3f2d286..56a95c9f0 100644 --- a/backend/src/graphql/resolver/GdtResolver.ts +++ b/backend/src/graphql/resolver/GdtResolver.ts @@ -1,4 +1,4 @@ -import { Context } from '@/server/context' +import { Context, getUser } from '@/server/context' import { Resolver, Query, Args, Ctx, Authorized, Arg } from 'type-graphql' import CONFIG from '@/config' import { GdtEntryList } from '@model/GdtEntryList' @@ -16,8 +16,7 @@ export class GdtResolver { { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, @Ctx() context: Context, ): Promise { - const userEntity = context.user - if (!userEntity) throw new Error('No user given!') + const userEntity = getUser(context) try { const resultGDT = await apiGet( @@ -35,8 +34,7 @@ export class GdtResolver { @Authorized([RIGHTS.GDT_BALANCE]) @Query(() => Number) async gdtBalance(@Ctx() context: Context): Promise { - const { user } = context - if (!user) throw new Error('No user given!') + const user = getUser(context) try { const resultGDTSum = await apiPost(`${CONFIG.GDT_API_URL}/GdtEntries/sumPerEmailApi`, { email: user.email, diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index 253e13ec6..733f1db28 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -1,4 +1,4 @@ -import { Context } from '@/server/context' +import { Context, getUser } from '@/server/context' import { Resolver, Args, Arg, Authorized, Ctx, Mutation, Query, Int } from 'type-graphql' import { TransactionLink } from '@model/TransactionLink' import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink' @@ -38,8 +38,7 @@ export class TransactionLinkResolver { @Args() { amount, memo }: TransactionLinkArgs, @Ctx() context: Context, ): Promise { - const { user } = context - if (!user) throw new Error('No user given!') + const user = getUser(context) const createdDate = new Date() const validUntil = transactionLinkExpireDate(createdDate) @@ -73,8 +72,7 @@ export class TransactionLinkResolver { @Arg('id', () => Int) id: number, @Ctx() context: Context, ): Promise { - const { user } = context - if (!user) throw new Error('No user given!') + const user = getUser(context) const transactionLink = await dbTransactionLink.findOne({ id }) if (!transactionLink) { @@ -115,8 +113,7 @@ export class TransactionLinkResolver { { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, @Ctx() context: Context, ): Promise { - const { user } = context - if (!user) throw new Error('No user given!') + const user = getUser(context) // const now = new Date() const transactionLinks = await dbTransactionLink.find({ where: { @@ -139,8 +136,7 @@ export class TransactionLinkResolver { @Arg('code', () => String) code: string, @Ctx() context: Context, ): Promise { - const { user } = context - if (!user) throw new Error('No user given!') + const user = getUser(context) const transactionLink = await dbTransactionLink.findOneOrFail({ code }) const linkedUser = await dbUser.findOneOrFail({ id: transactionLink.userId }) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 05e7f09b8..137c09622 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import { Context } from '@/server/context' +import { Context, getUser } from '@/server/context' import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql' import { getConnection, getCustomRepository } from '@dbTools/typeorm' import CONFIG from '@/config' @@ -192,8 +192,7 @@ export class UserResolver { @UseMiddleware(klicktippNewsletterStateMiddleware) async verifyLogin(@Ctx() context: Context): Promise { // TODO refactor and do not have duplicate code with login(see below) - const userEntity = context.user - if (!userEntity) throw new Error('No user given!') + const userEntity = getUser(context) const user = new User(userEntity) // user.pubkey = userEntity.pubKey.toString('hex') // Elopage Status & Stored PublisherId @@ -541,8 +540,7 @@ export class UserResolver { }: UpdateUserInfosArgs, @Ctx() context: Context, ): Promise { - const userEntity = context.user - if (!userEntity) throw new Error('No user given!') + const userEntity = getUser(context) if (firstName) { userEntity.firstName = firstName diff --git a/backend/src/server/context.ts b/backend/src/server/context.ts index 0958449a4..ffe90aca2 100644 --- a/backend/src/server/context.ts +++ b/backend/src/server/context.ts @@ -23,4 +23,9 @@ const context = (args: any): Context => { return context } +export const getUser = (context: Context): dbUser => { + if (context.user) return context.user + throw new Error('No user given in context!') +} + export default context From 00bba07b11c4de3cdd4ab7429373271f8a101d9e Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 16:22:09 +0200 Subject: [PATCH 22/28] define hack to pass already queried data to balance resolver --- backend/src/server/context.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/src/server/context.ts b/backend/src/server/context.ts index ffe90aca2..f764c2876 100644 --- a/backend/src/server/context.ts +++ b/backend/src/server/context.ts @@ -2,12 +2,19 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { Role } from '@/auth/Role' import { User as dbUser } from '@entity/User' +import { Transaction as dbTransaction } from '@entity/Transaction' +import Decimal from 'decimal.js-light' export interface Context { token: string | null setHeaders: { key: string; value: string }[] role?: Role user?: dbUser + // hack to use less DB calls for Balance Resolver + lastTransaction?: dbTransaction + transactionCount?: number + linkCount?: number + sumHoldAvailableAmount?: Decimal } const context = (args: any): Context => { From d7bec83d25adf1d9bac1db8dcaa09522cb83f480 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 16:22:32 +0200 Subject: [PATCH 23/28] use Context interface in Transaction resolver --- backend/src/graphql/resolver/TransactionResolver.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index 8747f14a3..540ab8fcf 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -1,8 +1,7 @@ /* eslint-disable new-cap */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ +import { Context, getUser } from '@/server/context' import { Resolver, Query, Args, Authorized, Ctx, Mutation } from 'type-graphql' import { getCustomRepository, getConnection } from '@dbTools/typeorm' @@ -147,10 +146,10 @@ export class TransactionResolver { async transactionList( @Args() { currentPage = 1, pageSize = 25, order = Order.DESC }: Paginated, - @Ctx() context: any, + @Ctx() context: Context, ): Promise { const now = new Date() - const user = context.user + const user = getUser(context) // find current balance const lastTransaction = await dbTransaction.findOne( @@ -247,10 +246,10 @@ export class TransactionResolver { @Mutation(() => String) async sendCoins( @Args() { email, amount, memo }: TransactionSendArgs, - @Ctx() context: any, + @Ctx() context: Context, ): Promise { // TODO this is subject to replay attacks - const senderUser = context.user + const senderUser = getUser(context) if (senderUser.pubKey.length !== 32) { throw new Error('invalid sender public key') } From 902dce63905701bdd20a73bc3337c871c59673bb Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 16:24:38 +0200 Subject: [PATCH 24/28] Context interface in balance resolver --- backend/src/graphql/resolver/BalanceResolver.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/backend/src/graphql/resolver/BalanceResolver.ts b/backend/src/graphql/resolver/BalanceResolver.ts index f30e779e5..7cbd455cb 100644 --- a/backend/src/graphql/resolver/BalanceResolver.ts +++ b/backend/src/graphql/resolver/BalanceResolver.ts @@ -1,6 +1,4 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - +import { Context, getUser } from '@/server/context' import { Resolver, Query, Ctx, Authorized } from 'type-graphql' import { Balance } from '@model/Balance' import { calculateDecay } from '@/util/decay' @@ -16,8 +14,8 @@ import { TransactionLinkRepository } from '@repository/TransactionLink' export class BalanceResolver { @Authorized([RIGHTS.BALANCE]) @Query(() => Balance) - async balance(@Ctx() context: any): Promise { - const { user } = context + async balance(@Ctx() context: Context): Promise { + const user = getUser(context) const now = new Date() const gdtResolver = new GdtResolver() From 71d170110259da8aba824fb571f2cacc6882031d Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 16:31:21 +0200 Subject: [PATCH 25/28] undo apollo log plugin hack --- backend/src/server/plugins.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/server/plugins.ts b/backend/src/server/plugins.ts index 5902a415f..a407135ea 100644 --- a/backend/src/server/plugins.ts +++ b/backend/src/server/plugins.ts @@ -39,6 +39,7 @@ const apolloLogPlugin = ApolloLogPlugin({ }, }) -const plugins = process.env.NODE_ENV === 'development' ? [setHeadersPlugin] : [setHeadersPlugin] // , apolloLogPlugin +const plugins = + process.env.NODE_ENV === 'development' ? [setHeadersPlugin] : [setHeadersPlugin, apolloLogPlugin] export default plugins From f752d8d0450cb049daf091c43083c6aeaf67a3c0 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 11 Apr 2022 17:25:59 +0200 Subject: [PATCH 26/28] type ExpressContext --- backend/src/server/context.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/src/server/context.ts b/backend/src/server/context.ts index f764c2876..d9fd55fe4 100644 --- a/backend/src/server/context.ts +++ b/backend/src/server/context.ts @@ -1,9 +1,8 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { Role } from '@/auth/Role' import { User as dbUser } from '@entity/User' import { Transaction as dbTransaction } from '@entity/Transaction' import Decimal from 'decimal.js-light' +import { ExpressContext } from 'apollo-server-express' export interface Context { token: string | null @@ -17,7 +16,7 @@ export interface Context { sumHoldAvailableAmount?: Decimal } -const context = (args: any): Context => { +const context = (args: ExpressContext): Context => { const authorization = args.req.headers.authorization let token: string | null = null if (authorization) { From 87aed30cfd8d90049715eebce5ccb2aef902e1d8 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 12 Apr 2022 14:57:46 +0200 Subject: [PATCH 27/28] good catch --- backend/src/seeds/graphql/queries.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index 04f849727..11a675eeb 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -59,7 +59,6 @@ export const transactionsQuery = gql` balanceGDT count balance - decayStartBlock transactions { id typeId From de6421201dd593dd5815c16b10e8827770dc56b8 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 12 Apr 2022 19:04:29 +0200 Subject: [PATCH 28/28] use getUser helper to get moderator form context --- backend/src/graphql/resolver/AdminResolver.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 481fb9bda..7ca3460ee 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -1,4 +1,4 @@ -import { Context } from '@/server/context' +import { Context, getUser } from '@/server/context' import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx, Int } from 'type-graphql' import { getCustomRepository, @@ -143,8 +143,8 @@ export class AdminResolver { throw new Error(`Could not find user with userId: ${userId}`) } // moderator user disabled own account? - const moderatorUser = context.user - if (moderatorUser && moderatorUser.id === userId) { + const moderatorUser = getUser(context) + if (moderatorUser.id === userId) { throw new Error('Moderator can not delete his own account!') } // soft-delete user @@ -310,8 +310,8 @@ export class AdminResolver { @Ctx() context: Context, ): Promise { const pendingCreation = await AdminPendingCreation.findOneOrFail(id) - const moderatorUser = context.user - if (moderatorUser && moderatorUser.id === pendingCreation.userId) + const moderatorUser = getUser(context) + if (moderatorUser.id === pendingCreation.userId) throw new Error('Moderator can not confirm own pending creation') const user = await dbUser.findOneOrFail({ id: pendingCreation.userId }, { withDeleted: true })