From 20b61d82b7c9ff7d9d60f6f71950522da8cb8a3e Mon Sep 17 00:00:00 2001 From: ogerly Date: Fri, 7 Jan 2022 13:20:23 +0100 Subject: [PATCH 01/22] reverse filter for unregistered emails --- admin/src/pages/UserSearch.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/src/pages/UserSearch.vue b/admin/src/pages/UserSearch.vue index 012dd0a44..d811fe2ad 100644 --- a/admin/src/pages/UserSearch.vue +++ b/admin/src/pages/UserSearch.vue @@ -75,7 +75,7 @@ export default { methods: { unconfirmedRegisterMails() { this.searchResult = this.searchResult.filter((user) => { - return user.emailChecked + return !user.emailChecked }) }, getUsers() { From 19f9ccd6392753f8d937b9313056d090b7cacddd Mon Sep 17 00:00:00 2001 From: ogerly Date: Fri, 7 Jan 2022 13:30:39 +0100 Subject: [PATCH 02/22] yarn test fixed --- admin/src/pages/UserSearch.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/src/pages/UserSearch.spec.js b/admin/src/pages/UserSearch.spec.js index 473b2bbdc..b6d01b254 100644 --- a/admin/src/pages/UserSearch.spec.js +++ b/admin/src/pages/UserSearch.spec.js @@ -61,7 +61,7 @@ describe('UserSearch', () => { }) it('filters the users by unconfirmed emails', () => { - expect(wrapper.vm.searchResult).toHaveLength(0) + expect(wrapper.vm.searchResult).toHaveLength(1) }) }) From bdf77f699faf3aca4035f37104e073d08ae4c976 Mon Sep 17 00:00:00 2001 From: ogerly Date: Fri, 7 Jan 2022 17:42:56 +0100 Subject: [PATCH 03/22] switch password-text by checkmail and reset --- frontend/src/views/Pages/ResetPassword.vue | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/frontend/src/views/Pages/ResetPassword.vue b/frontend/src/views/Pages/ResetPassword.vue index 3e6aef339..9c3c2da7c 100644 --- a/frontend/src/views/Pages/ResetPassword.vue +++ b/frontend/src/views/Pages/ResetPassword.vue @@ -5,10 +5,10 @@
-

{{ $t('settings.password.reset') }}

+

{{ $t(displaySetup.authenticated) }}

- {{ $t('settings.password.reset-password.text') }} + {{ $t(displaySetup.notAuthenticated) }}
@@ -49,14 +49,14 @@ import { setPassword } from '../../graphql/mutations' const textFields = { reset: { - authenticated: 'settings.password.reset-password.text', - notAuthenticated: 'settings.password.not-authenticated', - button: 'settings.password.reset', + authenticated: 'settings.password.change-password', + notAuthenticated: 'settings.password.reset-password.text', + button: 'settings.password.change-password', linkTo: '/login', }, checkEmail: { - authenticated: 'settings.password.set-password.text', - notAuthenticated: 'settings.password.not-authenticated', + authenticated: 'settings.password.set', + notAuthenticated: 'settings.password.set-password.text', button: 'settings.password.set', linkTo: '/login', }, @@ -103,11 +103,16 @@ export default { } }) }, - setDisplaySetup() { - if (!this.$route.params.comingFrom) { + setDisplaySetup(from) { + console.log('this.$route > ', this.$route.path) + + if (this.$route.path.includes('checkEmail')) { + this.displaySetup = textFields.checkEmail + console.log('this.displaySetup checkmail> ', this.displaySetup) + } + if (this.$route.path.includes('reset')) { this.displaySetup = textFields.reset - } else { - this.displaySetup = textFields[this.$route.params.comingFrom] + console.log('this.displaySetup reset> ', this.displaySetup) } }, }, From aa80f0f21a967f77d5c87863290c17fa414f8a2a Mon Sep 17 00:00:00 2001 From: ogerly Date: Fri, 7 Jan 2022 17:43:49 +0100 Subject: [PATCH 04/22] yarn lint --fix --- frontend/src/views/Pages/ResetPassword.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/views/Pages/ResetPassword.vue b/frontend/src/views/Pages/ResetPassword.vue index 9c3c2da7c..84bc6e83b 100644 --- a/frontend/src/views/Pages/ResetPassword.vue +++ b/frontend/src/views/Pages/ResetPassword.vue @@ -108,7 +108,7 @@ export default { if (this.$route.path.includes('checkEmail')) { this.displaySetup = textFields.checkEmail - console.log('this.displaySetup checkmail> ', this.displaySetup) + console.log('this.displaySetup checkmail> ', this.displaySetup) } if (this.$route.path.includes('reset')) { this.displaySetup = textFields.reset From d70ce5ed0056fb9ce09cd38dfbe48430e6e60a07 Mon Sep 17 00:00:00 2001 From: ogerly Date: Fri, 7 Jan 2022 17:45:33 +0100 Subject: [PATCH 05/22] remove console states. yarn lint --- frontend/src/views/Pages/ResetPassword.vue | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frontend/src/views/Pages/ResetPassword.vue b/frontend/src/views/Pages/ResetPassword.vue index 84bc6e83b..c227eeabe 100644 --- a/frontend/src/views/Pages/ResetPassword.vue +++ b/frontend/src/views/Pages/ResetPassword.vue @@ -104,15 +104,11 @@ export default { }) }, setDisplaySetup(from) { - console.log('this.$route > ', this.$route.path) - if (this.$route.path.includes('checkEmail')) { this.displaySetup = textFields.checkEmail - console.log('this.displaySetup checkmail> ', this.displaySetup) } if (this.$route.path.includes('reset')) { this.displaySetup = textFields.reset - console.log('this.displaySetup reset> ', this.displaySetup) } }, }, From 55d85a8ccf6f7f3d6d0fcae05aadb330384d07eb Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Jan 2022 10:01:47 +0100 Subject: [PATCH 06/22] fix: Change Password in User Profile --- backend/src/graphql/resolver/AdminResolver.ts | 3 +++ backend/src/graphql/resolver/UserResolver.ts | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 12a07d51d..0d16769c7 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -1,3 +1,6 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ + import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx } from 'type-graphql' import { getCustomRepository, Raw } from 'typeorm' import { UserAdmin } from '../model/UserAdmin' diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 2f98a2f6f..769bb4426 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -738,7 +738,7 @@ export class UserResolver { if (password && passwordNew) { // TODO: This had some error cases defined - like missing private key. This is no longer checked. const oldPasswordHash = SecretKeyCryptographyCreateKey(loginUser.email, password) - if (loginUser.password !== oldPasswordHash[0].readBigUInt64LE()) { + if (BigInt(loginUser.password.toString()) !== oldPasswordHash[0].readBigUInt64LE()) { throw new Error(`Old password is invalid`) } @@ -748,7 +748,7 @@ export class UserResolver { const encryptedPrivkey = SecretKeyCryptographyEncrypt(privKey, newPasswordHash[1]) // Save new password hash and newly encrypted private key - loginUser.password = newPasswordHash[0].readBigInt64LE() + loginUser.password = newPasswordHash[0].readBigUInt64LE() loginUser.privKey = encryptedPrivkey } From fd409252cbb49a3d0273f799e85afa766e0ad69c Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Jan 2022 10:45:41 +0100 Subject: [PATCH 07/22] get the test working --- frontend/src/views/Pages/ResetPassword.spec.js | 3 +++ frontend/src/views/Pages/ResetPassword.vue | 9 +++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/views/Pages/ResetPassword.spec.js b/frontend/src/views/Pages/ResetPassword.spec.js index f3bbc7334..e28d16c3e 100644 --- a/frontend/src/views/Pages/ResetPassword.spec.js +++ b/frontend/src/views/Pages/ResetPassword.spec.js @@ -28,6 +28,9 @@ const createMockObject = (comingFrom) => { optin: '123', comingFrom, }, + path: { + includes: (t) => t, + }, }, $toasted: { global: { diff --git a/frontend/src/views/Pages/ResetPassword.vue b/frontend/src/views/Pages/ResetPassword.vue index c227eeabe..05d8a0f6e 100644 --- a/frontend/src/views/Pages/ResetPassword.vue +++ b/frontend/src/views/Pages/ResetPassword.vue @@ -95,15 +95,12 @@ export default { this.$router.push('/thx/reset') }) .catch((error) => { - if (error.message.includes('Code is older than 10 minutes')) { - this.$toasted.global.error(error.message) + this.$toasted.global.error(error.message) + if (error.message.includes('Code is older than 10 minutes')) this.$router.push('/password/reset') - } else { - this.$toasted.global.error(error.message) - } }) }, - setDisplaySetup(from) { + setDisplaySetup() { if (this.$route.path.includes('checkEmail')) { this.displaySetup = textFields.checkEmail } From 09a1b05ca0cb48fd83342fa79ffa8f3e3d77d108 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 10 Jan 2022 11:03:10 +0100 Subject: [PATCH 08/22] Backend gave the gdtSum with cents include in the number, now divided by 100. --- backend/src/graphql/resolver/TransactionResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index d8ef1fb0f..88c1424b3 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -503,7 +503,7 @@ export class TransactionResolver { email: userEntity.email, }) if (!resultGDTSum.success) throw new Error(resultGDTSum.data) - transactions.gdtSum = resultGDTSum.data.sum || 0 + transactions.gdtSum = Number(resultGDTSum.data.sum / 100) || 0 // get balance const balanceRepository = getCustomRepository(BalanceRepository) From 933275c36702dd143b24eb7466be0f10d7eeeefc Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Jan 2022 13:03:05 +0100 Subject: [PATCH 09/22] .global.error to .error as global is not defined so far --- admin/src/components/CreationTransactionListFormular.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/src/components/CreationTransactionListFormular.vue b/admin/src/components/CreationTransactionListFormular.vue index 09e1fa92a..d3ffc3e29 100644 --- a/admin/src/components/CreationTransactionListFormular.vue +++ b/admin/src/components/CreationTransactionListFormular.vue @@ -33,7 +33,7 @@ export default { this.items = result.data.transactionList.transactions }) .catch((error) => { - this.$toasted.global.error(error.message) + this.$toasted.error(error.message) }) }, }, From 814f9e18ddb3c46d868c6a20018c559f70f3587c Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Jan 2022 13:25:35 +0100 Subject: [PATCH 10/22] fix update of open creations --- admin/src/pages/UserSearch.vue | 12 +++++------- backend/src/graphql/resolver/AdminResolver.ts | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/admin/src/pages/UserSearch.vue b/admin/src/pages/UserSearch.vue index d811fe2ad..a5d4c05cf 100644 --- a/admin/src/pages/UserSearch.vue +++ b/admin/src/pages/UserSearch.vue @@ -42,15 +42,13 @@ export default { { key: 'lastName', label: this.$t('lastname') }, { key: 'creation', - // label: this.$t('open_creation') + 'Jan | Feb | März', - label: - this.$moment().subtract(2, 'month').format('MMM') + - ' | ' + - this.$moment().subtract(1, 'month').format('MMM') + - ' | ' + + label: [ + this.$moment().subtract(2, 'month').format('MMM'), + this.$moment().subtract(1, 'month').format('MMM'), this.$moment().format('MMM'), + ].join(' | '), formatter: (value, key, item) => { - return String(value[0]) + ` | ` + String(value[1]) + ` | ` + String(value[2]) + return value.join(' | ') }, }, { key: 'show_details', label: this.$t('details') }, diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 0d16769c7..11d8c99cd 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -65,9 +65,9 @@ export class AdminResolver { loginPendingTaskAdmin.memo = memo loginPendingTaskAdmin.moderator = moderator - loginPendingTasksAdminRepository.save(loginPendingTaskAdmin) + await loginPendingTasksAdminRepository.save(loginPendingTaskAdmin) } - return await getUserCreations(user.id) + return getUserCreations(user.id) } @Authorized([RIGHTS.CREATE_PENDING_CREATION]) From 5c3c22780a4a8119e7716c0619c4450b49ab3de1 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Jan 2022 13:45:38 +0100 Subject: [PATCH 11/22] get the tests running --- .../components/CreationTransactionListFormular.spec.js | 4 +--- admin/src/components/UserTable.spec.js | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/admin/src/components/CreationTransactionListFormular.spec.js b/admin/src/components/CreationTransactionListFormular.spec.js index 9817d6b8f..1c7b81c25 100644 --- a/admin/src/components/CreationTransactionListFormular.spec.js +++ b/admin/src/components/CreationTransactionListFormular.spec.js @@ -58,9 +58,7 @@ const mocks = { query: apolloQueryMock, }, $toasted: { - global: { - error: toastedErrorMock, - }, + error: toastedErrorMock, }, } diff --git a/admin/src/components/UserTable.spec.js b/admin/src/components/UserTable.spec.js index 80bdf6047..e26a548cc 100644 --- a/admin/src/components/UserTable.spec.js +++ b/admin/src/components/UserTable.spec.js @@ -3,6 +3,9 @@ import UserTable from './UserTable.vue' const localVue = global.localVue +const apolloQueryMock = jest.fn() +apolloQueryMock.mockResolvedValue() + describe('UserTable', () => { let wrapper @@ -114,6 +117,12 @@ describe('UserTable', () => { }), } }), + $apollo: { + query: apolloQueryMock, + }, + $store: { + commit: jest.fn(), + }, } const Wrapper = (propsData) => { From c4cbc50da0cf5227c1dd940ccea63d632e316b83 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Jan 2022 16:33:52 +0100 Subject: [PATCH 12/22] address correct db column for only creations filter --- backend/src/typeorm/repository/UserTransaction.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/typeorm/repository/UserTransaction.ts b/backend/src/typeorm/repository/UserTransaction.ts index 57f89d5a5..386145d03 100644 --- a/backend/src/typeorm/repository/UserTransaction.ts +++ b/backend/src/typeorm/repository/UserTransaction.ts @@ -1,6 +1,7 @@ import { EntityRepository, Repository } from 'typeorm' import { Order } from '../../graphql/enum/Order' import { UserTransaction } from '@entity/UserTransaction' +import { TransactionTypeId } from '../../graphql/enum/TransactionTypeId' @EntityRepository(UserTransaction) export class UserTransactionRepository extends Repository { @@ -14,7 +15,9 @@ export class UserTransactionRepository extends Repository { if (onlyCreation) { return this.createQueryBuilder('userTransaction') .where('userTransaction.userId = :userId', { userId }) - .andWhere('userTransaction.type = "creation"') + .andWhere('userTransaction.transactionTypeId = :transactionTypeId', { + transactionTypeId: TransactionTypeId.CREATION, + }) .orderBy('userTransaction.balanceDate', order) .limit(limit) .offset(offset) From 3abce024baf8cd309c443ea0ff383f11c3f09b21 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Jan 2022 16:40:30 +0100 Subject: [PATCH 13/22] filter transactions for type creation due to the first transaction is always a decay --- .../components/CreationTransactionListFormular.spec.js | 8 +++----- admin/src/components/CreationTransactionListFormular.vue | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/admin/src/components/CreationTransactionListFormular.spec.js b/admin/src/components/CreationTransactionListFormular.spec.js index 9817d6b8f..32dcb6c9d 100644 --- a/admin/src/components/CreationTransactionListFormular.spec.js +++ b/admin/src/components/CreationTransactionListFormular.spec.js @@ -8,7 +8,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({ transactionList: { transactions: [ { - type: 'created', + type: 'creation', balance: 100, decayStart: 0, decayEnd: 0, @@ -27,7 +27,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({ }, }, { - type: 'created', + type: 'creation', balance: 200, decayStart: 0, decayEnd: 0, @@ -58,9 +58,7 @@ const mocks = { query: apolloQueryMock, }, $toasted: { - global: { - error: toastedErrorMock, - }, + error: toastedErrorMock, }, } diff --git a/admin/src/components/CreationTransactionListFormular.vue b/admin/src/components/CreationTransactionListFormular.vue index 09e1fa92a..7fed4adcc 100644 --- a/admin/src/components/CreationTransactionListFormular.vue +++ b/admin/src/components/CreationTransactionListFormular.vue @@ -30,10 +30,10 @@ export default { }, }) .then((result) => { - this.items = result.data.transactionList.transactions + this.items = result.data.transactionList.transactions.filter((t) => t.type === 'creation') }) .catch((error) => { - this.$toasted.global.error(error.message) + this.$toasted.error(error.message) }) }, }, From d07755f95aa9e1f26df35045dfc3355051eef56b Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Jan 2022 13:45:38 +0100 Subject: [PATCH 14/22] get the tests running --- admin/src/components/UserTable.spec.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/admin/src/components/UserTable.spec.js b/admin/src/components/UserTable.spec.js index 80bdf6047..e26a548cc 100644 --- a/admin/src/components/UserTable.spec.js +++ b/admin/src/components/UserTable.spec.js @@ -3,6 +3,9 @@ import UserTable from './UserTable.vue' const localVue = global.localVue +const apolloQueryMock = jest.fn() +apolloQueryMock.mockResolvedValue() + describe('UserTable', () => { let wrapper @@ -114,6 +117,12 @@ describe('UserTable', () => { }), } }), + $apollo: { + query: apolloQueryMock, + }, + $store: { + commit: jest.fn(), + }, } const Wrapper = (propsData) => { From b5a54929fd03e484a3a4d9eb3fccc8fe9b01eb0f Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Jan 2022 08:47:53 +0100 Subject: [PATCH 15/22] feat: Seed Garrick Ollivander --- database/src/factories/login-user.factory.ts | 2 +- database/src/index.ts | 2 ++ database/src/interface/UserContext.ts | 6 ++--- database/src/interface/UserInterface.ts | 4 ++-- .../seeds/users/garrick-ollivander.seed.ts | 9 +++++++ .../src/seeds/users/garrick-ollivander.ts | 24 +++++++++++++++++++ 6 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 database/src/seeds/users/garrick-ollivander.seed.ts create mode 100644 database/src/seeds/users/garrick-ollivander.ts diff --git a/database/src/factories/login-user.factory.ts b/database/src/factories/login-user.factory.ts index a5a28943e..b3c0312f3 100644 --- a/database/src/factories/login-user.factory.ts +++ b/database/src/factories/login-user.factory.ts @@ -19,7 +19,7 @@ define(LoginUser, (faker: typeof Faker, context?: LoginUserContext) => { user.privKey = context.privKey ? context.privKey : randomBytes(80) user.emailHash = context.emailHash ? context.emailHash : randomBytes(32) user.createdAt = context.createdAt ? context.createdAt : faker.date.recent() - user.emailChecked = context.emailChecked ? context.emailChecked : true + user.emailChecked = context.emailChecked === undefined ? false : context.emailChecked user.passphraseShown = context.passphraseShown ? context.passphraseShown : false user.language = context.language ? context.language : 'en' user.disabled = context.disabled ? context.disabled : false diff --git a/database/src/index.ts b/database/src/index.ts index 488d098d3..033a36d8b 100644 --- a/database/src/index.ts +++ b/database/src/index.ts @@ -6,6 +6,7 @@ import { CreatePeterLustigSeed } from './seeds/users/peter-lustig.admin.seed' import { CreateBibiBloxbergSeed } from './seeds/users/bibi-bloxberg.seed' import { CreateRaeuberHotzenplotzSeed } from './seeds/users/raeuber-hotzenplotz.seed' import { CreateBobBaumeisterSeed } from './seeds/users/bob-baumeister.seed' +import { CreateGarrickOllivanderSeed } from './seeds/users/garrick-ollivander.seed' import { DecayStartBlockSeed } from './seeds/decay-start-block.seed' import { resetDB, pool, migration } from './helpers' @@ -44,6 +45,7 @@ const run = async (command: string) => { await runSeeder(CreateBibiBloxbergSeed) await runSeeder(CreateRaeuberHotzenplotzSeed) await runSeeder(CreateBobBaumeisterSeed) + await runSeeder(CreateGarrickOllivanderSeed) break default: throw new Error(`Unsupported command ${command}`) diff --git a/database/src/interface/UserContext.ts b/database/src/interface/UserContext.ts index 4e188904c..87cc70af6 100644 --- a/database/src/interface/UserContext.ts +++ b/database/src/interface/UserContext.ts @@ -1,5 +1,5 @@ export interface UserContext { - pubkey?: Buffer + pubkey?: Buffer | null email?: string firstName?: string lastName?: string @@ -14,8 +14,8 @@ export interface LoginUserContext { username?: string description?: string password?: BigInt - pubKey?: Buffer - privKey?: Buffer + pubKey?: Buffer | null + privKey?: Buffer | null emailHash?: Buffer createdAt?: Date emailChecked?: boolean diff --git a/database/src/interface/UserInterface.ts b/database/src/interface/UserInterface.ts index 70be6cff4..e68c23ec3 100644 --- a/database/src/interface/UserInterface.ts +++ b/database/src/interface/UserInterface.ts @@ -6,8 +6,8 @@ export interface UserInterface { username?: string description?: string password?: BigInt - pubKey?: Buffer - privKey?: Buffer + pubKey?: Buffer | null + privKey?: Buffer | null emailHash?: Buffer createdAt?: Date emailChecked?: boolean diff --git a/database/src/seeds/users/garrick-ollivander.seed.ts b/database/src/seeds/users/garrick-ollivander.seed.ts new file mode 100644 index 000000000..54adc3475 --- /dev/null +++ b/database/src/seeds/users/garrick-ollivander.seed.ts @@ -0,0 +1,9 @@ +import { Factory, Seeder } from 'typeorm-seeding' +import { garrickOllivander } from './garrick-ollivander' +import { userSeeder } from '../helpers/user-helpers' + +export class CreateGarrickOllivanderSeed implements Seeder { + public async run(factory: Factory): Promise { + await userSeeder(factory, garrickOllivander) + } +} diff --git a/database/src/seeds/users/garrick-ollivander.ts b/database/src/seeds/users/garrick-ollivander.ts new file mode 100644 index 000000000..b04648dd5 --- /dev/null +++ b/database/src/seeds/users/garrick-ollivander.ts @@ -0,0 +1,24 @@ +export const garrickOllivander = { + email: 'garrick@ollivander.com', + firstName: 'Garrick', + lastName: 'Ollivander', + username: 'garrick', + description: `Curious ... curious ... +Renowned wandmaker Mr Ollivander owns the wand shop Ollivanders: Makers of Fine Wands Since 382 BC in Diagon Alley. His shop is widely considered the best place to purchase a wand.`, + password: BigInt('0'), + pubKey: null, + privKey: null, + emailHash: Buffer.from('91e358000e908146342789979d62a7255b2b88a71dad0c6a10e32af44be57886', 'hex'), + createdAt: new Date('2022-01-10T10:23:17'), + emailChecked: false, + passphraseShown: false, + language: 'en', + disabled: false, + groupId: 1, + publisherId: null, + passphrase: + 'human glide theory clump wish history other duty door fringe neck industry ostrich equal plate diesel tornado neck people antenna door category moon hen ', + mnemonicType: 2, + isAdmin: false, + addBalance: false, +} From 121b7530dc0fcaa5fb85d72a79a9814c399fcb38 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Jan 2022 09:22:51 +0100 Subject: [PATCH 16/22] fix: Override Existing Token in Response Header --- backend/src/server/plugins.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/src/server/plugins.ts b/backend/src/server/plugins.ts index 5436d595b..948f9ae1c 100644 --- a/backend/src/server/plugins.ts +++ b/backend/src/server/plugins.ts @@ -8,7 +8,11 @@ const plugins = [ willSendResponse(requestContext: any) { const { setHeaders = [] } = requestContext.context setHeaders.forEach(({ key, value }: { [key: string]: string }) => { - requestContext.response.http.headers.append(key, value) + if (requestContext.response.http.headers.get(key)) { + requestContext.response.http.headers.set(key, value) + } else { + requestContext.response.http.headers.append(key, value) + } }) return requestContext }, From fbf88d6d5bd4c6f3be754b3b7ffa53b97c89b255 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Jan 2022 09:56:45 +0100 Subject: [PATCH 17/22] fix: Pass Language to Admin Interface --- admin/src/graphql/verifyLogin.js | 1 + admin/src/main.js | 2 +- admin/src/router/guards.js | 3 ++- admin/src/router/guards.test.js | 24 +++++++++++++++++------- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/admin/src/graphql/verifyLogin.js b/admin/src/graphql/verifyLogin.js index 553557f3c..ea08bb5b1 100644 --- a/admin/src/graphql/verifyLogin.js +++ b/admin/src/graphql/verifyLogin.js @@ -7,6 +7,7 @@ export const verifyLogin = gql` lastName isAdmin id + language } } ` diff --git a/admin/src/main.js b/admin/src/main.js index 2743e0f9a..c0004beca 100644 --- a/admin/src/main.js +++ b/admin/src/main.js @@ -42,7 +42,7 @@ Vue.use(Toasted, { }, }) -addNavigationGuards(router, store, apolloProvider.defaultClient) +addNavigationGuards(router, store, apolloProvider.defaultClient, i18n) new Vue({ moment, diff --git a/admin/src/router/guards.js b/admin/src/router/guards.js index 4ed6c8516..dd61e8657 100644 --- a/admin/src/router/guards.js +++ b/admin/src/router/guards.js @@ -1,7 +1,7 @@ import { verifyLogin } from '../graphql/verifyLogin' import CONFIG from '../config' -const addNavigationGuards = (router, store, apollo) => { +const addNavigationGuards = (router, store, apollo, i18n) => { // store token on `authenticate` router.beforeEach(async (to, from, next) => { if (to.path === '/authenticate' && to.query && to.query.token) { @@ -14,6 +14,7 @@ const addNavigationGuards = (router, store, apollo) => { .then((result) => { const moderator = result.data.verifyLogin if (moderator.isAdmin) { + i18n.locale = moderator.language store.commit('moderator', moderator) next({ path: '/' }) } else { diff --git a/admin/src/router/guards.test.js b/admin/src/router/guards.test.js index cd5b33e68..da4dd5969 100644 --- a/admin/src/router/guards.test.js +++ b/admin/src/router/guards.test.js @@ -6,9 +6,11 @@ const apolloQueryMock = jest.fn().mockResolvedValue({ data: { verifyLogin: { isAdmin: true, + language: 'de', }, }, }) +const i18nLocaleMock = jest.fn() const store = { commit: storeCommitMock, @@ -21,7 +23,11 @@ const apollo = { query: apolloQueryMock, } -addNavigationGuards(router, store, apollo) +const i18n = { + locale: i18nLocaleMock, +} + +addNavigationGuards(router, store, apollo, i18n) describe('navigation guards', () => { beforeEach(() => { @@ -33,19 +39,23 @@ describe('navigation guards', () => { const next = jest.fn() describe('with valid token and as admin', () => { - beforeEach(() => { - navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next) + beforeEach(async () => { + await navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next) }) - it('commits the token to the store', async () => { + it('commits the token to the store', () => { expect(storeCommitMock).toBeCalledWith('token', 'valid-token') }) - it('commits the moderator to the store', () => { - expect(storeCommitMock).toBeCalledWith('moderator', { isAdmin: true }) + it.skip('sets the locale', () => { + expect(i18nLocaleMock).toBeCalledWith('de') }) - it('redirects to /', async () => { + it('commits the moderator to the store', () => { + expect(storeCommitMock).toBeCalledWith('moderator', { isAdmin: true, language: 'de' }) + }) + + it('redirects to /', () => { expect(next).toBeCalledWith({ path: '/' }) }) }) From 370994b35323c7f8b1879bd88844476643e27b12 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 10 Jan 2022 13:45:38 +0100 Subject: [PATCH 18/22] get the tests running --- .../components/CreationTransactionListFormular.spec.js | 4 +--- admin/src/components/UserTable.spec.js | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/admin/src/components/CreationTransactionListFormular.spec.js b/admin/src/components/CreationTransactionListFormular.spec.js index 9817d6b8f..1c7b81c25 100644 --- a/admin/src/components/CreationTransactionListFormular.spec.js +++ b/admin/src/components/CreationTransactionListFormular.spec.js @@ -58,9 +58,7 @@ const mocks = { query: apolloQueryMock, }, $toasted: { - global: { - error: toastedErrorMock, - }, + error: toastedErrorMock, }, } diff --git a/admin/src/components/UserTable.spec.js b/admin/src/components/UserTable.spec.js index 80bdf6047..e26a548cc 100644 --- a/admin/src/components/UserTable.spec.js +++ b/admin/src/components/UserTable.spec.js @@ -3,6 +3,9 @@ import UserTable from './UserTable.vue' const localVue = global.localVue +const apolloQueryMock = jest.fn() +apolloQueryMock.mockResolvedValue() + describe('UserTable', () => { let wrapper @@ -114,6 +117,12 @@ describe('UserTable', () => { }), } }), + $apollo: { + query: apolloQueryMock, + }, + $store: { + commit: jest.fn(), + }, } const Wrapper = (propsData) => { From a679b9042513a3630d0855a897faf4578afcec75 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Jan 2022 10:03:57 +0100 Subject: [PATCH 19/22] get the user table test up again --- admin/src/components/CreationTransactionListFormular.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/admin/src/components/CreationTransactionListFormular.spec.js b/admin/src/components/CreationTransactionListFormular.spec.js index 1c7b81c25..9817d6b8f 100644 --- a/admin/src/components/CreationTransactionListFormular.spec.js +++ b/admin/src/components/CreationTransactionListFormular.spec.js @@ -58,7 +58,9 @@ const mocks = { query: apolloQueryMock, }, $toasted: { - error: toastedErrorMock, + global: { + error: toastedErrorMock, + }, }, } From b244f31a533476221e38443e638a5f14f00eee10 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Jan 2022 10:06:40 +0100 Subject: [PATCH 20/22] catch language when comming back from admin interface --- frontend/src/main.js | 2 +- frontend/src/routes/guards.js | 3 ++- frontend/src/routes/guards.test.js | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/src/main.js b/frontend/src/main.js index edc9e575e..544dff66d 100755 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -28,7 +28,7 @@ Vue.toasted.register( loadAllRules(i18n) -addNavigationGuards(router, store, apolloProvider.defaultClient) +addNavigationGuards(router, store, apolloProvider.defaultClient, i18n) if (!store) { setTimeout( diff --git a/frontend/src/routes/guards.js b/frontend/src/routes/guards.js index 1838fa0fc..15d1eb5a1 100644 --- a/frontend/src/routes/guards.js +++ b/frontend/src/routes/guards.js @@ -1,6 +1,6 @@ import { verifyLogin } from '../graphql/queries' -const addNavigationGuards = (router, store, apollo) => { +const addNavigationGuards = (router, store, apollo, i18n) => { // handle publisherId router.beforeEach((to, from, next) => { const publisherId = to.query.pid @@ -21,6 +21,7 @@ const addNavigationGuards = (router, store, apollo) => { fetchPolicy: 'network-only', }) .then((result) => { + i18n.locale = result.data.verifyLogin.language store.dispatch('login', result.data.verifyLogin) next({ path: '/overview' }) }) diff --git a/frontend/src/routes/guards.test.js b/frontend/src/routes/guards.test.js index fa9f60f56..d4d2869d4 100644 --- a/frontend/src/routes/guards.test.js +++ b/frontend/src/routes/guards.test.js @@ -23,7 +23,11 @@ const apollo = { query: apolloQueryMock, } -addNavigationGuards(router, store, apollo) +const i18n = { + locale: jest.fn(), +} + +addNavigationGuards(router, store, apollo, i18n) describe('navigation guards', () => { beforeEach(() => { From dc8d838e004571009cbbd466eaeaabf1c0fb603d Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Jan 2022 10:07:25 +0100 Subject: [PATCH 21/22] coverage admin interface 77% --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15a736630..51f8e49b0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -470,7 +470,7 @@ jobs: report_name: Coverage Admin Interface type: lcov result_path: ./coverage/lcov.info - min_coverage: 76 + min_coverage: 77 token: ${{ github.token }} ############################################################################## From d157240d3b158e57f62365a009f4036d9bb9b657 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Jan 2022 12:17:08 +0100 Subject: [PATCH 22/22] remove null definitions --- database/src/interface/UserContext.ts | 8 ++++---- database/src/interface/UserInterface.ts | 6 +++--- database/src/seeds/users/bibi-bloxberg.ts | 1 - database/src/seeds/users/bob-baumeister.ts | 1 - database/src/seeds/users/garrick-ollivander.ts | 3 --- database/src/seeds/users/peter-lustig.ts | 1 - database/src/seeds/users/raeuber-hotzenplotz.ts | 1 - 7 files changed, 7 insertions(+), 14 deletions(-) diff --git a/database/src/interface/UserContext.ts b/database/src/interface/UserContext.ts index 87cc70af6..eb4323aee 100644 --- a/database/src/interface/UserContext.ts +++ b/database/src/interface/UserContext.ts @@ -1,5 +1,5 @@ export interface UserContext { - pubkey?: Buffer | null + pubkey?: Buffer email?: string firstName?: string lastName?: string @@ -14,8 +14,8 @@ export interface LoginUserContext { username?: string description?: string password?: BigInt - pubKey?: Buffer | null - privKey?: Buffer | null + pubKey?: Buffer + privKey?: Buffer emailHash?: Buffer createdAt?: Date emailChecked?: boolean @@ -23,7 +23,7 @@ export interface LoginUserContext { language?: string disabled?: boolean groupId?: number - publisherId?: number | null + publisherId?: number } export interface LoginUserBackupContext { diff --git a/database/src/interface/UserInterface.ts b/database/src/interface/UserInterface.ts index e68c23ec3..63804af6b 100644 --- a/database/src/interface/UserInterface.ts +++ b/database/src/interface/UserInterface.ts @@ -6,8 +6,8 @@ export interface UserInterface { username?: string description?: string password?: BigInt - pubKey?: Buffer | null - privKey?: Buffer | null + pubKey?: Buffer + privKey?: Buffer emailHash?: Buffer createdAt?: Date emailChecked?: boolean @@ -15,7 +15,7 @@ export interface UserInterface { language?: string disabled?: boolean groupId?: number - publisherId?: number | null + publisherId?: number // from login user backup passphrase?: string mnemonicType?: number diff --git a/database/src/seeds/users/bibi-bloxberg.ts b/database/src/seeds/users/bibi-bloxberg.ts index 30ad4eb4c..221349cb7 100644 --- a/database/src/seeds/users/bibi-bloxberg.ts +++ b/database/src/seeds/users/bibi-bloxberg.ts @@ -17,7 +17,6 @@ export const bibiBloxberg = { language: 'de', disabled: false, groupId: 1, - publisherId: null, passphrase: 'knife normal level all hurdle crucial color avoid warrior stadium road bachelor affair topple hawk pottery right afford immune two ceiling budget glance hour ', mnemonicType: 2, diff --git a/database/src/seeds/users/bob-baumeister.ts b/database/src/seeds/users/bob-baumeister.ts index a6933d7c1..013636079 100644 --- a/database/src/seeds/users/bob-baumeister.ts +++ b/database/src/seeds/users/bob-baumeister.ts @@ -17,7 +17,6 @@ export const bobBaumeister = { language: 'de', disabled: false, groupId: 1, - publisherId: null, passphrase: 'detail master source effort unable waste tilt flush domain orchard art truck hint barrel response gate impose peanut secret merry three uncle wink resource ', mnemonicType: 2, diff --git a/database/src/seeds/users/garrick-ollivander.ts b/database/src/seeds/users/garrick-ollivander.ts index b04648dd5..1c7bbb9fc 100644 --- a/database/src/seeds/users/garrick-ollivander.ts +++ b/database/src/seeds/users/garrick-ollivander.ts @@ -6,8 +6,6 @@ export const garrickOllivander = { description: `Curious ... curious ... Renowned wandmaker Mr Ollivander owns the wand shop Ollivanders: Makers of Fine Wands Since 382 BC in Diagon Alley. His shop is widely considered the best place to purchase a wand.`, password: BigInt('0'), - pubKey: null, - privKey: null, emailHash: Buffer.from('91e358000e908146342789979d62a7255b2b88a71dad0c6a10e32af44be57886', 'hex'), createdAt: new Date('2022-01-10T10:23:17'), emailChecked: false, @@ -15,7 +13,6 @@ Renowned wandmaker Mr Ollivander owns the wand shop Ollivanders: Makers of Fine language: 'en', disabled: false, groupId: 1, - publisherId: null, passphrase: 'human glide theory clump wish history other duty door fringe neck industry ostrich equal plate diesel tornado neck people antenna door category moon hen ', mnemonicType: 2, diff --git a/database/src/seeds/users/peter-lustig.ts b/database/src/seeds/users/peter-lustig.ts index 63caf55f6..c96b28a65 100644 --- a/database/src/seeds/users/peter-lustig.ts +++ b/database/src/seeds/users/peter-lustig.ts @@ -17,7 +17,6 @@ export const peterLustig = { language: 'de', disabled: false, groupId: 1, - publisherId: null, passphrase: 'okay property choice naive calm present weird increase stuff royal vibrant frame attend wood one else tribe pull hedgehog woman kitchen hawk snack smart ', mnemonicType: 2, diff --git a/database/src/seeds/users/raeuber-hotzenplotz.ts b/database/src/seeds/users/raeuber-hotzenplotz.ts index eb2118af5..c1f31b490 100644 --- a/database/src/seeds/users/raeuber-hotzenplotz.ts +++ b/database/src/seeds/users/raeuber-hotzenplotz.ts @@ -17,7 +17,6 @@ export const raeuberHotzenplotz = { language: 'de', disabled: false, groupId: 1, - publisherId: null, passphrase: 'gospel trip tenant mouse spider skill auto curious man video chief response same little over expire drum display fancy clinic keen throw urge basket ', mnemonicType: 2,