From 6c88713f3430e9a406c478fe9738d3793533a8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 20 Sep 2022 16:20:52 +0200 Subject: [PATCH 01/13] start inserting logger.addContext for userid --- backend/src/graphql/resolver/UserResolver.ts | 6 +++++- backend/src/server/createServer.ts | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index f2fd048fc..e642117df 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -277,6 +277,8 @@ export class UserResolver { logger.error(`User with email=${email} does not exist`) throw new Error('No user with this credentials') }) + logger.addContext('user', dbUser.id) + logger.info(`validation of user still ongoing...`) if (dbUser.deletedAt) { logger.error('The User was permanently deleted in database.') throw new Error('This user was permanently deleted. Contact support for questions.') @@ -303,7 +305,7 @@ export class UserResolver { } // add pubKey in logger-context for layout-pattern X{user} to print it in each logging message logger.addContext('user', dbUser.id) - logger.debug('login credentials valid...') + logger.debug('validation of login credentials successful...') const user = new User(dbUser, await getUserCreation(dbUser.id)) logger.debug('user=' + user) @@ -348,6 +350,7 @@ export class UserResolver { @Args() { email, firstName, lastName, language, publisherId, redeemCode = null }: CreateUserArgs, ): Promise { + logger.addContext('user', 'unknown') logger.info( `createUser(email=${email}, firstName=${firstName}, lastName=${lastName}, language=${language}, publisherId=${publisherId}, redeemCode =${redeemCode})`, ) @@ -483,6 +486,7 @@ export class UserResolver { } await queryRunner.commitTransaction() + logger.addContext('user', dbUser.id) } catch (e) { logger.error(`error during create user with ${e}`) await queryRunner.rollbackTransaction() diff --git a/backend/src/server/createServer.ts b/backend/src/server/createServer.ts index a0b294281..62ea93bf0 100644 --- a/backend/src/server/createServer.ts +++ b/backend/src/server/createServer.ts @@ -35,6 +35,7 @@ const createServer = async ( context: any = serverContext, logger: Logger = apolloLogger, ): Promise => { + logger.addContext('user', 'unknown') logger.debug('createServer...') // open mysql connection From 542b069aa90b5b54cc237b8d906118350694651c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 21 Sep 2022 04:12:48 +0200 Subject: [PATCH 02/13] reconfig now with rollover feature and userid in logevent-message --- backend/log4js-config.json | 57 +++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/backend/log4js-config.json b/backend/log4js-config.json index 848a4fa79..a096713ec 100644 --- a/backend/log4js-config.json +++ b/backend/log4js-config.json @@ -5,41 +5,66 @@ { "type": "dateFile", "filename": "../logs/backend/access.log", - "pattern": "%d{ISO8601} %p %c %X{user} %f:%l %m", + "pattern": "yyyy-MM-dd", + "layout": + { + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + }, "keepFileExt" : true, - "fileNameSep" : "_" + "fileNameSep" : "_", + "numBackups" : 30 }, "apollo": { "type": "dateFile", "filename": "../logs/backend/apollo.log", - "pattern": "%d{ISO8601} %p %c %m", + "pattern": "yyyy-MM-dd", + "layout": + { + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + }, "keepFileExt" : true, - "fileNameSep" : "_" + "fileNameSep" : "_", + "numBackups" : 30 }, "backend": { "type": "dateFile", "filename": "../logs/backend/backend.log", - "pattern": "%d{ISO8601} %p %c %X{user} %f:%l %m", + "pattern": "yyyy-MM-dd", + "layout": + { + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + }, "keepFileExt" : true, - "fileNameSep" : "_" + "fileNameSep" : "_", + "numBackups" : 30 }, "klicktipp": { "type": "dateFile", "filename": "../logs/backend/klicktipp.log", - "pattern": "%d{ISO8601} %p %c %X{user} %f:%l %m", + "pattern": "yyyy-MM-dd", + "layout": + { + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + }, "keepFileExt" : true, - "fileNameSep" : "_" + "fileNameSep" : "_", + "numBackups" : 30 }, "errorFile": { "type": "dateFile", "filename": "../logs/backend/errors.log", - "pattern": "%d{ISO8601} %p %c %X{user} %f:%l %m", + "pattern": "yyyy-MM-dd", + "layout": + { + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + }, "keepFileExt" : true, - "fileNameSep" : "_" + "fileNameSep" : "_", + "numBackups" : 30 }, "errors": { @@ -52,7 +77,7 @@ "type": "stdout", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c %X{user} %f:%l %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" } }, "apolloOut": @@ -60,7 +85,7 @@ "type": "stdout", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" } } }, @@ -74,7 +99,7 @@ "errors" ], "level": "debug", - "enableCallStack": true + "enableCallStack": false }, "apollo": { @@ -85,7 +110,7 @@ "errors" ], "level": "debug", - "enableCallStack": true + "enableCallStack": false }, "backend": { @@ -96,7 +121,7 @@ "errors" ], "level": "debug", - "enableCallStack": true + "enableCallStack": false }, "klicktipp": { @@ -107,7 +132,7 @@ "errors" ], "level": "debug", - "enableCallStack": true + "enableCallStack": false }, "http": { From 3dd66b4527cc37953c2fa6968153b40dc2b10084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 23 Sep 2022 00:31:33 +0200 Subject: [PATCH 03/13] small changes in log-pattern Merge remote-tracking branch 'origin/master' into 2220-feature-reconfigure-log4js --- backend/log4js-config.json | 22 ++++++++++---------- backend/src/graphql/resolver/UserResolver.ts | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/backend/log4js-config.json b/backend/log4js-config.json index a096713ec..e595e7c52 100644 --- a/backend/log4js-config.json +++ b/backend/log4js-config.json @@ -8,7 +8,7 @@ "pattern": "yyyy-MM-dd", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" }, "keepFileExt" : true, "fileNameSep" : "_", @@ -21,7 +21,7 @@ "pattern": "yyyy-MM-dd", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" }, "keepFileExt" : true, "fileNameSep" : "_", @@ -34,7 +34,7 @@ "pattern": "yyyy-MM-dd", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" }, "keepFileExt" : true, "fileNameSep" : "_", @@ -47,7 +47,7 @@ "pattern": "yyyy-MM-dd", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" }, "keepFileExt" : true, "fileNameSep" : "_", @@ -60,7 +60,7 @@ "pattern": "yyyy-MM-dd", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" }, "keepFileExt" : true, "fileNameSep" : "_", @@ -77,7 +77,7 @@ "type": "stdout", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" } }, "apolloOut": @@ -85,7 +85,7 @@ "type": "stdout", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" } } }, @@ -99,7 +99,7 @@ "errors" ], "level": "debug", - "enableCallStack": false + "enableCallStack": true }, "apollo": { @@ -110,7 +110,7 @@ "errors" ], "level": "debug", - "enableCallStack": false + "enableCallStack": true }, "backend": { @@ -121,7 +121,7 @@ "errors" ], "level": "debug", - "enableCallStack": false + "enableCallStack": true }, "klicktipp": { @@ -132,7 +132,7 @@ "errors" ], "level": "debug", - "enableCallStack": false + "enableCallStack": true }, "http": { diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 647bf4fc1..1f05a5162 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -510,6 +510,7 @@ export class UserResolver { @Authorized([RIGHTS.SEND_RESET_PASSWORD_EMAIL]) @Mutation(() => Boolean) async forgotPassword(@Arg('email') email: string): Promise { + logger.addContext('user', 'unknown') logger.info(`forgotPassword(${email})...`) email = email.trim().toLowerCase() const user = await DbUser.findOne({ email }) From 55453b217b35da34c3966ec9c5e696e1b4d6eda0 Mon Sep 17 00:00:00 2001 From: mahula Date: Thu, 29 Sep 2022 12:37:30 +0200 Subject: [PATCH 04/13] admin frontend: merge components - functionality of slot compoments IsModerator and IsNotModerator is added to component ContributionMessagesListItem - the slot components are removed, since not required anymore --- .../slots/ContributionMessagesListItem.vue | 37 +++++++++++++++---- .../slots/IsModerator.vue | 37 ------------------- .../slots/IsNotModerator.vue | 34 ----------------- 3 files changed, 29 insertions(+), 79 deletions(-) delete mode 100644 admin/src/components/ContributionMessages/slots/IsModerator.vue delete mode 100644 admin/src/components/ContributionMessages/slots/IsNotModerator.vue diff --git a/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.vue b/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.vue index fa5bdd940..b0630d0b4 100644 --- a/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.vue +++ b/admin/src/components/ContributionMessages/slots/ContributionMessagesListItem.vue @@ -1,19 +1,24 @@ + diff --git a/admin/src/components/ContributionMessages/slots/IsModerator.vue b/admin/src/components/ContributionMessages/slots/IsModerator.vue deleted file mode 100644 index 0224e042f..000000000 --- a/admin/src/components/ContributionMessages/slots/IsModerator.vue +++ /dev/null @@ -1,37 +0,0 @@ - - - diff --git a/admin/src/components/ContributionMessages/slots/IsNotModerator.vue b/admin/src/components/ContributionMessages/slots/IsNotModerator.vue deleted file mode 100644 index 64946c557..000000000 --- a/admin/src/components/ContributionMessages/slots/IsNotModerator.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - From 899b74d60a4b83317fc4c1e8fbcef5810e3d1cb8 Mon Sep 17 00:00:00 2001 From: mahula Date: Thu, 29 Sep 2022 12:39:21 +0200 Subject: [PATCH 05/13] wallet frontend: merge components - functionality of slot compoments IsModerator and IsNotModerator is added to component ContributionMessagesListItem - the slot components are removed, since not required anymore --- .../ContributionMessagesListItem.vue | 39 ++++++++++++++----- .../slots/IsModerator.vue | 34 ---------------- .../slots/IsNotModerator.vue | 36 ----------------- 3 files changed, 30 insertions(+), 79 deletions(-) delete mode 100644 frontend/src/components/ContributionMessages/slots/IsModerator.vue delete mode 100644 frontend/src/components/ContributionMessages/slots/IsNotModerator.vue diff --git a/frontend/src/components/ContributionMessages/ContributionMessagesListItem.vue b/frontend/src/components/ContributionMessages/ContributionMessagesListItem.vue index 5fde8f825..85d371250 100644 --- a/frontend/src/components/ContributionMessages/ContributionMessagesListItem.vue +++ b/frontend/src/components/ContributionMessages/ContributionMessagesListItem.vue @@ -1,19 +1,24 @@ - + diff --git a/frontend/src/components/ContributionMessages/slots/IsModerator.vue b/frontend/src/components/ContributionMessages/slots/IsModerator.vue deleted file mode 100644 index 343b92d97..000000000 --- a/frontend/src/components/ContributionMessages/slots/IsModerator.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - diff --git a/frontend/src/components/ContributionMessages/slots/IsNotModerator.vue b/frontend/src/components/ContributionMessages/slots/IsNotModerator.vue deleted file mode 100644 index 8efca7270..000000000 --- a/frontend/src/components/ContributionMessages/slots/IsNotModerator.vue +++ /dev/null @@ -1,36 +0,0 @@ - - - From 14aa976e5a1c1ce19e6807a250f0dba54bfcfa3a Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 4 Oct 2022 12:11:23 +0200 Subject: [PATCH 06/13] wallet frontend: adapt unit tests for merged components - add tests to ContributionMessagesListItem.spec.js - remove slots tests --- .../ContributionMessagesListItem.spec.js | 127 +++++++++++++++--- .../ContributionMessagesListItem.vue | 4 +- .../slots/IsModerator.spec.js | 49 ------- .../slots/IsNotModerator.spec.js | 49 ------- 4 files changed, 110 insertions(+), 119 deletions(-) delete mode 100644 frontend/src/components/ContributionMessages/slots/IsModerator.spec.js delete mode 100644 frontend/src/components/ContributionMessages/slots/IsNotModerator.spec.js diff --git a/frontend/src/components/ContributionMessages/ContributionMessagesListItem.spec.js b/frontend/src/components/ContributionMessages/ContributionMessagesListItem.spec.js index b9f6f0029..74cab882d 100644 --- a/frontend/src/components/ContributionMessages/ContributionMessagesListItem.spec.js +++ b/frontend/src/components/ContributionMessages/ContributionMessagesListItem.spec.js @@ -1,29 +1,29 @@ import { mount } from '@vue/test-utils' import ContributionMessagesList from './ContributionMessagesList.vue' +import ContributionMessagesListItem from './ContributionMessagesListItem.vue' const localVue = global.localVue +let wrapper + +const mocks = { + $t: jest.fn((t) => t), + $d: jest.fn((d) => d), + $store: { + state: { + firstName: 'Peter', + lastName: 'Lustig', + }, + }, +} describe('ContributionMessagesList', () => { - let wrapper - - const mocks = { - $t: jest.fn((t) => t), - $d: jest.fn((d) => d), - $store: { - state: { - firstName: 'Peter', - lastName: 'Lustig', - }, - }, - } - const propsData = { contributionId: 42, - state: 'PENDING0', + state: 'PENDING', messages: [ { id: 111, - message: 'asd asda sda sda', + message: 'Lorem ipsum?', createdAt: '2022-08-29T12:23:27.000Z', updatedAt: null, type: 'DIALOG', @@ -32,10 +32,21 @@ describe('ContributionMessagesList', () => { userId: 107, __typename: 'ContributionMessage', }, + { + id: 113, + message: 'Asda sdad ad asdasd, das Ass das Das. ', + createdAt: '2022-08-29T12:25:34.000Z', + updatedAt: null, + type: 'DIALOG', + userFirstName: 'Bibi', + userLastName: 'Bloxberg', + userId: 108, + __typename: 'ContributionMessage', + }, ], } - const Wrapper = () => { + const ListWrapper = () => { return mount(ContributionMessagesList, { localVue, mocks, @@ -45,11 +56,89 @@ describe('ContributionMessagesList', () => { describe('mount', () => { beforeEach(() => { - wrapper = Wrapper() + wrapper = ListWrapper() }) - it('has a DIV .contribution-messages-list-item', () => { - expect(wrapper.find('div.contribution-messages-list-item').exists()).toBe(true) + it('has two DIV .contribution-messages-list-item elements', () => { + expect(wrapper.findAll('div.contribution-messages-list-item').length).toBe(2) + }) + }) +}) + +describe('ContributionMessagesListItem', () => { + describe('if message author has moderator role', () => { + const propsData = { + message: { + id: 113, + message: 'Asda sdad ad asdasd, das Ass das Das. ', + createdAt: '2022-08-29T12:25:34.000Z', + updatedAt: null, + type: 'DIALOG', + userFirstName: 'Bibi', + userLastName: 'Bloxberg', + userId: 108, + __typename: 'ContributionMessage', + }, + } + + const ItemWrapper = () => { + return mount(ContributionMessagesListItem, { + localVue, + mocks, + propsData, + }) + } + + describe('mount', () => { + beforeAll(() => { + wrapper = ItemWrapper() + }) + + it('has a DIV .is-moderator.text-left', () => { + expect(wrapper.find('div.is-moderator.text-left').exists()).toBe(true) + }) + + it('props.message.default', () => { + expect(wrapper.vm.$options.props.message.default.call()).toEqual({}) + }) + }) + }) + + describe('if message author does not have moderator role', () => { + const propsData = { + message: { + id: 111, + message: 'Lorem ipsum?', + createdAt: '2022-08-29T12:23:27.000Z', + updatedAt: null, + type: 'DIALOG', + userFirstName: 'Peter', + userLastName: 'Lustig', + userId: 107, + __typename: 'ContributionMessage', + }, + } + + const ModeratorItemWrapper = () => { + return mount(ContributionMessagesListItem, { + localVue, + mocks, + propsData, + }) + } + + describe('mount', () => { + beforeAll(() => { + wrapper = ModeratorItemWrapper() + }) + + it('has a DIV .is-not-moderator.text-right', () => { + expect(wrapper.find('div.is-not-moderator.text-right').exists()).toBe(true) + }) + + it('props.message.default', () => { + expect(wrapper.vm.$options.props.message.default.call()).toEqual({}) + }) }) }) }) diff --git a/frontend/src/components/ContributionMessages/ContributionMessagesListItem.vue b/frontend/src/components/ContributionMessages/ContributionMessagesListItem.vue index 85d371250..e2bc50be6 100644 --- a/frontend/src/components/ContributionMessages/ContributionMessagesListItem.vue +++ b/frontend/src/components/ContributionMessages/ContributionMessagesListItem.vue @@ -44,7 +44,7 @@ export default {