Merge branch 'master' into refactor_user_resolver

This commit is contained in:
Ulf Gebhardt 2022-02-18 17:17:57 +01:00 committed by GitHub
commit 09d15a2359
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 129 additions and 40 deletions

View File

@ -4,7 +4,7 @@ import dotenv from 'dotenv'
dotenv.config()
const constants = {
DB_VERSION: '0022-delete_decay_start_block',
DB_VERSION: '0023-users_disabled_soft_delete',
DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0
}

View File

@ -367,7 +367,7 @@ export class TransactionResolver {
const recipiantUser = await userRepository.findByPubkeyHex(recipiantPublicKey)
if (!recipiantUser) {
throw new Error('Cannot find recipiant user by local send coins transaction')
} else if (recipiantUser.disabled) {
} else if (recipiantUser.deletedAt) {
throw new Error('recipiant user account is disabled')
}

View File

@ -0,0 +1,75 @@
import {
BaseEntity,
Entity,
PrimaryGeneratedColumn,
Column,
OneToMany,
DeleteDateColumn,
} from 'typeorm'
import { UserSetting } from '../UserSetting'
@Entity('users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
export class User extends BaseEntity {
@PrimaryGeneratedColumn('increment', { unsigned: true })
id: number
@Column({ name: 'public_key', type: 'binary', length: 32, default: null, nullable: true })
pubKey: Buffer
@Column({ name: 'privkey', type: 'binary', length: 80, default: null, nullable: true })
privKey: Buffer
@Column({ length: 255, unique: true, nullable: false, collation: 'utf8mb4_unicode_ci' })
email: string
@Column({
name: 'first_name',
length: 255,
nullable: true,
default: null,
collation: 'utf8mb4_unicode_ci',
})
firstName: string
@Column({
name: 'last_name',
length: 255,
nullable: true,
default: null,
collation: 'utf8mb4_unicode_ci',
})
lastName: string
@DeleteDateColumn()
deletedAt: Date | null
@Column({ type: 'bigint', default: 0, unsigned: true })
password: BigInt
@Column({ name: 'email_hash', type: 'binary', length: 32, default: null, nullable: true })
emailHash: Buffer
@Column({ name: 'created', default: () => 'CURRENT_TIMESTAMP', nullable: false })
createdAt: Date
@Column({ name: 'email_checked', type: 'bool', nullable: false, default: false })
emailChecked: boolean
@Column({ length: 4, default: 'de', collation: 'utf8mb4_unicode_ci', nullable: false })
language: string
@Column({ name: 'publisher_id', default: 0 })
publisherId: number
@Column({
type: 'text',
name: 'passphrase',
collation: 'utf8mb4_unicode_ci',
nullable: true,
default: null,
})
passphrase: string
@OneToMany(() => UserSetting, (userSetting) => userSetting.user)
settings: UserSetting[]
}

View File

@ -1 +1 @@
export { User } from './0020-rename_and_clean_state_users/User'
export { User } from './0023-users_disabled_soft_delete/User'

View File

@ -0,0 +1,26 @@
/* MIGRATION TO IMPLEMENT SOFT DELETE ON THE USERS TABLE
*
* Replace the `disabled` column with `deletedAt` containing
* a date as it is standard for soft delete fields
*/
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
// Create new `deletedAt` column
await queryFn(
'ALTER TABLE `users` ADD COLUMN `deletedAt` datetime DEFAULT NULL AFTER `disabled`;',
)
// Insert a 1.1.2022 as date for those users with `disabled=1`
await queryFn('UPDATE `users` SET `deletedAt` = "2022-01-01 00:00:00" WHERE `disabled` = 1;')
// Delete `disabled` column
await queryFn('ALTER TABLE `users` DROP COLUMN `disabled`;')
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(
'ALTER TABLE `users` ADD COLUMN `disabled` tinyint(4) NOT NULL DEFAULT 0 AFTER `deletedAt`;',
)
await queryFn('UPDATE `users` SET `disabled` = 1 WHERE `deletedAt` IS NOT NULL;')
await queryFn('ALTER TABLE `users` DROP COLUMN `deletedAt`;')
}

View File

@ -12,7 +12,7 @@ define(User, (faker: typeof Faker, context?: UserContext) => {
user.email = context.email ? context.email : faker.internet.email()
user.firstName = context.firstName ? context.firstName : faker.name.firstName()
user.lastName = context.lastName ? context.lastName : faker.name.lastName()
user.disabled = context.disabled ? context.disabled : false
user.deletedAt = context.deletedAt ? context.deletedAt : null
// TODO Create real password and keys/hash
user.password = context.password ? context.password : BigInt(0)
user.privKey = context.privKey ? context.privKey : randomBytes(80)

View File

@ -3,7 +3,7 @@ export interface UserContext {
email?: string
firstName?: string
lastName?: string
disabled?: boolean
deletedAt?: Date
password?: BigInt
privKey?: Buffer
emailHash?: Buffer

View File

@ -10,7 +10,7 @@ export interface UserInterface {
createdAt?: Date
emailChecked?: boolean
language?: string
disabled?: boolean
deletedAt?: Date
groupId?: number
publisherId?: number
passphrase?: string

View File

@ -42,7 +42,7 @@ const createUserContext = (context: UserInterface): UserContext => {
email: context.email,
firstName: context.firstName,
lastName: context.lastName,
disabled: context.disabled,
deletedAt: context.deletedAt,
password: context.password,
privKey: context.privKey,
emailHash: context.emailHash,

View File

@ -1,7 +1,7 @@
<template>
<div class="decayinformation">
<span v-if="decaytyp === 'short'">
{{ decay ? ' - ' + $n(decay.balance, 'decimal') + ' ' + decayStartBlockTextShort : '' }}
{{ decay ? ' ' + $n(decay.balance, 'decimal') : '' }}
</span>
<div v-if="decaytyp === 'new'">
@ -19,14 +19,11 @@
<b-col cols="6">
<div v-if="decay.decayStartBlock > 0">
<div class="display-4">{{ $t('decay.Starting_block_decay') }}</div>
<div>
{{ $t('decay.decay_introduced') }} :
{{ $d($moment.unix(decay.decayStart), 'long') }}
</div>
<div>{{ $t('decay.decay_introduced') }} :</div>
</div>
<div>
<span v-if="decay.decayStart">
{{ $d($moment.unix(decay.decayStart), 'long') }}
{{ $d(new Date(decay.decayStart * 1000), 'long') }}
{{ $i18n.locale === 'de' ? 'Uhr' : '' }}
</span>
</div>
@ -59,7 +56,7 @@
<div>{{ $t('decay.decay') }}</div>
</b-col>
<b-col cols="6">
<div>- {{ $n(decay.balance, 'decimal') }}</div>
<div> {{ $n(decay.balance, 'decimal') }}</div>
</b-col>
</b-row>
<hr class="mt-2 mb-2" />
@ -75,7 +72,7 @@
<div v-if="type === 'receive'">{{ $t('decay.received') }}</div>
</b-col>
<b-col cols="6">
<div v-if="type === 'send'">- {{ $n(balance, 'decimal') }}</div>
<div v-if="type === 'send'"> {{ $n(balance, 'decimal') }}</div>
<div v-if="type === 'receive'">+ {{ $n(balance, 'decimal') }}</div>
</b-col>
</b-row>
@ -85,7 +82,7 @@
<div>{{ $t('decay.decay') }}</div>
</b-col>
<b-col cols="6">
<div>- {{ $n(decay.balance, 'decimal') }}</div>
<div> {{ $n(decay.balance, 'decimal') }}</div>
</b-col>
</b-row>
<!-- Total-->
@ -95,13 +92,13 @@
</b-col>
<b-col cols="6">
<div v-if="type === 'send'">
<b>- {{ $n(balance + decay.balance, 'decimal') }}</b>
<b> {{ $n(balance + decay.balance, 'decimal') }}</b>
</div>
<div v-if="type === 'receive'">
<b>{{ $n(balance - decay.balance, 'decimal') }}</b>
</div>
<div v-if="type === 'creation'">
<b>- {{ $n(balance - decay.balance, 'decimal') }}</b>
<b> {{ $n(balance - decay.balance, 'decimal') }}</b>
</div>
</b-col>
</b-row>
@ -124,17 +121,8 @@ export default {
decaytyp: { type: String, default: '' },
},
computed: {
decayStartBlockTextShort() {
return this.decay.decayStartBlock
? this.$t('decay.decayStart') + this.$d(this.$moment.unix(this.decay.decayStartBlock))
: ''
},
duration() {
return this.$moment.duration(
this.$moment
.unix(new Date(this.decay.decayEnd))
.diff(this.$moment.unix(new Date(this.decay.decayStart))),
)._data
return this.$moment.duration((this.decay.decayEnd - this.decay.decayStart) * 1000)._data
},
},
}

View File

@ -50,7 +50,7 @@
{{ $t('form.date') }}
</b-col>
<b-col cols="6">
{{ $d($moment(date), 'long') }} {{ $i18n.locale === 'de' ? 'Uhr' : '' }}
{{ $d(new Date(date), 'long') }} {{ $i18n.locale === 'de' ? 'Uhr' : '' }}
</b-col>
</b-row>

View File

@ -69,8 +69,8 @@ const dateTimeFormats = {
},
long: {
year: 'numeric',
month: 'short',
day: 'numeric',
month: 'long',
day: 'long',
weekday: 'short',
hour: 'numeric',
minute: 'numeric',
@ -84,9 +84,9 @@ const dateTimeFormats = {
},
long: {
day: 'numeric',
month: 'short',
month: 'long',
year: 'numeric',
weekday: 'short',
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
},

View File

@ -145,7 +145,7 @@ describe('GddTransactionList', () => {
it('has a minus operator', () => {
expect(transaction.findAll('.gdd-transaction-list-item-operator').at(0).text()).toContain(
'-',
'',
)
})
@ -175,7 +175,7 @@ describe('GddTransactionList', () => {
it('shows the decay calculation', () => {
expect(transaction.findAll('div.gdd-transaction-list-item-decay').at(0).text()).toContain(
'- 0.5',
' 0.5',
)
})
})
@ -265,7 +265,7 @@ describe('GddTransactionList', () => {
it('shows the decay calculation', () => {
expect(transaction.findAll('.gdd-transaction-list-item-decay').at(0).text()).toContain(
'- 1.5',
' 1.5',
)
})
})
@ -286,7 +286,7 @@ describe('GddTransactionList', () => {
it('has a minus operator', () => {
expect(transaction.findAll('.gdd-transaction-list-item-operator').at(0).text()).toContain(
'-',
'',
)
})

View File

@ -77,7 +77,7 @@
</b-col>
<b-col cols="7">
<div class="gdd-transaction-list-item-date">
{{ $d($moment(date), 'long') }} {{ $i18n.locale === 'de' ? 'Uhr' : '' }}
{{ $d(new Date(date), 'long') }} {{ $i18n.locale === 'de' ? 'Uhr' : '' }}
</div>
</b-col>
</b-row>
@ -146,10 +146,10 @@ import PaginationButtons from '../../../components/PaginationButtons'
import DecayInformation from '../../../components/DecayInformation'
const iconsByType = {
send: { icon: 'arrow-left-circle', classes: 'text-danger', operator: '-' },
send: { icon: 'arrow-left-circle', classes: 'text-danger', operator: '' },
receive: { icon: 'arrow-right-circle', classes: 'gradido-global-color-accent', operator: '+' },
creation: { icon: 'gift', classes: 'gradido-global-color-accent', operator: '+' },
decay: { icon: 'droplet-half', classes: 'gradido-global-color-gray', operator: '-' },
decay: { icon: 'droplet-half', classes: 'gradido-global-color-gray', operator: '' },
}
export default {