From 7e9a82d7cfcca0f9f8e09d082476aec5c4777060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Thu, 15 Sep 2022 15:35:00 +0200 Subject: [PATCH 01/26] Update install.sh --- deployment/bare_metal/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/install.sh b/deployment/bare_metal/install.sh index 0fcf6d847..90b647f0e 100755 --- a/deployment/bare_metal/install.sh +++ b/deployment/bare_metal/install.sh @@ -90,7 +90,7 @@ sudo certbot # Install logrotate sudo apt-get install -y logrotate envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $SCRIPT_DIR/logrotate/gradido.conf.template > $SCRIPT_DIR/logrotate/gradido.conf -sudo mv $SCRIPT_DIR/logrotate/gradido.conf /etc/logrotate.d/gradido.conf +sudo mv $SCRIPT_DIR/logrotate/gradido.conf.template /etc/logrotate.d/gradido.conf sudo chown root:root /etc/logrotate.d/gradido.conf # Install mysql autobackup @@ -133,4 +133,4 @@ envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $PROJECT_ROOT/admin/.env.te # Start gradido # Note: on first startup some errors will occur - nothing serious -./start.sh \ No newline at end of file +./start.sh From ef8cbacb6d248857c711de922f716ece5fd41e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Thu, 15 Sep 2022 15:42:39 +0200 Subject: [PATCH 02/26] Update install.sh --- deployment/bare_metal/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/install.sh b/deployment/bare_metal/install.sh index 90b647f0e..0bcea653b 100755 --- a/deployment/bare_metal/install.sh +++ b/deployment/bare_metal/install.sh @@ -90,7 +90,7 @@ sudo certbot # Install logrotate sudo apt-get install -y logrotate envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $SCRIPT_DIR/logrotate/gradido.conf.template > $SCRIPT_DIR/logrotate/gradido.conf -sudo mv $SCRIPT_DIR/logrotate/gradido.conf.template /etc/logrotate.d/gradido.conf +sudo cp $SCRIPT_DIR/logrotate/gradido.conf.template /etc/logrotate.d/gradido.conf sudo chown root:root /etc/logrotate.d/gradido.conf # Install mysql autobackup From 03672bef255551ea730807c05cb33390457d7988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Thu, 15 Sep 2022 16:27:22 +0200 Subject: [PATCH 03/26] Update install.sh --- deployment/bare_metal/install.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/deployment/bare_metal/install.sh b/deployment/bare_metal/install.sh index 0bcea653b..01b1e7a0b 100755 --- a/deployment/bare_metal/install.sh +++ b/deployment/bare_metal/install.sh @@ -4,6 +4,12 @@ # How to do this is described in detail in [setup.md](./setup.md) # Find current directory & configure paths +## For manualy use in terminal +## set -o allexport +## SCRIPT_DIR=$(pwd) +## PROJECT_ROOT=$SCRIPT_DIR/../.. +## set +o allexport +# Use here in script set -o allexport SCRIPT_PATH=$(realpath $0) SCRIPT_DIR=$(dirname $SCRIPT_PATH) From 9624a79881596f3b7c4c47ef48181f0c9672c14c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Thu, 15 Sep 2022 17:22:48 +0200 Subject: [PATCH 04/26] Update setup.md --- deployment/bare_metal/setup.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/deployment/bare_metal/setup.md b/deployment/bare_metal/setup.md index f43a3d655..7c1154862 100644 --- a/deployment/bare_metal/setup.md +++ b/deployment/bare_metal/setup.md @@ -95,5 +95,17 @@ > cp .env.dist .env > nano .env >> Adjust values accordingly + # TODO the install.sh is not yet ready to run directly - consider to use it as pattern to do it manually -> ./install.sh + +!!! ATTENTION: + +- NGINX: + - Be aware to set the values for NGINX in the following files according to your needs before you install NGINX! + - `./nginx/sites-available/gradido.conf` + - `./nginx/sites-available/update-page.conf` +- Commands in `./install.sh`: + - The commands for setting the paths in the used env variables are not working directly in the terminal, consider the out commented commands for this purpose, see below. + +Follow the commands in `./install.sh`. + From c08aac58a9ca13c723a39f8489fc67f4cfcbe25f Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 22 Sep 2022 11:44:30 +0200 Subject: [PATCH 05/26] events and half log tests --- .../resolver/ContributionResolver.test.ts | 24 ++++++++++++++++++- .../graphql/resolver/ContributionResolver.ts | 18 ++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 20f11ff9a..b91d3213b 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -16,6 +16,9 @@ import { userFactory } from '@/seeds/factory/user' import { creationFactory } from '@/seeds/factory/creation' import { creations } from '@/seeds/creation/index' import { peterLustig } from '@/seeds/users/peter-lustig' +import { EventProtocol } from '@entity/EventProtocol' +import { EventProtocolType } from '@/event/EventProtocolType' +import { logger } from '@test/testSetup' let mutate: any, query: any, con: any let testEnv: any @@ -35,6 +38,8 @@ afterAll(async () => { }) describe('ContributionResolver', () => { + let bibi: any + describe('createContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { @@ -54,7 +59,7 @@ describe('ContributionResolver', () => { describe('authenticated with valid user', () => { beforeAll(async () => { await userFactory(testEnv, bibiBloxberg) - await query({ + bibi = await query({ query: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) @@ -84,6 +89,10 @@ describe('ContributionResolver', () => { ) }) + it('logs the error found', () => { + expect(logger.error).toBeCalledWith(`memo text is too short: memo.length=4 < (5)`) + }) + it('throws error when memo length greater than 255 chars', async () => { const date = new Date() await expect( @@ -102,6 +111,10 @@ describe('ContributionResolver', () => { ) }) + it('logs the error found', () => { + expect(logger.error).toBeCalledWith(`memo text is too long: memo.length=259 > (255)`) + }) + it('throws error when creationDate not-valid', async () => { await expect( mutate({ @@ -165,6 +178,15 @@ describe('ContributionResolver', () => { }), ) }) + + it('stores the create contribution event in the database', async () => { + await expect(EventProtocol.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventProtocolType.CONTRIBUTION_CREATE, + userId: bibi.data.login.id, + }), + ) + }) }) }) }) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index fc93880f1..b788384f1 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -13,6 +13,8 @@ import { Contribution, ContributionListResult } from '@model/Contribution' import { UnconfirmedContribution } from '@model/UnconfirmedContribution' import { validateContribution, getUserCreation, updateCreations } from './util/creations' import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' +import { Event, EventConfirmationEmail, EventContributionCreate } from '@/event/Event' +import { eventProtocol } from '@/event/EventProtocolEmitter' @Resolver() export class ContributionResolver { @@ -23,15 +25,17 @@ export class ContributionResolver { @Ctx() context: Context, ): Promise { if (memo.length > MEMO_MAX_CHARS) { - logger.error(`memo text is too long: memo.length=${memo.length} > (${MEMO_MAX_CHARS}`) + logger.error(`memo text is too long: memo.length=${memo.length} > (${MEMO_MAX_CHARS})`) throw new Error(`memo text is too long (${MEMO_MAX_CHARS} characters maximum)`) } if (memo.length < MEMO_MIN_CHARS) { - logger.error(`memo text is too short: memo.length=${memo.length} < (${MEMO_MIN_CHARS}`) + logger.error(`memo text is too short: memo.length=${memo.length} < (${MEMO_MIN_CHARS})`) throw new Error(`memo text is too short (${MEMO_MIN_CHARS} characters minimum)`) } + const event = new Event() + const user = getUser(context) const creations = await getUserCreation(user.id) logger.trace('creations', creations) @@ -49,6 +53,11 @@ export class ContributionResolver { logger.trace('contribution to save', contribution) await dbContribution.save(contribution) + + const eventCreateContribution = new EventContributionCreate() + eventCreateContribution.userId = user.id + await eventProtocol.writeEvent(event.setEventContributionCreate(eventCreateContribution)) + return new UnconfirmedContribution(contribution, user, creations) } @@ -61,12 +70,15 @@ export class ContributionResolver { const user = getUser(context) const contribution = await dbContribution.findOne(id) if (!contribution) { + logger.error('Contribution not found for given id') throw new Error('Contribution not found for given id.') } if (contribution.userId !== user.id) { + logger.error('Can not delete contribution of another user') throw new Error('Can not delete contribution of another user') } if (contribution.confirmedAt) { + logger.error('A confirmed contribution can not be deleted') throw new Error('A confirmed contribution can not be deleted') } contribution.contributionStatus = ContributionStatus.DELETED @@ -154,9 +166,11 @@ export class ContributionResolver { where: { id: contributionId, confirmedAt: IsNull() }, }) if (!contributionToUpdate) { + logger.error('No contribution found for given id') throw new Error('No contribution found to given id.') } if (contributionToUpdate.userId !== user.id) { + logger.error('user of the pending contribution and send user does not correspond') throw new Error('user of the pending contribution and send user does not correspond') } From 0176131c39db97c81c208978957ae0e165aabe29 Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 22 Sep 2022 12:07:12 +0200 Subject: [PATCH 06/26] errors are now logged, and events are checked --- .../resolver/ContributionResolver.test.ts | 58 ++++++++++++++++++- .../graphql/resolver/ContributionResolver.ts | 4 +- .../src/graphql/resolver/util/creations.ts | 4 ++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index b91d3213b..d08396285 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -134,6 +134,12 @@ describe('ContributionResolver', () => { ) }) + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + 'No information for available creations for the given date', + ) + }) + it('throws error when creationDate 3 month behind', async () => { const date = new Date() await expect( @@ -153,6 +159,12 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + 'No information for available creations for the given date', + ) + }) }) describe('valid input', () => { @@ -369,6 +381,10 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('No contribution found to given id') + }) }) describe('Memo length smaller than 5 chars', () => { @@ -390,6 +406,10 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('memo text is too short: memo.length=4 < (5)') + }) }) describe('Memo length greater than 255 chars', () => { @@ -411,6 +431,10 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('memo text is too long: memo.length=259 > (255)') + }) }) describe('wrong user tries to update the contribution', () => { @@ -442,6 +466,12 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + 'user of the pending contribution and send user does not correspond', + ) + }) }) describe('admin tries to update a user contribution', () => { @@ -463,6 +493,8 @@ describe('ContributionResolver', () => { }), ) }) + + // TODO check that the error is logged (need to modify AdminResolver, avoid conflicts) }) describe('update too much so that the limit is exceeded', () => { @@ -494,6 +526,12 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + 'The amount (1019 GDD) to be created exceeds the amount (1000 GDD) still available for this month.', + ) + }) }) describe('update creation to a date that is older than 3 months', () => { @@ -517,6 +555,12 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + 'No information for available creations for the given date', + ) + }) }) describe('valid input', () => { @@ -686,9 +730,13 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('Contribution not found for given id') + }) }) - describe('other user sends a deleteContribtuion', () => { + describe('other user sends a deleteContribution', () => { it('returns an error', async () => { await query({ query: login, @@ -707,6 +755,10 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('Can not delete contribution of another user') + }) }) describe('User deletes own contribution', () => { @@ -751,6 +803,10 @@ describe('ContributionResolver', () => { }), ) }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('A confirmed contribution can not be deleted') + }) }) }) }) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index b788384f1..3c33a4e0f 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -13,7 +13,7 @@ import { Contribution, ContributionListResult } from '@model/Contribution' import { UnconfirmedContribution } from '@model/UnconfirmedContribution' import { validateContribution, getUserCreation, updateCreations } from './util/creations' import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' -import { Event, EventConfirmationEmail, EventContributionCreate } from '@/event/Event' +import { Event, EventContributionCreate } from '@/event/Event' import { eventProtocol } from '@/event/EventProtocolEmitter' @Resolver() @@ -166,7 +166,7 @@ export class ContributionResolver { where: { id: contributionId, confirmedAt: IsNull() }, }) if (!contributionToUpdate) { - logger.error('No contribution found for given id') + logger.error('No contribution found to given id') throw new Error('No contribution found to given id.') } if (contributionToUpdate.userId !== user.id) { diff --git a/backend/src/graphql/resolver/util/creations.ts b/backend/src/graphql/resolver/util/creations.ts index ad15ebec6..afbadead1 100644 --- a/backend/src/graphql/resolver/util/creations.ts +++ b/backend/src/graphql/resolver/util/creations.ts @@ -19,10 +19,14 @@ export const validateContribution = ( const index = getCreationIndex(creationDate.getMonth()) if (index < 0) { + logger.error('No information for available creations for the given date') throw new Error('No information for available creations for the given date') } if (amount.greaterThan(creations[index].toString())) { + logger.error( + `The amount (${amount} GDD) to be created exceeds the amount (${creations[index]} GDD) still available for this month.`, + ) throw new Error( `The amount (${amount} GDD) to be created exceeds the amount (${creations[index]} GDD) still available for this month.`, ) From 79f7ebce57d2179d1b365de8dfb6f6118fde103f Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 22 Sep 2022 17:35:41 +0200 Subject: [PATCH 07/26] updated event working, deletion is not working properly (deeper than the event itself) --- backend/src/event/Event.ts | 16 ++++++++++++ backend/src/event/EventProtocolType.ts | 2 ++ .../resolver/ContributionResolver.test.ts | 21 ++++++++++++++++ .../graphql/resolver/ContributionResolver.ts | 25 ++++++++++++++++++- 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 6f07661f1..40eb333fd 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -48,6 +48,8 @@ export class EventTransactionCreation extends EventBasicUserId { export class EventTransactionReceive extends EventBasicTx {} export class EventTransactionReceiveRedeem extends EventBasicTx {} export class EventContributionCreate extends EventBasicCt {} +export class EventContributionDelete extends EventBasicCt {} +export class EventContributionUpdate extends EventBasicCt {} export class EventContributionConfirm extends EventBasicCt { xUserId: number xCommunityId: number @@ -206,6 +208,20 @@ export class Event { return this } + public setEventContributionDelete(ev: EventContributionDelete): Event { + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + this.type = EventProtocolType.CONTRIBUTION_DELETE + + return this + } + + public setEventContributionUpdate(ev: EventContributionUpdate): Event { + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + this.type = EventProtocolType.CONTRIBUTION_UPDATE + + return this + } + public setEventContributionConfirm(ev: EventContributionConfirm): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) if (ev.xUserId) this.xUserId = ev.xUserId diff --git a/backend/src/event/EventProtocolType.ts b/backend/src/event/EventProtocolType.ts index 0f61f787a..c0fc1bb8e 100644 --- a/backend/src/event/EventProtocolType.ts +++ b/backend/src/event/EventProtocolType.ts @@ -21,4 +21,6 @@ export enum EventProtocolType { CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM', CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE', CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM', + CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE', + CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE', } diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index d08396285..683946633 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -19,6 +19,7 @@ import { peterLustig } from '@/seeds/users/peter-lustig' import { EventProtocol } from '@entity/EventProtocol' import { EventProtocolType } from '@/event/EventProtocolType' import { logger } from '@test/testSetup' +import { Contribution } from '@entity/Contribution' let mutate: any, query: any, con: any let testEnv: any @@ -587,6 +588,15 @@ describe('ContributionResolver', () => { }), ) }) + + it('stores the update contribution event in the database', async () => { + await expect(EventProtocol.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventProtocolType.CONTRIBUTION_UPDATE, + contributionId: result.data.createContribution.id, + }), + ) + }) }) }) }) @@ -763,6 +773,7 @@ describe('ContributionResolver', () => { describe('User deletes own contribution', () => { it('deletes successfully', async () => { + console.log(await Contribution.find({ id: result.data.createContribution.id })) await expect( mutate({ mutation: deleteContribution, @@ -772,6 +783,16 @@ describe('ContributionResolver', () => { }), ).resolves.toBeTruthy() }) + + it('stores the delete contribution event in the database', async () => { + console.log(await Contribution.find({ id: result.data.createContribution.id })) + await expect(EventProtocol.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventProtocolType.CONTRIBUTION_DELETE, + // id: result.data.createContribution.id, + }), + ) + }) }) describe('User deletes already confirmed contribution', () => { diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 3c33a4e0f..9886eeb05 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -13,7 +13,12 @@ import { Contribution, ContributionListResult } from '@model/Contribution' import { UnconfirmedContribution } from '@model/UnconfirmedContribution' import { validateContribution, getUserCreation, updateCreations } from './util/creations' import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' -import { Event, EventContributionCreate } from '@/event/Event' +import { + Event, + EventContributionCreate, + EventContributionDelete, + EventContributionUpdate, +} from '@/event/Event' import { eventProtocol } from '@/event/EventProtocolEmitter' @Resolver() @@ -56,6 +61,8 @@ export class ContributionResolver { const eventCreateContribution = new EventContributionCreate() eventCreateContribution.userId = user.id + eventCreateContribution.amount = amount + eventCreateContribution.contributionId = contribution.id await eventProtocol.writeEvent(event.setEventContributionCreate(eventCreateContribution)) return new UnconfirmedContribution(contribution, user, creations) @@ -67,6 +74,7 @@ export class ContributionResolver { @Arg('id', () => Int) id: number, @Ctx() context: Context, ): Promise { + const event = new Event() const user = getUser(context) const contribution = await dbContribution.findOne(id) if (!contribution) { @@ -81,8 +89,16 @@ export class ContributionResolver { logger.error('A confirmed contribution can not be deleted') throw new Error('A confirmed contribution can not be deleted') } + contribution.contributionStatus = ContributionStatus.DELETED + contribution.deletedAt = new Date() await contribution.save() + + const eventDeleteContribution = new EventContributionDelete() + eventDeleteContribution.userId = user.id + eventDeleteContribution.contributionId = contribution.id + await eventProtocol.writeEvent(event.setEventContributionDelete(eventDeleteContribution)) + const res = await contribution.softRemove() return !!res } @@ -188,6 +204,13 @@ export class ContributionResolver { contributionToUpdate.contributionStatus = ContributionStatus.PENDING dbContribution.save(contributionToUpdate) + const event = new Event() + + const eventUpdateContribution = new EventContributionUpdate() + eventUpdateContribution.userId = user.id + eventUpdateContribution.contributionId = contributionId + await eventProtocol.writeEvent(event.setEventContributionUpdate(eventUpdateContribution)) + return new UnconfirmedContribution(contributionToUpdate, user, creations) } } From 60d2e2ff7bd0c093bb7b4acbea0b81ca34044e42 Mon Sep 17 00:00:00 2001 From: joseji Date: Fri, 23 Sep 2022 18:46:40 +0200 Subject: [PATCH 08/26] fixed contribution delete event saving and testing --- .../resolver/ContributionResolver.test.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 683946633..ee261c545 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -19,7 +19,6 @@ import { peterLustig } from '@/seeds/users/peter-lustig' import { EventProtocol } from '@entity/EventProtocol' import { EventProtocolType } from '@/event/EventProtocolType' import { logger } from '@test/testSetup' -import { Contribution } from '@entity/Contribution' let mutate: any, query: any, con: any let testEnv: any @@ -773,7 +772,6 @@ describe('ContributionResolver', () => { describe('User deletes own contribution', () => { it('deletes successfully', async () => { - console.log(await Contribution.find({ id: result.data.createContribution.id })) await expect( mutate({ mutation: deleteContribution, @@ -785,11 +783,26 @@ describe('ContributionResolver', () => { }) it('stores the delete contribution event in the database', async () => { - console.log(await Contribution.find({ id: result.data.createContribution.id })) + const contribution = await mutate({ + mutation: createContribution, + variables: { + amount: 166.0, + memo: 'Whatever contribution', + creationDate: new Date().toString(), + }, + }) + + await mutate({ + mutation: deleteContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }) + await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_DELETE, - // id: result.data.createContribution.id, + contributionId: contribution.data.createContribution.id, }), ) }) From 744c961c0bcda7595eb6ed1f8269aef5c993d700 Mon Sep 17 00:00:00 2001 From: joseji Date: Fri, 23 Sep 2022 19:33:54 +0200 Subject: [PATCH 09/26] fixed tests with new log message --- backend/src/event/EventProtocolType.ts | 12 ++++++++++++ .../graphql/resolver/ContributionResolver.test.ts | 11 ++++++++--- backend/src/graphql/resolver/util/creations.ts | 5 ++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/backend/src/event/EventProtocolType.ts b/backend/src/event/EventProtocolType.ts index c0fc1bb8e..4265fb924 100644 --- a/backend/src/event/EventProtocolType.ts +++ b/backend/src/event/EventProtocolType.ts @@ -3,24 +3,36 @@ export enum EventProtocolType { VISIT_GRADIDO = 'VISIT_GRADIDO', REGISTER = 'REGISTER', REDEEM_REGISTER = 'REDEEM_REGISTER', + VERIFY_REDEEM = 'VERIFY_REDEEM', // TODO INACTIVE_ACCOUNT = 'INACTIVE_ACCOUNT', SEND_CONFIRMATION_EMAIL = 'SEND_CONFIRMATION_EMAIL', + SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = 'SEND_ACCOUNT_MULTIREGISTRATION_EMAIL', // TODO CONFIRM_EMAIL = 'CONFIRM_EMAIL', REGISTER_EMAIL_KLICKTIPP = 'REGISTER_EMAIL_KLICKTIPP', LOGIN = 'LOGIN', + LOGOUT = 'LOGOUT', // TODO REDEEM_LOGIN = 'REDEEM_LOGIN', ACTIVATE_ACCOUNT = 'ACTIVATE_ACCOUNT', + SEND_FORGOT_PASSWORD_EMAIL = 'SEND_FORGOT_PASSWORD_EMAIL', // TODO PASSWORD_CHANGE = 'PASSWORD_CHANGE', + SEND_TRANSACTION_SEND_EMAIL = 'SEND_TRANSACTION_SEND_EMAIL', // TODO + SEND_TRANSACTION_RECEIVE_EMAIL = 'SEND_TRANSACTION_RECEIVE_EMAIL', // TODO TRANSACTION_SEND = 'TRANSACTION_SEND', TRANSACTION_SEND_REDEEM = 'TRANSACTION_SEND_REDEEM', TRANSACTION_REPEATE_REDEEM = 'TRANSACTION_REPEATE_REDEEM', TRANSACTION_CREATION = 'TRANSACTION_CREATION', TRANSACTION_RECEIVE = 'TRANSACTION_RECEIVE', TRANSACTION_RECEIVE_REDEEM = 'TRANSACTION_RECEIVE_REDEEM', + SEND_TRANSACTION_LINK_REDEEM_EMAIL = 'SEND_TRANSACTION_LINK_REDEEM_EMAIL', // TODO + SEND_ADDED_CONTRIBUTION_EMAIL = 'SEND_ADDED_CONTRIBUTION_EMAIL', // TODO + SEND_CONTRIBUTION_CONFIRM_EMAIL = 'SEND_CONTRIBUTION_CONFIRM_EMAIL', // TODO CONTRIBUTION_CREATE = 'CONTRIBUTION_CREATE', CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM', + CONTRIBUTION_DENY = 'CONTRIBUTION_DENY', // TODO CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE', CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM', CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE', CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE', + USER_CREATE_CONTRIBUTION_MESSAGE = 'USER_CREATE_CONTRIBUTION_MESSAGE', // TODO + ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE', // TODO } diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index ee261c545..b8bbebbd9 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -136,7 +136,8 @@ describe('ContributionResolver', () => { it('logs the error found', () => { expect(logger.error).toBeCalledWith( - 'No information for available creations for the given date', + 'No information for available creations with the given creationDate=', + new Date('non-valid').toDateString, ) }) @@ -161,8 +162,10 @@ describe('ContributionResolver', () => { }) it('logs the error found', () => { + const date = new Date() expect(logger.error).toBeCalledWith( - 'No information for available creations for the given date', + 'No information for available creations with the given creationDate=', + new Date(date.setMonth(date.getMonth() - 3).toString()).toDateString, ) }) }) @@ -557,8 +560,10 @@ describe('ContributionResolver', () => { }) it('logs the error found', () => { + const date = new Date() expect(logger.error).toBeCalledWith( - 'No information for available creations for the given date', + 'No information for available creations with the given creationDate=', + new Date(date.setMonth(date.getMonth() - 3).toString()).toDateString, ) }) }) diff --git a/backend/src/graphql/resolver/util/creations.ts b/backend/src/graphql/resolver/util/creations.ts index afbadead1..0b055e1d0 100644 --- a/backend/src/graphql/resolver/util/creations.ts +++ b/backend/src/graphql/resolver/util/creations.ts @@ -19,7 +19,10 @@ export const validateContribution = ( const index = getCreationIndex(creationDate.getMonth()) if (index < 0) { - logger.error('No information for available creations for the given date') + logger.error( + 'No information for available creations with the given creationDate=', + creationDate.toDateString, + ) throw new Error('No information for available creations for the given date') } From 49378c64e250beccdf72045eaea6598257d39bd0 Mon Sep 17 00:00:00 2001 From: joseji Date: Mon, 26 Sep 2022 22:17:07 +0200 Subject: [PATCH 10/26] new events fully implemented --- backend/src/event/Event.ts | 115 +++++++++++++++++++++++++ backend/src/event/EventProtocolType.ts | 24 +++--- 2 files changed, 127 insertions(+), 12 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 40eb333fd..f6e6a554c 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -30,11 +30,20 @@ export class EventBasicRedeem extends EventBasicUserId { export class EventVisitGradido extends EventBasic {} export class EventRegister extends EventBasicUserId {} export class EventRedeemRegister extends EventBasicRedeem {} +export class EventVerifyRedeem extends EventBasicRedeem {} export class EventInactiveAccount extends EventBasicUserId {} export class EventSendConfirmationEmail extends EventBasicUserId {} +export class EventSendAccountMultiregistrationEmail extends EventBasicUserId {} +export class EventSendForgotPasswordEmail extends EventBasicUserId {} +export class EventSendTransactionSendEmail extends EventBasicRedeem {} +export class EventSendTransactionReceiveEmail extends EventBasicRedeem {} +export class EventSendTransactionLinkRedeemEmail extends EventBasicRedeem {} +export class EventSendAddedContributionEmail extends EventBasicCt {} +export class EventSendContributionConfirmEmail extends EventBasicCt {} export class EventConfirmationEmail extends EventBasicUserId {} export class EventRegisterEmailKlicktipp extends EventBasicUserId {} export class EventLogin extends EventBasicUserId {} +export class EventLogout extends EventBasicUserId {} export class EventRedeemLogin extends EventBasicRedeem {} export class EventActivateAccount extends EventBasicUserId {} export class EventPasswordChange extends EventBasicUserId {} @@ -48,12 +57,22 @@ export class EventTransactionCreation extends EventBasicUserId { export class EventTransactionReceive extends EventBasicTx {} export class EventTransactionReceiveRedeem extends EventBasicTx {} export class EventContributionCreate extends EventBasicCt {} +export class EventUserCreateContributionMessage extends EventBasicCt { + message: string +} +export class EventAdminCreateContributionMessage extends EventBasicCt { + message: string +} export class EventContributionDelete extends EventBasicCt {} export class EventContributionUpdate extends EventBasicCt {} export class EventContributionConfirm extends EventBasicCt { xUserId: number xCommunityId: number } +export class EventContributionDeny extends EventBasicCt { + xUserId: number + xCommunityId: number +} export class EventContributionLinkDefine extends EventBasicCt {} export class EventContributionLinkActivateRedeem extends EventBasicCt {} @@ -101,6 +120,13 @@ export class Event { return this } + public setEventVerifyRedeem(ev: EventVerifyRedeem): Event { + this.setByBasicRedeem(ev.userId, ev.transactionId, ev.contributionId) + this.type = EventProtocolType.VERIFY_REDEEM + + return this + } + public setEventInactiveAccount(ev: EventInactiveAccount): Event { this.setByBasicUser(ev.userId) this.type = EventProtocolType.INACTIVE_ACCOUNT @@ -115,6 +141,62 @@ export class Event { return this } + public setEventSendAccountMultiregistrationEmail( + ev: EventSendAccountMultiregistrationEmail, + ): Event { + this.setByBasicUser(ev.userId) + this.type = EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL + + return this + } + + public setEventSendForgotPasswordEmail(ev: EventSendForgotPasswordEmail): Event { + this.setByBasicUser(ev.userId) + this.type = EventProtocolType.SEND_FORGOT_PASSWORD_EMAIL + + return this + } + + public setEventSendTransactionSendEmail(ev: EventSendTransactionSendEmail): Event { + this.setByBasicUser(ev.userId) + this.transactionId = ev.transactionId + this.type = EventProtocolType.SEND_TRANSACTION_SEND_EMAIL + + return this + } + + public setEventSendTransactionReceiveEmail(ev: EventSendTransactionReceiveEmail): Event { + this.setByBasicUser(ev.userId) + this.transactionId = ev.transactionId + this.type = EventProtocolType.SEND_TRANSACTION_RECEIVE_EMAIL + + return this + } + + public setEventSendTransactionLinkRedeemEmail(ev: EventSendTransactionLinkRedeemEmail): Event { + this.setByBasicUser(ev.userId) + this.transactionId = ev.transactionId + this.type = EventProtocolType.SEND_TRANSACTION_LINK_REDEEM_EMAIL + + return this + } + + public setEventSendAddedContributionEmail(ev: EventSendAddedContributionEmail): Event { + this.setByBasicUser(ev.userId) + this.contributionId = ev.contributionId + this.type = EventProtocolType.SEND_ADDED_CONTRIBUTION_EMAIL + + return this + } + + public setEventSendContributionConfirmEmail(ev: EventSendContributionConfirmEmail): Event { + this.setByBasicUser(ev.userId) + this.contributionId = ev.contributionId + this.type = EventProtocolType.SEND_CONTRIBUTION_CONFIRM_EMAIL + + return this + } + public setEventConfirmationEmail(ev: EventConfirmationEmail): Event { this.setByBasicUser(ev.userId) this.type = EventProtocolType.CONFIRM_EMAIL @@ -136,6 +218,13 @@ export class Event { return this } + public setEventLogout(ev: EventLogout): Event { + this.setByBasicUser(ev.userId) + this.type = EventProtocolType.LOGOUT + + return this + } + public setEventRedeemLogin(ev: EventRedeemLogin): Event { this.setByBasicRedeem(ev.userId, ev.transactionId, ev.contributionId) this.type = EventProtocolType.REDEEM_LOGIN @@ -208,6 +297,22 @@ export class Event { return this } + public setEventUserCreateContributionMessage(ev: EventUserCreateContributionMessage): Event { + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + if (ev.message) this.message = ev.message + this.type = EventProtocolType.USER_CREATE_CONTRIBUTION_MESSAGE + + return this + } + + public setEventAdminCreateContributionMessage(ev: EventAdminCreateContributionMessage): Event { + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + if (ev.message) this.message = ev.message + this.type = EventProtocolType.ADMIN_CREATE_CONTRIBUTION_MESSAGE + + return this + } + public setEventContributionDelete(ev: EventContributionDelete): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.CONTRIBUTION_DELETE @@ -231,6 +336,15 @@ export class Event { return this } + public setEventContributionDeny(ev: EventContributionDeny): Event { + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + if (ev.xUserId) this.xUserId = ev.xUserId + if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + this.type = EventProtocolType.CONTRIBUTION_DENY + + return this + } + public setEventContributionLinkDefine(ev: EventContributionLinkDefine): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.CONTRIBUTION_LINK_DEFINE @@ -314,4 +428,5 @@ export class Event { transactionId?: number contributionId?: number amount?: decimal + message?: string } diff --git a/backend/src/event/EventProtocolType.ts b/backend/src/event/EventProtocolType.ts index 4265fb924..d53eb6961 100644 --- a/backend/src/event/EventProtocolType.ts +++ b/backend/src/event/EventProtocolType.ts @@ -3,36 +3,36 @@ export enum EventProtocolType { VISIT_GRADIDO = 'VISIT_GRADIDO', REGISTER = 'REGISTER', REDEEM_REGISTER = 'REDEEM_REGISTER', - VERIFY_REDEEM = 'VERIFY_REDEEM', // TODO + VERIFY_REDEEM = 'VERIFY_REDEEM', INACTIVE_ACCOUNT = 'INACTIVE_ACCOUNT', SEND_CONFIRMATION_EMAIL = 'SEND_CONFIRMATION_EMAIL', - SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = 'SEND_ACCOUNT_MULTIREGISTRATION_EMAIL', // TODO + SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = 'SEND_ACCOUNT_MULTIREGISTRATION_EMAIL', CONFIRM_EMAIL = 'CONFIRM_EMAIL', REGISTER_EMAIL_KLICKTIPP = 'REGISTER_EMAIL_KLICKTIPP', LOGIN = 'LOGIN', - LOGOUT = 'LOGOUT', // TODO + LOGOUT = 'LOGOUT', REDEEM_LOGIN = 'REDEEM_LOGIN', ACTIVATE_ACCOUNT = 'ACTIVATE_ACCOUNT', - SEND_FORGOT_PASSWORD_EMAIL = 'SEND_FORGOT_PASSWORD_EMAIL', // TODO + SEND_FORGOT_PASSWORD_EMAIL = 'SEND_FORGOT_PASSWORD_EMAIL', PASSWORD_CHANGE = 'PASSWORD_CHANGE', - SEND_TRANSACTION_SEND_EMAIL = 'SEND_TRANSACTION_SEND_EMAIL', // TODO - SEND_TRANSACTION_RECEIVE_EMAIL = 'SEND_TRANSACTION_RECEIVE_EMAIL', // TODO + SEND_TRANSACTION_SEND_EMAIL = 'SEND_TRANSACTION_SEND_EMAIL', + SEND_TRANSACTION_RECEIVE_EMAIL = 'SEND_TRANSACTION_RECEIVE_EMAIL', TRANSACTION_SEND = 'TRANSACTION_SEND', TRANSACTION_SEND_REDEEM = 'TRANSACTION_SEND_REDEEM', TRANSACTION_REPEATE_REDEEM = 'TRANSACTION_REPEATE_REDEEM', TRANSACTION_CREATION = 'TRANSACTION_CREATION', TRANSACTION_RECEIVE = 'TRANSACTION_RECEIVE', TRANSACTION_RECEIVE_REDEEM = 'TRANSACTION_RECEIVE_REDEEM', - SEND_TRANSACTION_LINK_REDEEM_EMAIL = 'SEND_TRANSACTION_LINK_REDEEM_EMAIL', // TODO - SEND_ADDED_CONTRIBUTION_EMAIL = 'SEND_ADDED_CONTRIBUTION_EMAIL', // TODO - SEND_CONTRIBUTION_CONFIRM_EMAIL = 'SEND_CONTRIBUTION_CONFIRM_EMAIL', // TODO + SEND_TRANSACTION_LINK_REDEEM_EMAIL = 'SEND_TRANSACTION_LINK_REDEEM_EMAIL', + SEND_ADDED_CONTRIBUTION_EMAIL = 'SEND_ADDED_CONTRIBUTION_EMAIL', + SEND_CONTRIBUTION_CONFIRM_EMAIL = 'SEND_CONTRIBUTION_CONFIRM_EMAIL', CONTRIBUTION_CREATE = 'CONTRIBUTION_CREATE', CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM', - CONTRIBUTION_DENY = 'CONTRIBUTION_DENY', // TODO + CONTRIBUTION_DENY = 'CONTRIBUTION_DENY', CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE', CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM', CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE', CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE', - USER_CREATE_CONTRIBUTION_MESSAGE = 'USER_CREATE_CONTRIBUTION_MESSAGE', // TODO - ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE', // TODO + USER_CREATE_CONTRIBUTION_MESSAGE = 'USER_CREATE_CONTRIBUTION_MESSAGE', + ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE', } From 329e6f0893e8a2786c60a2264717965cb578a791 Mon Sep 17 00:00:00 2001 From: joseji Date: Mon, 26 Sep 2022 22:29:48 +0200 Subject: [PATCH 11/26] removed unnecesary previously included parameter 'message' on events --- backend/src/event/Event.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index f6e6a554c..bebc91915 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -299,7 +299,6 @@ export class Event { public setEventUserCreateContributionMessage(ev: EventUserCreateContributionMessage): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) - if (ev.message) this.message = ev.message this.type = EventProtocolType.USER_CREATE_CONTRIBUTION_MESSAGE return this @@ -307,7 +306,6 @@ export class Event { public setEventAdminCreateContributionMessage(ev: EventAdminCreateContributionMessage): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) - if (ev.message) this.message = ev.message this.type = EventProtocolType.ADMIN_CREATE_CONTRIBUTION_MESSAGE return this @@ -428,5 +426,4 @@ export class Event { transactionId?: number contributionId?: number amount?: decimal - message?: string } From c8a2d899b88bc563e1363cead9caef1064481605 Mon Sep 17 00:00:00 2001 From: joseji Date: Mon, 26 Sep 2022 22:41:33 +0200 Subject: [PATCH 12/26] all stated according to the events table --- backend/src/event/Event.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index bebc91915..27e188a64 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -35,9 +35,9 @@ export class EventInactiveAccount extends EventBasicUserId {} export class EventSendConfirmationEmail extends EventBasicUserId {} export class EventSendAccountMultiregistrationEmail extends EventBasicUserId {} export class EventSendForgotPasswordEmail extends EventBasicUserId {} -export class EventSendTransactionSendEmail extends EventBasicRedeem {} -export class EventSendTransactionReceiveEmail extends EventBasicRedeem {} -export class EventSendTransactionLinkRedeemEmail extends EventBasicRedeem {} +export class EventSendTransactionSendEmail extends EventBasicTx {} +export class EventSendTransactionReceiveEmail extends EventBasicTx {} +export class EventSendTransactionLinkRedeemEmail extends EventBasicTx {} export class EventSendAddedContributionEmail extends EventBasicCt {} export class EventSendContributionConfirmEmail extends EventBasicCt {} export class EventConfirmationEmail extends EventBasicUserId {} @@ -57,9 +57,7 @@ export class EventTransactionCreation extends EventBasicUserId { export class EventTransactionReceive extends EventBasicTx {} export class EventTransactionReceiveRedeem extends EventBasicTx {} export class EventContributionCreate extends EventBasicCt {} -export class EventUserCreateContributionMessage extends EventBasicCt { - message: string -} +export class EventUserCreateContributionMessage extends EventBasicCt {} export class EventAdminCreateContributionMessage extends EventBasicCt { message: string } @@ -159,7 +157,10 @@ export class Event { public setEventSendTransactionSendEmail(ev: EventSendTransactionSendEmail): Event { this.setByBasicUser(ev.userId) - this.transactionId = ev.transactionId + if (ev.transactionId) this.transactionId = ev.transactionId + if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + if (ev.xUserId) this.xUserId = ev.xUserId + if (ev.amount) this.amount = ev.amount this.type = EventProtocolType.SEND_TRANSACTION_SEND_EMAIL return this @@ -167,7 +168,10 @@ export class Event { public setEventSendTransactionReceiveEmail(ev: EventSendTransactionReceiveEmail): Event { this.setByBasicUser(ev.userId) - this.transactionId = ev.transactionId + if (ev.transactionId) this.transactionId = ev.transactionId + if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + if (ev.xUserId) this.xUserId = ev.xUserId + if (ev.amount) this.amount = ev.amount this.type = EventProtocolType.SEND_TRANSACTION_RECEIVE_EMAIL return this @@ -175,7 +179,10 @@ export class Event { public setEventSendTransactionLinkRedeemEmail(ev: EventSendTransactionLinkRedeemEmail): Event { this.setByBasicUser(ev.userId) - this.transactionId = ev.transactionId + if (ev.transactionId) this.transactionId = ev.transactionId + if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + if (ev.xUserId) this.xUserId = ev.xUserId + if (ev.amount) this.amount = ev.amount this.type = EventProtocolType.SEND_TRANSACTION_LINK_REDEEM_EMAIL return this @@ -183,7 +190,7 @@ export class Event { public setEventSendAddedContributionEmail(ev: EventSendAddedContributionEmail): Event { this.setByBasicUser(ev.userId) - this.contributionId = ev.contributionId + if (ev.contributionId) this.contributionId = ev.contributionId this.type = EventProtocolType.SEND_ADDED_CONTRIBUTION_EMAIL return this @@ -191,7 +198,7 @@ export class Event { public setEventSendContributionConfirmEmail(ev: EventSendContributionConfirmEmail): Event { this.setByBasicUser(ev.userId) - this.contributionId = ev.contributionId + if (ev.contributionId) this.contributionId = ev.contributionId this.type = EventProtocolType.SEND_CONTRIBUTION_CONFIRM_EMAIL return this From e97aac759fd33ec0e678789686f78d681d69a5ad Mon Sep 17 00:00:00 2001 From: joseji Date: Mon, 26 Sep 2022 23:00:33 +0200 Subject: [PATCH 13/26] typo camel case in 'send multiregistration email event' --- backend/src/event/Event.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 7c212978a..a0b5c05ec 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -33,7 +33,7 @@ export class EventRedeemRegister extends EventBasicRedeem {} export class EventVerifyRedeem extends EventBasicRedeem {} export class EventInactiveAccount extends EventBasicUserId {} export class EventSendConfirmationEmail extends EventBasicUserId {} -export class EventSendAccountMultiregistrationEmail extends EventBasicUserId {} +export class EventSendAccountMultiRegistrationEmail extends EventBasicUserId {} export class EventSendForgotPasswordEmail extends EventBasicUserId {} export class EventSendTransactionSendEmail extends EventBasicTx {} export class EventSendTransactionReceiveEmail extends EventBasicTx {} @@ -139,8 +139,8 @@ export class Event { return this } - public setEventSendAccountMultiregistrationEmail( - ev: EventSendAccountMultiregistrationEmail, + public setEventSendAccountMultiRegistrationEmail( + ev: EventSendAccountMultiRegistrationEmail, ): Event { this.setByBasicUser(ev.userId) this.type = EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL From b7c3d2acf19c40752c4352373a13b2e620fbb3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Tue, 27 Sep 2022 09:58:22 +0200 Subject: [PATCH 14/26] Refactor 'setup.md' to a mark-down file and clearify instructions --- deployment/bare_metal/setup.md | 265 ++++++++++++++++++++++----------- 1 file changed, 174 insertions(+), 91 deletions(-) diff --git a/deployment/bare_metal/setup.md b/deployment/bare_metal/setup.md index 7c1154862..1bce53b26 100644 --- a/deployment/bare_metal/setup.md +++ b/deployment/bare_metal/setup.md @@ -1,111 +1,194 @@ -# Setup script to setup the server be ready to run gradido -# This assums you have root access via ssh to your cleanly setup server -# Furthermore this assumes you have debian (11 64bit) running -# Check your (Sub-)Domain with your Provider. -# In this document gddhost.tld refers to your chosen domain +# Instructions To Run `Gradido` On Your Server -> ssh root@gddhost.tld +We split setting up `Gradido` on your server into two steps: -# change root default shell -> chsh -s /bin/bash -# Create user `gradido` -> useradd -d /home/gradido -m gradido -> passwd gradido ->> enter new password twice +- [Preparing your server](#command-list-to-setup-your-server-be-ready-to-install-gradido) +- [Installing `Gradido`](#use-commands-in-installsh-manually-in-your-shell-for-now) -# Gives the user priviledges - this might be omitted in order to harden security -# Care: This will require another administering user if you don't want root access. -# Since this setup expects the user running the software be the same as the administering user, -# you have to adjust the instructions according to that scenario. -# You might lock yourself out, if done wrong. -> usermod -a -G sudo gradido +## Command List To Setup Your Server Be Ready To Install `Gradido` -# change gradido default shell -> chsh -s /bin/bash gradido -# Install sudo -> apt-get install sudo -# switch to the new user -> su gradido +We assume you have root access via ssh to your cleanly setup server. +Furthermore we assume you have debian (11 64bit) running. -# Register first ssh key for user `gradido` -> mkdir ~/.ssh -> chmod 700 ~/.ssh -> nano ~/.ssh/authorized_keys ->> insert public key ->> ctrl + x ->> save +Check your (Sub-)Domain with your Provider. +In this document `gddhost.tld` refers to your chosen domain. -# Test authentication via SSH -> ssh -i /path/to/privKey gradido@gddhost.tld ->> This should log you in and allow you to use sudo commands, which will require the user's password +### SSH into your server -# Disable password authentication & root login -> cd /etc/ssh -> sudo cp sshd_config sshd_config.org -> sudo nano sshd_config ->> change `PermitRootLogin yes` to `PermitRootLogin no` ->> change `#PasswordAuthentication yes` to `PasswordAuthentication no` ->> change `UsePAM yes` to `UsePAM no` ->> ctrl + x ->> save -> sudo /etc/init.d/ssh restart +```bash +ssh root@gddhost.tld +``` -# Test SSH Access only, no root ssh access -> ssh gradido@gddhost.tld ->> Will result in in either a password request for your key or the message `Permission denied (publickey)` -> ssh -i /path/to/privKey root@gddhost.tld ->> Will result in `Permission denied (publickey)` -> ssh -i /path/to/privKey gradido@gddhost.tld ->> Will succeed after entering the correct keys password (if any) +### Change root default shell -# update system -> sudo apt-get update -> sudo apt-get upgrade +```bash +chsh -s /bin/bash +``` -# Install security tools -## ufw -> sudo apt-get install ufw -> sudo ufw allow http -> sudo ufw allow https -> sudo ufw allow ssh -> sudo ufw enable +### Create user `gradido` -## fail2ban -> sudo apt-get install -y fail2ban -> sudo /etc/init.d/fail2ban restart +```bash +$ useradd -d /home/gradido -m gradido +$ passwd gradido +# enter new password twice +``` -# Install gradido -> sudo apt-get install -y git -> cd ~ -> git clone https://github.com/gradido/gradido.git +### Give the user priviledges -# Timezone -# Note: This is needed - since there is Summer-Time included in the default server Setup - UTC is REQUIRED for production data -> sudo timedatectl set-timezone UTC -# > sudo timedatectl set-ntp on -# > sudo apt purge ntp -# > sudo systemctl start systemd-timesyncd -# >> timedatectl to verify +This might be omitted in order to harden security. -# Adjust .env -# NOTE ';' can not be part of any value -# The Github Secret is Created on Github in Settimgs -> Webhooks -> cd gradido/deployment/bare_metal -> cp .env.dist .env -> nano .env ->> Adjust values accordingly +***!!! Attention !!!*** -# TODO the install.sh is not yet ready to run directly - consider to use it as pattern to do it manually +- Care: This will require another administering user if you don't want root access. +- Since this setup expects the user running the software be the same as the administering user, + - you have to adjust the instructions according to that scenario. + - you might lock yourself out, if done wrong. -!!! ATTENTION: +#### Add the new user `gradido` to `sudo` group -- NGINX: - - Be aware to set the values for NGINX in the following files according to your needs before you install NGINX! - - `./nginx/sites-available/gradido.conf` - - `./nginx/sites-available/update-page.conf` -- Commands in `./install.sh`: - - The commands for setting the paths in the used env variables are not working directly in the terminal, consider the out commented commands for this purpose, see below. +```bash +usermod -a -G sudo gradido +``` -Follow the commands in `./install.sh`. +### Change gradido default shell +```bash +chsh -s /bin/bash gradido +``` + +### Install sudo + +```bash +apt-get install sudo +``` + +### Switch to the new user + +```bash +su gradido +``` + +### Register first ssh key for user `gradido` + +```bash +$ mkdir ~/.ssh +$ chmod 700 ~/.ssh +$ nano ~/.ssh/authorized_keys +# insert public key +# ctrl + x +# save +``` + +### Test authentication via SSH + +```bash +$ ssh -i /path/to/privKey gradido@gddhost.tld +# This should log you in and allow you to use sudo commands, which will require the user's password +``` + +### Disable password authentication and root login + +```bash +$ cd /etc/ssh +$ sudo cp sshd_config sshd_config.org +$ sudo nano sshd_config +# change 'PermitRootLogin yes' to `PermitRootLogin no` +# change 'PasswordAuthentication yes' to 'PasswordAuthentication no' +# change 'UsePAM yes' to 'UsePAM no' +# ctrl + x +# save +$ sudo /etc/init.d/ssh restart +``` + +### Test SSH Access only, no root ssh access + +```bash +$ ssh gradido@gddhost.tld +# Will result in in either a password request for your key or the message 'Permission denied (publickey)' +$ ssh -i /path/to/privKey root@gddhost.tld +# Will result in 'Permission denied (publickey)' +$ ssh -i /path/to/privKey gradido@gddhost.tld +# Will succeed after entering the correct keys password (if any) +``` + +### Update system + +```bash +sudo apt-get update +sudo apt-get upgrade +``` + +### Install security tools + +#### Install: `ufw` + +```bash +sudo apt-get install ufw +sudo ufw allow http +sudo ufw allow https +sudo ufw allow ssh +sudo ufw enable +``` + +#### Install: `fail2ban` + +```bash +sudo apt-get install -y fail2ban +sudo /etc/init.d/fail2ban restart +``` + +### Install `Gradido` code + +```bash +sudo apt-get install -y git +cd ~ +git clone https://github.com/gradido/gradido.git +``` + +### Timezone + +*Note: This is needed - since there is Summer-Time included in the default server Setup - UTC is REQUIRED for production data.* + +```bash +sudo timedatectl set-timezone UTC +sudo timedatectl set-ntp on +sudo apt purge ntp +sudo systemctl start systemd-timesyncd +# timedatectl to verify +``` + +### Adjust the values in `.env` + +***!!! Attention !!!*** + +*Don't forget this step! +All your following installations in `install.sh` will fail!* + +*Notes:* + +- *`;` cannot be part of any value!* +- *The GitHub secret is created on GitHub in Settings -> Webhooks.* + +#### Create `.env` and set values + +```bash +$ cd gradido/deployment/bare_metal +$ cp .env.dist .env +$ nano .env +# adjust values accordingly +``` + +## Use Commands In `install.sh` Manually In Your Shell For Now + +The script `install.sh` is not yet ready to run directly. +Use it as pattern to do all steps manually in your terminal shell. + +*TODO: Bring the `install.sh` script to run in the shell.* + +***!!! Attention !!!*** + +- *Commands in `install.sh`:* + - *The commands for setting the paths in the used env variables are not working directly in the terminal, consider the out commented commands for this purpose.* + +Follow the commands in `./install.sh` as installation pattern. From 3c1b103f931a8dae74325fb66e226da34c72055c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Tue, 27 Sep 2022 10:22:08 +0200 Subject: [PATCH 15/26] Refine the integration of the conflicting docu --- deployment/bare_metal/setup.md | 44 +++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/deployment/bare_metal/setup.md b/deployment/bare_metal/setup.md index 8f09d296b..96ff0f48b 100644 --- a/deployment/bare_metal/setup.md +++ b/deployment/bare_metal/setup.md @@ -1,10 +1,11 @@ # Instructions To Run `Gradido` On Your Server -We split setting up `Gradido` on your server into two steps: +We split setting up `Gradido` on your server into three steps: - [Preparing your server](#command-list-to-setup-your-server-be-ready-to-install-gradido) - [Installing `Gradido`](#use-commands-in-installsh-manually-in-your-shell-for-now) +- [Crone-Job for `Gradido`](#define-cronjob-to-compensate-yarn-output-in-tmp) ## Command List To Setup Your Server Be Ready To Install `Gradido` @@ -193,13 +194,38 @@ Use it as pattern to do all steps manually in your terminal shell. Follow the commands in `./install.sh` as installation pattern. -## Define cronjob to compensate yarn output in /tmp +## Define Cronjob To Compensate Yarn Output In `/tmp` -> yarn creates output in /tmp directory, which must be deleted regularly and will be done per cronjob -> on stage1 a hourly job is necessary by setting the following job in the crontab for the gradido user -> crontab -e opens the crontab in edit-mode and insert the following entry: -> "0 * * * * find /tmp -name "yarn--*" -cmin +60 -exec rm -r {} \; > /dev/null" -> on stage2 a daily job is necessary by setting the following job in the crontab for the gradido user -> crontab -e opens the crontab in edit-mode and insert the following entry: -> "0 4 * * * find /tmp -name "yarn--*" -ctime +1 -exec rm -r {} \; > /dev/null" +`yarn` creates output in `/tmp` directory, which must be deleted regularly and will be done per Cron-Job. +### On `stage1` + +An hourly job is necessary on `stage1` by setting the following job in the `crontab` for the `gradido` user. + +Run: + +```bash +crontab -e +``` + +This opens the crontab in edit-mode and insert the following entry: + +```bash +0 * * * * find /tmp -name "yarn--*" -cmin +60 -exec rm -r {} \; > /dev/null +``` + +### On `stage2` + +A daily job is necessary on `stage2` by setting the following job in the `crontab` for the `gradido` user. + +Run: + +```bash +crontab -e +``` + +This opens the `crontab` in edit-mode and insert the following entry: + +```bash +0 4 * * * find /tmp -name "yarn--*" -ctime +1 -exec rm -r {} \; > /dev/null +``` From cbfeb88a2f80905b4e48d654a5d11f86a5e3b540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Tue, 27 Sep 2022 14:13:19 +0200 Subject: [PATCH 16/26] Fulfill Moriz suggestions Co-Authored-By: Mogge --- deployment/bare_metal/setup.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/setup.md b/deployment/bare_metal/setup.md index 96ff0f48b..5892cf4fc 100644 --- a/deployment/bare_metal/setup.md +++ b/deployment/bare_metal/setup.md @@ -83,6 +83,8 @@ $ nano ~/.ssh/authorized_keys ### Test authentication via SSH +If you logout from the server you can test authentication: + ```bash $ ssh -i /path/to/privKey gradido@gddhost.tld # This should log you in and allow you to use sudo commands, which will require the user's password @@ -106,11 +108,11 @@ $ sudo /etc/init.d/ssh restart ```bash $ ssh gradido@gddhost.tld -# Will result in in either a password request for your key or the message 'Permission denied (publickey)' +# Will result in in either a passphrase request for your key or the message 'Permission denied (publickey)' $ ssh -i /path/to/privKey root@gddhost.tld # Will result in 'Permission denied (publickey)' $ ssh -i /path/to/privKey gradido@gddhost.tld -# Will succeed after entering the correct keys password (if any) +# Will succeed after entering the correct keys passphrase (if any) ``` ### Update system From ce280f6320c802ded0d9a422aabdb8a51d26a531 Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 29 Sep 2022 11:53:32 +0200 Subject: [PATCH 17/26] some conversations solved --- backend/src/event/Event.ts | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index a0b5c05ec..8b8834b59 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -22,11 +22,22 @@ export class EventBasicCt extends EventBasicUserId { amount: decimal } +export class EventBasicCtX extends EventBasicUserId { + xUserId: number + xCommunityId: number + contributionId: number + amount: decimal +} + export class EventBasicRedeem extends EventBasicUserId { transactionId?: number contributionId?: number } +export class EventBasicCtMsg extends EventBasicCt { + message: string +} + export class EventVisitGradido extends EventBasic {} export class EventRegister extends EventBasicUserId {} export class EventRedeemRegister extends EventBasicRedeem {} @@ -57,8 +68,8 @@ export class EventTransactionCreation extends EventBasicUserId { export class EventTransactionReceive extends EventBasicTx {} export class EventTransactionReceiveRedeem extends EventBasicTx {} export class EventContributionCreate extends EventBasicCt {} -export class EventUserCreateContributionMessage extends EventBasicCt {} -export class EventAdminCreateContributionMessage extends EventBasicCt { +export class EventUserCreateContributionMessage extends EventBasicCtMsg {} +export class EventAdminCreateContributionMessage extends EventBasicCtMsg { message: string } export class EventContributionDelete extends EventBasicCt {} @@ -67,10 +78,7 @@ export class EventContributionConfirm extends EventBasicCt { xUserId: number xCommunityId: number } -export class EventContributionDeny extends EventBasicCt { - xUserId: number - xCommunityId: number -} +export class EventContributionDeny extends EventBasicCtX {} export class EventContributionLinkDefine extends EventBasicCt {} export class EventContributionLinkActivateRedeem extends EventBasicCt {} @@ -306,14 +314,14 @@ export class Event { public setEventUserCreateContributionMessage(ev: EventUserCreateContributionMessage): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.USER_CREATE_CONTRIBUTION_MESSAGE - + this.message = ev.message return this } public setEventAdminCreateContributionMessage(ev: EventAdminCreateContributionMessage): Event { this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.ADMIN_CREATE_CONTRIBUTION_MESSAGE - + this.message = ev.message return this } @@ -341,9 +349,11 @@ export class Event { } public setEventContributionDeny(ev: EventContributionDeny): Event { - this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) - if (ev.xUserId) this.xUserId = ev.xUserId + this.setByBasicTx(ev.userId) + if (ev.contributionId) this.contributionId = ev.contributionId if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + if (ev.xUserId) this.xUserId = ev.xUserId + if (ev.amount) this.amount = ev.amount this.type = EventProtocolType.CONTRIBUTION_DENY return this @@ -432,4 +442,5 @@ export class Event { transactionId?: number contributionId?: number amount?: decimal + message?: string } From 7061718c1f92aee84ef2c14aeb21055ad59162f9 Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 29 Sep 2022 12:20:08 +0200 Subject: [PATCH 18/26] all conversations solved --- backend/src/event/Event.ts | 78 ++++++++++--------- .../resolver/ContributionResolver.test.ts | 8 +- .../src/graphql/resolver/util/creations.ts | 2 +- 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 8b8834b59..ee24c768b 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -22,7 +22,7 @@ export class EventBasicCt extends EventBasicUserId { amount: decimal } -export class EventBasicCtX extends EventBasicUserId { +export class EventBasicCtX extends EventBasicCt { xUserId: number xCommunityId: number contributionId: number @@ -74,10 +74,7 @@ export class EventAdminCreateContributionMessage extends EventBasicCtMsg { } export class EventContributionDelete extends EventBasicCt {} export class EventContributionUpdate extends EventBasicCt {} -export class EventContributionConfirm extends EventBasicCt { - xUserId: number - xCommunityId: number -} +export class EventContributionConfirm extends EventBasicCtX {} export class EventContributionDeny extends EventBasicCtX {} export class EventContributionLinkDefine extends EventBasicCt {} export class EventContributionLinkActivateRedeem extends EventBasicCt {} @@ -164,50 +161,37 @@ export class Event { } public setEventSendTransactionSendEmail(ev: EventSendTransactionSendEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.transactionId) this.transactionId = ev.transactionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) this.type = EventProtocolType.SEND_TRANSACTION_SEND_EMAIL return this } public setEventSendTransactionReceiveEmail(ev: EventSendTransactionReceiveEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.transactionId) this.transactionId = ev.transactionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) this.type = EventProtocolType.SEND_TRANSACTION_RECEIVE_EMAIL return this } public setEventSendTransactionLinkRedeemEmail(ev: EventSendTransactionLinkRedeemEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.transactionId) this.transactionId = ev.transactionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) this.type = EventProtocolType.SEND_TRANSACTION_LINK_REDEEM_EMAIL return this } public setEventSendAddedContributionEmail(ev: EventSendAddedContributionEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.contributionId) this.contributionId = ev.contributionId + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.SEND_ADDED_CONTRIBUTION_EMAIL return this } public setEventSendContributionConfirmEmail(ev: EventSendContributionConfirmEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.contributionId) this.contributionId = ev.contributionId + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.SEND_CONTRIBUTION_CONFIRM_EMAIL + return this } @@ -312,16 +296,16 @@ export class Event { } public setEventUserCreateContributionMessage(ev: EventUserCreateContributionMessage): Event { - this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.message) this.type = EventProtocolType.USER_CREATE_CONTRIBUTION_MESSAGE - this.message = ev.message + return this } public setEventAdminCreateContributionMessage(ev: EventAdminCreateContributionMessage): Event { - this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.message) this.type = EventProtocolType.ADMIN_CREATE_CONTRIBUTION_MESSAGE - this.message = ev.message + return this } @@ -340,20 +324,14 @@ export class Event { } public setEventContributionConfirm(ev: EventContributionConfirm): Event { - this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + this.setByBasicCtX(ev.userId, ev.xUserId, ev.xCommunityId, ev.contributionId, ev.amount) this.type = EventProtocolType.CONTRIBUTION_CONFIRM return this } public setEventContributionDeny(ev: EventContributionDeny): Event { - this.setByBasicTx(ev.userId) - if (ev.contributionId) this.contributionId = ev.contributionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicCtX(ev.userId, ev.xUserId, ev.xCommunityId, ev.contributionId, ev.amount) this.type = EventProtocolType.CONTRIBUTION_DENY return this @@ -404,6 +382,34 @@ export class Event { return this } + setByBasicCtMsg( + userId: number, + contributionId: number, + amount?: decimal, + message?: string, + ): Event { + this.setByBasicCt(userId, contributionId, amount) + if (message) this.message = message + + return this + } + + setByBasicCtX( + userId: number, + xUserId?: number, + xCommunityId?: number, + contributionId?: number, + amount?: decimal, + ): Event { + this.setByBasicUser(userId) + if (xUserId) this.xUserId = xUserId + if (xCommunityId) this.xCommunityId = xCommunityId + if (contributionId) this.contributionId = contributionId + if (amount) this.amount = amount + + return this + } + setByBasicRedeem(userId: number, transactionId?: number, contributionId?: number): Event { this.setByBasicUser(userId) if (transactionId) this.transactionId = transactionId diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index b8bbebbd9..199fb6c76 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -137,7 +137,7 @@ describe('ContributionResolver', () => { it('logs the error found', () => { expect(logger.error).toBeCalledWith( 'No information for available creations with the given creationDate=', - new Date('non-valid').toDateString, + 'Invalid Date', ) }) @@ -162,10 +162,9 @@ describe('ContributionResolver', () => { }) it('logs the error found', () => { - const date = new Date() expect(logger.error).toBeCalledWith( 'No information for available creations with the given creationDate=', - new Date(date.setMonth(date.getMonth() - 3).toString()).toDateString, + 'Invalid Date', ) }) }) @@ -560,10 +559,9 @@ describe('ContributionResolver', () => { }) it('logs the error found', () => { - const date = new Date() expect(logger.error).toBeCalledWith( 'No information for available creations with the given creationDate=', - new Date(date.setMonth(date.getMonth() - 3).toString()).toDateString, + 'Invalid Date', ) }) }) diff --git a/backend/src/graphql/resolver/util/creations.ts b/backend/src/graphql/resolver/util/creations.ts index b390e197d..9987dfae6 100644 --- a/backend/src/graphql/resolver/util/creations.ts +++ b/backend/src/graphql/resolver/util/creations.ts @@ -21,7 +21,7 @@ export const validateContribution = ( if (index < 0) { logger.error( 'No information for available creations with the given creationDate=', - creationDate.toDateString, + creationDate.toString(), ) throw new Error('No information for available creations for the given date') } From f05c31f69b90df32e71d424c08a166246dbe277e Mon Sep 17 00:00:00 2001 From: joseji Date: Thu, 29 Sep 2022 12:32:43 +0200 Subject: [PATCH 19/26] removed duplicated code --- backend/src/event/Event.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index ee24c768b..a70df23a2 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -69,9 +69,7 @@ export class EventTransactionReceive extends EventBasicTx {} export class EventTransactionReceiveRedeem extends EventBasicTx {} export class EventContributionCreate extends EventBasicCt {} export class EventUserCreateContributionMessage extends EventBasicCtMsg {} -export class EventAdminCreateContributionMessage extends EventBasicCtMsg { - message: string -} +export class EventAdminCreateContributionMessage extends EventBasicCtMsg {} export class EventContributionDelete extends EventBasicCt {} export class EventContributionUpdate extends EventBasicCt {} export class EventContributionConfirm extends EventBasicCtX {} From 7a21ec12e0ee2817d847dffabf7b55c85ec20f49 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 19:26:05 +0200 Subject: [PATCH 20/26] message changed for messageId and some small problems solved --- backend/src/event/Event.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index a70df23a2..3fbaf71f7 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -25,8 +25,6 @@ export class EventBasicCt extends EventBasicUserId { export class EventBasicCtX extends EventBasicCt { xUserId: number xCommunityId: number - contributionId: number - amount: decimal } export class EventBasicRedeem extends EventBasicUserId { @@ -35,7 +33,7 @@ export class EventBasicRedeem extends EventBasicUserId { } export class EventBasicCtMsg extends EventBasicCt { - message: string + messageId: number } export class EventVisitGradido extends EventBasic {} @@ -294,14 +292,14 @@ export class Event { } public setEventUserCreateContributionMessage(ev: EventUserCreateContributionMessage): Event { - this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.message) + this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.messageId) this.type = EventProtocolType.USER_CREATE_CONTRIBUTION_MESSAGE return this } public setEventAdminCreateContributionMessage(ev: EventAdminCreateContributionMessage): Event { - this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.message) + this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.messageId) this.type = EventProtocolType.ADMIN_CREATE_CONTRIBUTION_MESSAGE return this @@ -383,11 +381,11 @@ export class Event { setByBasicCtMsg( userId: number, contributionId: number, - amount?: decimal, - message?: string, + amount: decimal, + messageId: number, ): Event { this.setByBasicCt(userId, contributionId, amount) - if (message) this.message = message + if (messageId) this.messageId = messageId return this } @@ -446,5 +444,5 @@ export class Event { transactionId?: number contributionId?: number amount?: decimal - message?: string + messageId?: number } From 903fd4446e6efdf6f5c7540915d22c0b545deee8 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 20:32:10 +0200 Subject: [PATCH 21/26] changed database version --- backend/src/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 3e6bafd9f..b622293ad 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -10,7 +10,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0049-add_user_contacts_table', + DB_VERSION: '0050-add_messageId_to_event_protocol', DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info From 4853eea32a6995166ac33adf9c04c77be6f6db63 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 20:33:22 +0200 Subject: [PATCH 22/26] fixed wrong non mandatory attributes --- backend/src/event/Event.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 3fbaf71f7..832e61ec5 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -392,16 +392,16 @@ export class Event { setByBasicCtX( userId: number, - xUserId?: number, - xCommunityId?: number, - contributionId?: number, - amount?: decimal, + xUserId: number, + xCommunityId: number, + contributionId: number, + amount: decimal, ): Event { this.setByBasicUser(userId) - if (xUserId) this.xUserId = xUserId - if (xCommunityId) this.xCommunityId = xCommunityId - if (contributionId) this.contributionId = contributionId - if (amount) this.amount = amount + this.xUserId = xUserId + this.xCommunityId = xCommunityId + this.contributionId = contributionId + this.amount = amount return this } From bb3d1caa73ece468a60f68958ae0d393fca603a4 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 20:33:50 +0200 Subject: [PATCH 23/26] fixed amount not being initialized in databsae while storing events --- backend/src/graphql/resolver/ContributionResolver.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 9886eeb05..e7d9ecdaa 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -97,6 +97,7 @@ export class ContributionResolver { const eventDeleteContribution = new EventContributionDelete() eventDeleteContribution.userId = user.id eventDeleteContribution.contributionId = contribution.id + eventDeleteContribution.amount = contribution.amount await eventProtocol.writeEvent(event.setEventContributionDelete(eventDeleteContribution)) const res = await contribution.softRemove() @@ -209,6 +210,7 @@ export class ContributionResolver { const eventUpdateContribution = new EventContributionUpdate() eventUpdateContribution.userId = user.id eventUpdateContribution.contributionId = contributionId + eventUpdateContribution.amount = amount await eventProtocol.writeEvent(event.setEventContributionUpdate(eventUpdateContribution)) return new UnconfirmedContribution(contributionToUpdate, user, creations) From 65f53df9390fb617313bba246468875dc7013d85 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 20:34:37 +0200 Subject: [PATCH 24/26] added new column to event protocol dabatase table to keep message id --- .../EventProtocol.ts | 42 +++++++++++++++++++ .../0050-add_messageId_to_event_protocol.ts | 12 ++++++ 2 files changed, 54 insertions(+) create mode 100644 database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts create mode 100644 database/migrations/0050-add_messageId_to_event_protocol.ts diff --git a/database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts b/database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts new file mode 100644 index 000000000..d4dbc526f --- /dev/null +++ b/database/entity/0050-add_messageId_to_event_protocol/EventProtocol.ts @@ -0,0 +1,42 @@ +import Decimal from 'decimal.js-light' +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm' +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' + +@Entity('event_protocol') +export class EventProtocol extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' }) + type: string + + @Column({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) + createdAt: Date + + @Column({ name: 'user_id', unsigned: true, nullable: false }) + userId: number + + @Column({ name: 'x_user_id', unsigned: true, nullable: true }) + xUserId: number + + @Column({ name: 'x_community_id', unsigned: true, nullable: true }) + xCommunityId: number + + @Column({ name: 'transaction_id', unsigned: true, nullable: true }) + transactionId: number + + @Column({ name: 'contribution_id', unsigned: true, nullable: true }) + contributionId: number + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: true, + transformer: DecimalTransformer, + }) + amount: Decimal + + @Column({ name: 'message_id', unsigned: true, nullable: true }) + messageId: number +} diff --git a/database/migrations/0050-add_messageId_to_event_protocol.ts b/database/migrations/0050-add_messageId_to_event_protocol.ts new file mode 100644 index 000000000..ccef98688 --- /dev/null +++ b/database/migrations/0050-add_messageId_to_event_protocol.ts @@ -0,0 +1,12 @@ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn( + `ALTER TABLE \`event_protocol\` ADD COLUMN \`message_id\` int(10) unsigned NULL DEFAULT NULL;`, + ) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(`ALTER TABLE \`event_protocol\` DROP COLUMN \`message_id\`;`) +} From 3eae1f60b292f95e20bccd0da96b670ec9631fa8 Mon Sep 17 00:00:00 2001 From: joseji Date: Tue, 4 Oct 2022 21:18:00 +0200 Subject: [PATCH 25/26] applied propper conventions and fixed code duplication --- backend/src/event/Event.ts | 113 ++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 65 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 832e61ec5..94266ebc0 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -11,12 +11,15 @@ export class EventBasicUserId extends EventBasic { } export class EventBasicTx extends EventBasicUserId { - xUserId: number - xCommunityId: number transactionId: number amount: decimal } +export class EventBasicTxX extends EventBasicTx { + xUserId: number + xCommunityId: number +} + export class EventBasicCt extends EventBasicUserId { contributionId: number amount: decimal @@ -28,8 +31,8 @@ export class EventBasicCtX extends EventBasicCt { } export class EventBasicRedeem extends EventBasicUserId { - transactionId?: number - contributionId?: number + transactionId: number + contributionId: number } export class EventBasicCtMsg extends EventBasicCt { @@ -44,9 +47,9 @@ export class EventInactiveAccount extends EventBasicUserId {} export class EventSendConfirmationEmail extends EventBasicUserId {} export class EventSendAccountMultiRegistrationEmail extends EventBasicUserId {} export class EventSendForgotPasswordEmail extends EventBasicUserId {} -export class EventSendTransactionSendEmail extends EventBasicTx {} -export class EventSendTransactionReceiveEmail extends EventBasicTx {} -export class EventSendTransactionLinkRedeemEmail extends EventBasicTx {} +export class EventSendTransactionSendEmail extends EventBasicTxX {} +export class EventSendTransactionReceiveEmail extends EventBasicTxX {} +export class EventSendTransactionLinkRedeemEmail extends EventBasicTxX {} export class EventSendAddedContributionEmail extends EventBasicCt {} export class EventSendContributionConfirmEmail extends EventBasicCt {} export class EventConfirmationEmail extends EventBasicUserId {} @@ -56,15 +59,12 @@ export class EventLogout extends EventBasicUserId {} export class EventRedeemLogin extends EventBasicRedeem {} export class EventActivateAccount extends EventBasicUserId {} export class EventPasswordChange extends EventBasicUserId {} -export class EventTransactionSend extends EventBasicTx {} -export class EventTransactionSendRedeem extends EventBasicTx {} -export class EventTransactionRepeateRedeem extends EventBasicTx {} -export class EventTransactionCreation extends EventBasicUserId { - transactionId: number - amount: decimal -} -export class EventTransactionReceive extends EventBasicTx {} -export class EventTransactionReceiveRedeem extends EventBasicTx {} +export class EventTransactionSend extends EventBasicTxX {} +export class EventTransactionSendRedeem extends EventBasicTxX {} +export class EventTransactionRepeateRedeem extends EventBasicTxX {} +export class EventTransactionCreation extends EventBasicTx {} +export class EventTransactionReceive extends EventBasicTxX {} +export class EventTransactionReceiveRedeem extends EventBasicTxX {} export class EventContributionCreate extends EventBasicCt {} export class EventUserCreateContributionMessage extends EventBasicCtMsg {} export class EventAdminCreateContributionMessage extends EventBasicCtMsg {} @@ -157,21 +157,21 @@ export class Event { } public setEventSendTransactionSendEmail(ev: EventSendTransactionSendEmail): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.SEND_TRANSACTION_SEND_EMAIL return this } public setEventSendTransactionReceiveEmail(ev: EventSendTransactionReceiveEmail): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.SEND_TRANSACTION_RECEIVE_EMAIL return this } public setEventSendTransactionLinkRedeemEmail(ev: EventSendTransactionLinkRedeemEmail): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.SEND_TRANSACTION_LINK_REDEEM_EMAIL return this @@ -241,44 +241,42 @@ export class Event { } public setEventTransactionSend(ev: EventTransactionSend): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.TRANSACTION_SEND return this } public setEventTransactionSendRedeem(ev: EventTransactionSendRedeem): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.TRANSACTION_SEND_REDEEM return this } public setEventTransactionRepeateRedeem(ev: EventTransactionRepeateRedeem): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.TRANSACTION_REPEATE_REDEEM return this } public setEventTransactionCreation(ev: EventTransactionCreation): Event { - this.setByBasicUser(ev.userId) - if (ev.transactionId) this.transactionId = ev.transactionId - if (ev.amount) this.amount = ev.amount + this.setByBasicTx(ev.userId, ev.transactionId, ev.amount) this.type = EventProtocolType.TRANSACTION_CREATION return this } public setEventTransactionReceive(ev: EventTransactionReceive): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.TRANSACTION_RECEIVE return this } public setEventTransactionReceiveRedeem(ev: EventTransactionReceiveRedeem): Event { - this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) + this.setByBasicTxX(ev.userId, ev.transactionId, ev.amount, ev.xUserId, ev.xCommunityId) this.type = EventProtocolType.TRANSACTION_RECEIVE_REDEEM return this @@ -354,26 +352,32 @@ export class Event { return this } - setByBasicTx( - userId: number, - xUserId?: number, - xCommunityId?: number, - transactionId?: number, - amount?: decimal, - ): Event { + setByBasicTx(userId: number, transactionId: number, amount: decimal): Event { this.setByBasicUser(userId) - if (xUserId) this.xUserId = xUserId - if (xCommunityId) this.xCommunityId = xCommunityId - if (transactionId) this.transactionId = transactionId - if (amount) this.amount = amount + this.transactionId = transactionId + this.amount = amount return this } - setByBasicCt(userId: number, contributionId: number, amount?: decimal): Event { + setByBasicTxX( + userId: number, + transactionId: number, + amount: decimal, + xUserId: number, + xCommunityId: number, + ): Event { + this.setByBasicTx(userId, transactionId, amount) + this.xUserId = xUserId + this.xCommunityId = xCommunityId + + return this + } + + setByBasicCt(userId: number, contributionId: number, amount: decimal): Event { this.setByBasicUser(userId) - if (contributionId) this.contributionId = contributionId - if (amount) this.amount = amount + this.contributionId = contributionId + this.amount = amount return this } @@ -406,31 +410,10 @@ export class Event { return this } - setByBasicRedeem(userId: number, transactionId?: number, contributionId?: number): Event { + setByBasicRedeem(userId: number, transactionId: number, contributionId: number): Event { this.setByBasicUser(userId) - if (transactionId) this.transactionId = transactionId - if (contributionId) this.contributionId = contributionId - - return this - } - - setByEventTransactionCreation(event: EventTransactionCreation): Event { - this.type = event.type - this.createdAt = event.createdAt - this.userId = event.userId - this.transactionId = event.transactionId - this.amount = event.amount - - return this - } - - setByEventContributionConfirm(event: EventContributionConfirm): Event { - this.type = event.type - this.createdAt = event.createdAt - this.userId = event.userId - this.xUserId = event.xUserId - this.xCommunityId = event.xCommunityId - this.amount = event.amount + this.transactionId = transactionId + this.contributionId = contributionId return this } From ad174e6e0a8a2a8d6b84a401284c9965242bf66e Mon Sep 17 00:00:00 2001 From: joseji Date: Fri, 7 Oct 2022 12:09:09 +0200 Subject: [PATCH 26/26] corrections --- backend/src/event/Event.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 94266ebc0..cec94e5bf 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -31,8 +31,8 @@ export class EventBasicCtX extends EventBasicCt { } export class EventBasicRedeem extends EventBasicUserId { - transactionId: number - contributionId: number + transactionId?: number + contributionId?: number } export class EventBasicCtMsg extends EventBasicCt { @@ -389,31 +389,29 @@ export class Event { messageId: number, ): Event { this.setByBasicCt(userId, contributionId, amount) - if (messageId) this.messageId = messageId + this.messageId = messageId return this } setByBasicCtX( userId: number, - xUserId: number, - xCommunityId: number, contributionId: number, amount: decimal, + xUserId: number, + xCommunityId: number, ): Event { - this.setByBasicUser(userId) + this.setByBasicCt(userId, contributionId, amount) this.xUserId = xUserId this.xCommunityId = xCommunityId - this.contributionId = contributionId - this.amount = amount return this } - setByBasicRedeem(userId: number, transactionId: number, contributionId: number): Event { + setByBasicRedeem(userId: number, transactionId?: number, contributionId?: number): Event { this.setByBasicUser(userId) - this.transactionId = transactionId - this.contributionId = contributionId + if (transactionId) this.transactionId = transactionId + if (contributionId) this.contributionId = contributionId return this }