Merge branch 'master' into 1751-Make-GTT-visible-only-if-explicitly-clicked

This commit is contained in:
Alexander Friedland 2022-04-12 20:53:20 +02:00 committed by GitHub
commit fcb3250b63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 80 additions and 118 deletions

View File

@ -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

View File

@ -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, 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<Date | null> {
const user = await dbUser.findOne({ id: userId })
// user exists ?
@ -145,7 +143,7 @@ export class AdminResolver {
throw new Error(`Could not find user with userId: ${userId}`)
}
// moderator user disabled own account?
const moderatorUser = context.user
const moderatorUser = getUser(context)
if (moderatorUser.id === userId) {
throw new Error('Moderator can not delete his own account!')
}
@ -309,10 +307,10 @@ export class AdminResolver {
@Mutation(() => Boolean)
async confirmPendingCreation(
@Arg('id', () => Int) id: number,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<boolean> {
const pendingCreation = await AdminPendingCreation.findOneOrFail(id)
const moderatorUser = context.user
const moderatorUser = getUser(context)
if (moderatorUser.id === pendingCreation.userId)
throw new Error('Moderator can not confirm own pending creation')

View File

@ -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<Balance> {
const { user } = context
async balance(@Ctx() context: Context): Promise<Balance> {
const user = getUser(context)
const now = new Date()
const gdtResolver = new GdtResolver()

View File

@ -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'

View File

@ -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, Args, Ctx, Authorized, Arg } from 'type-graphql'
import CONFIG from '@/config'
import { GdtEntryList } from '@model/GdtEntryList'
@ -16,9 +14,9 @@ export class GdtResolver {
async listGDTEntries(
@Args()
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<GdtEntryList> {
const userEntity = context.user
const userEntity = getUser(context)
try {
const resultGDT = await apiGet(
@ -28,15 +26,15 @@ 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<number | null> {
const { user } = context
async gdtBalance(@Ctx() context: Context): Promise<number | null> {
const user = getUser(context)
try {
const resultGDTSum = await apiPost(`${CONFIG.GDT_API_URL}/GdtEntries/sumPerEmailApi`, {
email: user.email,
@ -45,9 +43,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
}
}

View File

@ -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,

View File

@ -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, 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,9 @@ export class TransactionLinkResolver {
@Mutation(() => TransactionLink)
async createTransactionLink(
@Args() { amount, memo }: TransactionLinkArgs,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<TransactionLink> {
const { user } = context
const user = getUser(context)
const createdDate = new Date()
const validUntil = transactionLinkExpireDate(createdDate)
@ -72,9 +70,9 @@ export class TransactionLinkResolver {
@Mutation(() => Boolean)
async deleteTransactionLink(
@Arg('id', () => Int) id: number,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<boolean> {
const { user } = context
const user = getUser(context)
const transactionLink = await dbTransactionLink.findOne({ id })
if (!transactionLink) {
@ -113,9 +111,9 @@ export class TransactionLinkResolver {
async listTransactionLinks(
@Args()
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<TransactionLink[]> {
const { user } = context
const user = getUser(context)
// const now = new Date()
const transactionLinks = await dbTransactionLink.find({
where: {
@ -136,9 +134,9 @@ export class TransactionLinkResolver {
@Mutation(() => Boolean)
async redeemTransactionLink(
@Arg('code', () => String) code: string,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<boolean> {
const { user } = context
const user = getUser(context)
const transactionLink = await dbTransactionLink.findOneOrFail({ code })
const linkedUser = await dbUser.findOneOrFail({ id: transactionLink.userId })

View File

@ -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<TransactionList> {
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<boolean> {
// 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')
}

View File

@ -1,7 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import fs from 'fs'
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,9 +190,9 @@ export class UserResolver {
@Authorized([RIGHTS.VERIFY_LOGIN])
@Query(() => User)
@UseMiddleware(klicktippNewsletterStateMiddleware)
async verifyLogin(@Ctx() context: any): Promise<User> {
async verifyLogin(@Ctx() context: Context): Promise<User> {
// TODO refactor and do not have duplicate code with login(see below)
const userEntity = context.user
const userEntity = getUser(context)
const user = new User(userEntity)
// user.pubkey = userEntity.pubKey.toString('hex')
// Elopage Status & Stored PublisherId
@ -218,7 +216,7 @@ export class UserResolver {
@UseMiddleware(klicktippNewsletterStateMiddleware)
async login(
@Args() { email, password, publisherId }: UnsecureLoginArgs,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<User> {
email = email.trim().toLowerCase()
const dbUser = await DbUser.findOneOrFail({ email }, { withDeleted: true }).catch(() => {
@ -250,7 +248,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, user: dbUser })
if (!user.hasElopage && publisherId) {
user.publisherId = publisherId
// TODO: Check if we can use updateUserInfos
@ -540,9 +538,9 @@ export class UserResolver {
passwordNew,
coinanimation,
}: UpdateUserInfosArgs,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<boolean> {
const userEntity = context.user
const userEntity = getUser(context)
if (firstName) {
userEntity.firstName = firstName
@ -619,7 +617,7 @@ export class UserResolver {
@Authorized([RIGHTS.HAS_ELOPAGE])
@Query(() => Boolean)
async hasElopage(@Ctx() context: any): Promise<boolean> {
async hasElopage(@Ctx() context: Context): Promise<boolean> {
const userEntity = context.user
if (!userEntity) {
return false

View File

@ -59,7 +59,6 @@ export const transactionsQuery = gql`
balanceGDT
count
balance
decayStartBlock
transactions {
id
typeId

View File

@ -1,9 +1,24 @@
/* 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'
const context = (args: any) => {
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: ExpressContext): Context => {
const authorization = args.req.headers.authorization
let token = null
let token: string | null = null
if (authorization) {
token = authorization.replace(/^Bearer /, '')
}
@ -14,4 +29,9 @@ const context = (args: any) => {
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

View File

@ -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"

View File

@ -50,7 +50,6 @@ export default {
name: 'DecayInformation-StartBlock',
props: {
balanceDate: { type: String },
decayStartBlock: { type: Date },
amount: {
type: String,
},

View File

@ -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()
},
},
}

View File

@ -26,7 +26,6 @@
<transaction-send
class="list-group-item"
v-bind="transactions[index]"
:decayStartBlock="decayStartBlock"
:previousBookedBalance="previousBookedBalance(index)"
v-on="$listeners"
/>
@ -36,7 +35,6 @@
<transaction-receive
class="list-group-item"
v-bind="transactions[index]"
:decayStartBlock="decayStartBlock"
:previousBookedBalance="previousBookedBalance(index)"
v-on="$listeners"
/>
@ -46,7 +44,6 @@
<transaction-creation
class="list-group-item"
v-bind="transactions[index]"
:decayStartBlock="decayStartBlock"
:previousBookedBalance="previousBookedBalance(index)"
v-on="$listeners"
/>
@ -105,7 +102,6 @@ export default {
}
},
props: {
decayStartBlock: { type: Date },
transactions: { default: () => [] },
pageSize: { type: Number, default: 25 },
timestamp: { type: Number, default: 0 },

View File

@ -27,12 +27,7 @@
</div>
<b-collapse :class="visible ? 'bg-secondary' : ''" class="pb-4 pt-5" v-model="visible">
<decay-information
:typeId="typeId"
:decay="decay"
:amount="amount"
:decayStartBlock="decayStartBlock"
/>
<decay-information :typeId="typeId" :decay="decay" :amount="amount" />
</b-collapse>
</div>
</div>
@ -82,10 +77,6 @@ export default {
type: String,
required: true,
},
decayStartBlock: {
type: Date,
required: true,
},
previousBookedBalance: {
type: String,
required: true,

View File

@ -33,12 +33,7 @@
</div>
<b-collapse :class="visible ? 'bg-secondary' : ''" class="pb-4 pt-5" v-model="visible">
<decay-information
:typeId="typeId"
:decay="decay"
:amount="amount"
:decayStartBlock="decayStartBlock"
/>
<decay-information :typeId="typeId" :decay="decay" :amount="amount" />
</b-collapse>
</div>
</div>
@ -87,10 +82,6 @@ export default {
typeId: {
type: String,
},
decayStartBlock: {
type: Date,
required: true,
},
transactionLinkId: {
type: Number,
required: false,

View File

@ -33,12 +33,7 @@
</div>
<b-collapse :class="visible ? 'bg-secondary' : ''" class="pb-4 pt-5" v-model="visible">
<decay-information
:typeId="typeId"
:decay="decay"
:amount="amount"
:decayStartBlock="decayStartBlock"
/>
<decay-information :typeId="typeId" :decay="decay" :amount="amount" />
</b-collapse>
</div>
</div>
@ -88,10 +83,6 @@ export default {
type: String,
required: true,
},
decayStartBlock: {
type: Date,
required: true,
},
transactionLinkId: {
type: Number,
required: false,

View File

@ -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',

View File

@ -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'))
})
})
})

View File

@ -52,7 +52,6 @@ export const transactionsQuery = gql`
balanceGDT
count
linkCount
decayStartBlock
lastBookedDate
}
transactions {

View File

@ -26,7 +26,6 @@
:transactionCount="transactionCount"
:transactionLinkCount="transactionLinkCount"
:pending="pending"
:decayStartBlock="decayStartBlock"
@update-transactions="updateTransactions"
@set-tunneled-email="setTunneledEmail"
></router-view>
@ -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) => {

View File

@ -5,7 +5,6 @@
:transactions="transactions"
:pageSize="5"
:timestamp="timestamp"
:decayStartBlock="decayStartBlock"
:transaction-count="transactionCount"
:transactionLinkCount="transactionLinkCount"
:pending="pending"
@ -32,8 +31,6 @@ export default {
}
},
props: {
balance: { type: Number, default: 0 },
decayStartBlock: { type: Date },
transactions: {
default: () => [],
},

View File

@ -10,7 +10,6 @@
:transactionLinkCount="transactionLinkCount"
:transactions="transactions"
:show-pagination="true"
:decayStartBlock="decayStartBlock"
@update-transactions="updateTransactions"
v-on="$listeners"
/>
@ -44,7 +43,6 @@ export default {
},
transactionCount: { type: Number, default: 0 },
transactionLinkCount: { type: Number, default: 0 },
decayStartBlock: { type: Date },
},
data() {
return {