From d38539df7ceda1cfcd6aeaaf2f6035f040d255a9 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 14 Feb 2023 12:09:29 +0100 Subject: [PATCH 01/49] Add yarn build on gradido folder, goes into database, admin, frontend, backend, e2e-tests and federation. --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2220c1a85..626e3ed02 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "author": "Ulf Gebhardt ", "license": "Apache-2.0", "scripts": { - "release": "scripts/release.sh" + "release": "scripts/release.sh", + "build": "yarn && cd database && yarn && cd ../frontend && yarn && cd ../admin && yarn && cd ../backend && yarn && cd ../e2e-tests && yarn && cd ../federation && yarn && cd .." }, "dependencies": { "auto-changelog": "^2.4.0", From 8e85bf30d02ac4f2051618425543788d2ce9f9d6 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 15 Feb 2023 16:15:47 +0100 Subject: [PATCH 02/49] Rename build to install so we can install gradido under packages with this command. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 626e3ed02..86c345011 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "license": "Apache-2.0", "scripts": { "release": "scripts/release.sh", - "build": "yarn && cd database && yarn && cd ../frontend && yarn && cd ../admin && yarn && cd ../backend && yarn && cd ../e2e-tests && yarn && cd ../federation && yarn && cd .." + "install": "yarn && cd database && yarn && cd ../frontend && yarn && cd ../admin && yarn && cd ../backend && yarn && cd ../e2e-tests && yarn && cd ../federation && yarn && cd .." }, "dependencies": { "auto-changelog": "^2.4.0", From 4db4e63200dd30f90b045f224c77950f8a21e7e7 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 15 Feb 2023 16:18:31 +0100 Subject: [PATCH 03/49] With install it collide with the normal install. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 86c345011..e7fc91a96 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "license": "Apache-2.0", "scripts": { "release": "scripts/release.sh", - "install": "yarn && cd database && yarn && cd ../frontend && yarn && cd ../admin && yarn && cd ../backend && yarn && cd ../e2e-tests && yarn && cd ../federation && yarn && cd .." + "installAll": "yarn && cd database && yarn && cd ../frontend && yarn && cd ../admin && yarn && cd ../backend && yarn && cd ../e2e-tests && yarn && cd ../federation && yarn && cd .." }, "dependencies": { "auto-changelog": "^2.4.0", From 81daa8324437760e59c47eabdda9bc50832e3afa Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 15 Feb 2023 16:22:33 +0100 Subject: [PATCH 04/49] Add new command to the README. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d086018e..87b4f44e5 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,11 @@ git clone git@github.com:gradido/gradido.git git submodule update --recursive --init ``` -### 2. Run docker-compose +### 2. Install modules + +You can go in each under folder (admin, frontend, database, backend, ...) and call ``yarn`` in each folder or you can call ``yarn installAll``. + +### 3. Run docker-compose Run docker-compose to bring up the development environment From ddae7f647dc1f7aa1d1324f4fbd1a937bd6935ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 15 Feb 2023 23:11:16 +0100 Subject: [PATCH 05/49] describe and draw the current federation moduls and handshake --- .../TechnicalRequirements/Federation.md | 47 ++- .../graphics/TechnicalOverview_V1-19.drawio | 282 ++++++++++++++++++ .../image/TechnicalOverview_V1-19.svg | 1 + 3 files changed, 303 insertions(+), 27 deletions(-) create mode 100644 docu/Concepts/TechnicalRequirements/graphics/TechnicalOverview_V1-19.drawio create mode 100644 docu/Concepts/TechnicalRequirements/image/TechnicalOverview_V1-19.svg diff --git a/docu/Concepts/TechnicalRequirements/Federation.md b/docu/Concepts/TechnicalRequirements/Federation.md index 959aa8afe..7210756ff 100644 --- a/docu/Concepts/TechnicalRequirements/Federation.md +++ b/docu/Concepts/TechnicalRequirements/Federation.md @@ -4,29 +4,6 @@ This document contains the concept and technical details for the *federation* of But meanwhile the usage of a DHT like HyperSwarm promises more coverage of the gradido requirements out of the box. More details about HyperSwarm can be found here [@hyperswarm/dht](https://github.com/hyperswarm/dht). -## ActivityPub (deprecated) - -The activity pub defines a server-to-server federation protocol to share information between decentralized instances and will be the main komponent for the gradido community federation. - -At first we asume a *gradido community* as an *ActivityPub user*. A user is represented by "*actors*" via the users's accounts on servers. User's accounts on different servers corrsponds to different actors, which means community accounts on different servers corrsponds to different communities. - -Every community (actor) has an: - -* inbox: to get messages from the world -* outbox: to send messages to others - -and are simple endpoints or just URLs, which are described in the *ActivityStream* of each *ActivityPub community*. - -### Open Decision: - -It has to be decided, if the Federation will work with an internal or with external ActivityPub-Server, as shown in the picture below: - -![FederationActivityPub](./image/FederationActivityPub.png " ") - -The Variant A with an internal server contains the benefit to be as independent as possible from third party service providers and will not cause additional hosting costs. But this solution will cause the additional efforts of impementing an ActivityPub-Server in the gradido application and the responsibility for this component. - -The Varaint B with an external server contains the benefit to reduce the implementation efforts and the responsibility for an own ActivitPub-Server. But it will cause an additional dependency to a third party service provider and the growing hosting costs. - ## HyperSwarm The decision to switch from ActivityPub to HyperSwarm base on the arguments, that the *hyperswarm/dht* library will satify the most federation requirements out of the box. It is now to design the business requirements of the [gradido community communication](../BusinessRequirements/CommunityVerwaltung.md#UC-createCommunity) in a technical conception. @@ -41,12 +18,28 @@ To enable such a relationship between an existing community and a new community 2. Authentication 3. Autorized Communication -### Overview +### Overview of Federation-Handshake At first the following diagramm gives an overview of the three stages and shows the handshake between an existing community-A and a new created community-B including the data exchange for buildup such a federated, authenticated and autorized relationship. ![FederationHyperSwarm.png](./image/FederationHyperSwarm.png) +### Technical Architecture + +The previous described handshake will be done by several technical moduls of the gradido system. The following picture gives an overview about the moduls and how the communicate with each other. + +![img](./image/TechnicalOverview_V1-19.svg) + +As soon as a Gradido Community is up and running the DHT-Modul first write the home-community-entries in the database and starts with the federation per HyperSwarm. Each community, which is configured to listen on the GRADIDO_HUB of the DHT will be part of the Gradido-Net-Federation. That means each DHT-Modul of each community will receive the publicKey of all connected communities. The DHT-Modul will open for each received publicKey a communication-socket with the associated community DHT-Modul, to exchange api-version info and hosted urls for later direct communication between both communities. The exchanged api-version info and urls will be written in the own database. + +The up and running Backend-Modul contains a validation logic to verify the community entries from the own DHT-Modul. For each announced but unverified community-entry the GraphQL-Client is used to invoke a getPublicKey-Request. Depending on the containing api-version the matching GraphQL-Client is used and the getPublicKey-Request will be send to the given URL. + +As soon as the FederationModul of the assoziated community received the getPublicKey-request the own publicKey is read from database and send back in the response. + +The GraphQL-Client will read from the returned response data the publicKey of the other community and compare it with the data of the community-entry, which cause the getPublicKey-Request. If they match the community-entry will be updated be inserting the current timestamp in the verifiedAt-field of this community-entry. + +This federation and verification logic will work the whole time and can be monitored by observing the communities-table changes. The Admin-UI will contain a Page to have a look on the current state of the communities table content. + ### Prerequisits Before starting in describing the details of the federation handshake, some prerequisits have to be defined. @@ -235,7 +228,7 @@ For the first federation release the *DHT-Node* will be part of the *apollo serv | communityApiVersion.apiversion | keep existing value | | communityApiVersion.validFrom | exchangedData.API.validFrom | | communityApiVersion.verifiedAt | keep existing value | - * + * 3. After all received data is stored successfully, the *DHT-Node* starts the *stage2 - Authentication* of the federation handshake ### Stage2 - Authentication @@ -284,8 +277,8 @@ As soon the *openConnection* request is invoked: 3. check if the decrypted `parameter.signedAndEncryptedURL` is equals the selected url from the previous selected CommunityFederationEntry 1. if not then break the further processing of this request by only writing an error-log event. There will be no answer to the invoker community, because this community will only go on with a `openConnectionRedirect`-request from this community. 2. if yes then verify the signature of `parameter.signedAndEncryptedURL` with the `cf.pubKey` read in step 2 before - 3. -4. + 3. +4. ### Stage3 - Autorized Business Communication diff --git a/docu/Concepts/TechnicalRequirements/graphics/TechnicalOverview_V1-19.drawio b/docu/Concepts/TechnicalRequirements/graphics/TechnicalOverview_V1-19.drawio new file mode 100644 index 000000000..534804e1d --- /dev/null +++ b/docu/Concepts/TechnicalRequirements/graphics/TechnicalOverview_V1-19.drawio @@ -0,0 +1,282 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docu/Concepts/TechnicalRequirements/image/TechnicalOverview_V1-19.svg b/docu/Concepts/TechnicalRequirements/image/TechnicalOverview_V1-19.svg new file mode 100644 index 000000000..4b407aa5a --- /dev/null +++ b/docu/Concepts/TechnicalRequirements/image/TechnicalOverview_V1-19.svg @@ -0,0 +1 @@ +
Community  "Gradido-Akademie"
Community  "Gradido-Akademie"
Gradido - technical Infrastructure-Overview
State of 02.2023
Gradido - technical Infrastructure-Overview...
Backend-Modul
GraphQL-API
Backend-Modul...
CommunityServer DB
CommunityServer DB
Layer 1:
Layer 1:
Layer 2:
Layer 2:
"GDT-Server"
base on C++ + mySQL
"GDT-Server"...
GDT-Server DB
GDT-Server DB
json-
ajax-
request
json-...
Layer 3:
Layer 3:
"Elopage"
external Service-Portal
"Elopage"...
"User-UI"
"User-UI"
graphql
graphql
json-
request
json-...
graphql
graphql
"Admin-UI"
"Admin-UI"
DHT-Modul
HyperSwarm
DHT-Modul...
Federation-Modul
GraphQL-API V2_0
Federation-Modul...
Federation-Modul
GraphQL-API V1_x
Federation-Modul...
Federation-Modul
GraphQL-API V1_1
Federation-Modul...
Federation-Modul
GraphQL-API V1_0
Federation-Modul...
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
Community "GallischesDorf-TBB"
Community "GallischesDorf-TBB"
Backend-Modul
GraphQL-API
Backend-Modul...
CommunityServer DB
CommunityServer DB
Layer 1:
Layer 1:
Layer 2:
Layer 2:
Layer 3:
Layer 3:
"User-UI"
"User-UI"
graphql
graphql
graphql
graphql
"Admin-UI"
"Admin-UI"
 DHT-Socket Communication 
 DHT-Socket Communication 
DHT-Modul
HyperSwarm
DHT-Modul...
Federation-Modul
GraphQL-API V1_1
Federation-Modul...
Federation-Modul
GraphQL-API V1_0
Federation-Modul...
graphQL-Handshake
graphQL-Handshake
GraphQL-Client V1_1
GraphQL-Client V1_1
graphQL-Handshake
graphQL-Handshake
GraphQL-Client V1_0
GraphQL-Client V1_0
graphQL-Handshake
graphQL-Handshake
graphQL-Handshake
graphQL-Handshake
Viewer does not support full SVG 1.1
\ No newline at end of file From d6044b4fe61bd26ec0ba7318523d12c1318bbb22 Mon Sep 17 00:00:00 2001 From: Einhornimmond Date: Thu, 16 Feb 2023 14:46:12 +0100 Subject: [PATCH 06/49] correct error with gdt server in graphic --- .../graphics/TechnicalOverview_V1-19.drawio | 144 +++++++++--------- .../image/TechnicalOverview_V1-19.svg | 2 +- 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/docu/Concepts/TechnicalRequirements/graphics/TechnicalOverview_V1-19.drawio b/docu/Concepts/TechnicalRequirements/graphics/TechnicalOverview_V1-19.drawio index 534804e1d..3ce2508d9 100644 --- a/docu/Concepts/TechnicalRequirements/graphics/TechnicalOverview_V1-19.drawio +++ b/docu/Concepts/TechnicalRequirements/graphics/TechnicalOverview_V1-19.drawio @@ -1,277 +1,277 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/docu/Concepts/TechnicalRequirements/image/TechnicalOverview_V1-19.svg b/docu/Concepts/TechnicalRequirements/image/TechnicalOverview_V1-19.svg index 4b407aa5a..2f5264182 100644 --- a/docu/Concepts/TechnicalRequirements/image/TechnicalOverview_V1-19.svg +++ b/docu/Concepts/TechnicalRequirements/image/TechnicalOverview_V1-19.svg @@ -1 +1 @@ -
Community  "Gradido-Akademie"
Community  "Gradido-Akademie"
Gradido - technical Infrastructure-Overview
State of 02.2023
Gradido - technical Infrastructure-Overview...
Backend-Modul
GraphQL-API
Backend-Modul...
CommunityServer DB
CommunityServer DB
Layer 1:
Layer 1:
Layer 2:
Layer 2:
"GDT-Server"
base on C++ + mySQL
"GDT-Server"...
GDT-Server DB
GDT-Server DB
json-
ajax-
request
json-...
Layer 3:
Layer 3:
"Elopage"
external Service-Portal
"Elopage"...
"User-UI"
"User-UI"
graphql
graphql
json-
request
json-...
graphql
graphql
"Admin-UI"
"Admin-UI"
DHT-Modul
HyperSwarm
DHT-Modul...
Federation-Modul
GraphQL-API V2_0
Federation-Modul...
Federation-Modul
GraphQL-API V1_x
Federation-Modul...
Federation-Modul
GraphQL-API V1_1
Federation-Modul...
Federation-Modul
GraphQL-API V1_0
Federation-Modul...
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
Community "GallischesDorf-TBB"
Community "GallischesDorf-TBB"
Backend-Modul
GraphQL-API
Backend-Modul...
CommunityServer DB
CommunityServer DB
Layer 1:
Layer 1:
Layer 2:
Layer 2:
Layer 3:
Layer 3:
"User-UI"
"User-UI"
graphql
graphql
graphql
graphql
"Admin-UI"
"Admin-UI"
 DHT-Socket Communication 
 DHT-Socket Communication 
DHT-Modul
HyperSwarm
DHT-Modul...
Federation-Modul
GraphQL-API V1_1
Federation-Modul...
Federation-Modul
GraphQL-API V1_0
Federation-Modul...
graphQL-Handshake
graphQL-Handshake
GraphQL-Client V1_1
GraphQL-Client V1_1
graphQL-Handshake
graphQL-Handshake
GraphQL-Client V1_0
GraphQL-Client V1_0
graphQL-Handshake
graphQL-Handshake
graphQL-Handshake
graphQL-Handshake
Viewer does not support full SVG 1.1
\ No newline at end of file +
Community  "Gradido-Akademie"
Community  "Gradido-Akademie"
Gradido - technical Infrastructure-Overview
State of 02.2023
Gradido - technical Infrastructure-Overview...
Backend-Modul
GraphQL-API
Backend-Modul...
CommunityServer DB
CommunityServer DB
Layer 1:
Layer 1:
Layer 2:
Layer 2:
"GDT-Server"
base on cakephp + mySQL
"GDT-Server"...
GDT-Server DB
GDT-Server DB
json-
ajax-
request
json-...
Layer 3:
Layer 3:
"Elopage"
external Service-Portal
"Elopage"...
"User-UI"
"User-UI"
graphql
graphql
json-
request
json-...
graphql
graphql
"Admin-UI"
"Admin-UI"
DHT-Modul
HyperSwarm
DHT-Modul...
Federation-Modul
GraphQL-API V2_0
Federation-Modul...
Federation-Modul
GraphQL-API V1_x
Federation-Modul...
Federation-Modul
GraphQL-API V1_1
Federation-Modul...
Federation-Modul
GraphQL-API V1_0
Federation-Modul...
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
GraphQL-Client V1_0
Community "GallischesDorf-TBB"
Community "GallischesDorf-TBB"
Backend-Modul
GraphQL-API
Backend-Modul...
CommunityServer DB
CommunityServer DB
Layer 1:
Layer 1:
Layer 2:
Layer 2:
Layer 3:
Layer 3:
"User-UI"
"User-UI"
graphql
graphql
graphql
graphql
"Admin-UI"
"Admin-UI"
 DHT-Socket Communication 
 DHT-Socket Communication 
DHT-Modul
HyperSwarm
DHT-Modul...
Federation-Modul
GraphQL-API V1_1
Federation-Modul...
Federation-Modul
GraphQL-API V1_0
Federation-Modul...
graphQL-Handshake
graphQL-Handshake
GraphQL-Client V1_1
GraphQL-Client V1_1
graphQL-Handshake
graphQL-Handshake
GraphQL-Client V1_0
GraphQL-Client V1_0
graphQL-Handshake
graphQL-Handshake
graphQL-Handshake
graphQL-Handshake
Text is not SVG - cannot display
\ No newline at end of file From d3a1b8afe5844cf179fad61f6da8212fcb7e8249 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:32:22 +0100 Subject: [PATCH 07/49] Update docu/Concepts/TechnicalRequirements/Federation.md Co-authored-by: Ulf Gebhardt --- docu/Concepts/TechnicalRequirements/Federation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docu/Concepts/TechnicalRequirements/Federation.md b/docu/Concepts/TechnicalRequirements/Federation.md index 7210756ff..5e674e7d1 100644 --- a/docu/Concepts/TechnicalRequirements/Federation.md +++ b/docu/Concepts/TechnicalRequirements/Federation.md @@ -26,7 +26,7 @@ At first the following diagramm gives an overview of the three stages and shows ### Technical Architecture -The previous described handshake will be done by several technical moduls of the gradido system. The following picture gives an overview about the moduls and how the communicate with each other. +The previous described handshake will be done by several technical modules of the gradido system. The following picture gives an overview about the modules and how the communicate with each other. ![img](./image/TechnicalOverview_V1-19.svg) From 73ce45034401c6a409215d3b9f54c9dcf00823e1 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:35:45 +0100 Subject: [PATCH 08/49] Update docu/Concepts/TechnicalRequirements/Federation.md Co-authored-by: Ulf Gebhardt --- docu/Concepts/TechnicalRequirements/Federation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docu/Concepts/TechnicalRequirements/Federation.md b/docu/Concepts/TechnicalRequirements/Federation.md index 5e674e7d1..afa7116d3 100644 --- a/docu/Concepts/TechnicalRequirements/Federation.md +++ b/docu/Concepts/TechnicalRequirements/Federation.md @@ -34,7 +34,7 @@ As soon as a Gradido Community is up and running the DHT-Modul first write the h The up and running Backend-Modul contains a validation logic to verify the community entries from the own DHT-Modul. For each announced but unverified community-entry the GraphQL-Client is used to invoke a getPublicKey-Request. Depending on the containing api-version the matching GraphQL-Client is used and the getPublicKey-Request will be send to the given URL. -As soon as the FederationModul of the assoziated community received the getPublicKey-request the own publicKey is read from database and send back in the response. +As soon as the FederationModul of the associated community received the getPublicKey-request the own publicKey is read from database and send back in the response. The GraphQL-Client will read from the returned response data the publicKey of the other community and compare it with the data of the community-entry, which cause the getPublicKey-Request. If they match the community-entry will be updated be inserting the current timestamp in the verifiedAt-field of this community-entry. From b617149138ec1c161ecf70f31a3fe34e12a196c3 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:36:02 +0100 Subject: [PATCH 09/49] Update docu/Concepts/TechnicalRequirements/Federation.md Co-authored-by: Ulf Gebhardt --- docu/Concepts/TechnicalRequirements/Federation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docu/Concepts/TechnicalRequirements/Federation.md b/docu/Concepts/TechnicalRequirements/Federation.md index afa7116d3..a5ecc984d 100644 --- a/docu/Concepts/TechnicalRequirements/Federation.md +++ b/docu/Concepts/TechnicalRequirements/Federation.md @@ -36,7 +36,7 @@ The up and running Backend-Modul contains a validation logic to verify the commu As soon as the FederationModul of the associated community received the getPublicKey-request the own publicKey is read from database and send back in the response. -The GraphQL-Client will read from the returned response data the publicKey of the other community and compare it with the data of the community-entry, which cause the getPublicKey-Request. If they match the community-entry will be updated be inserting the current timestamp in the verifiedAt-field of this community-entry. +The GraphQL-Client will read the publicKey of the other community from the returned response data and compare it with the data of the community-entry, which caused the getPublicKey-Request. If they match the community-entry will be updated be inserting the current timestamp in the verifiedAt-field of this community-entry. This federation and verification logic will work the whole time and can be monitored by observing the communities-table changes. The Admin-UI will contain a Page to have a look on the current state of the communities table content. From c89a1916aea0ad0f78283df749f05262166d2a8a Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:37:04 +0100 Subject: [PATCH 10/49] Update docu/Concepts/TechnicalRequirements/Federation.md Co-authored-by: Hannes Heine --- docu/Concepts/TechnicalRequirements/Federation.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docu/Concepts/TechnicalRequirements/Federation.md b/docu/Concepts/TechnicalRequirements/Federation.md index a5ecc984d..6ba5589e3 100644 --- a/docu/Concepts/TechnicalRequirements/Federation.md +++ b/docu/Concepts/TechnicalRequirements/Federation.md @@ -277,8 +277,6 @@ As soon the *openConnection* request is invoked: 3. check if the decrypted `parameter.signedAndEncryptedURL` is equals the selected url from the previous selected CommunityFederationEntry 1. if not then break the further processing of this request by only writing an error-log event. There will be no answer to the invoker community, because this community will only go on with a `openConnectionRedirect`-request from this community. 2. if yes then verify the signature of `parameter.signedAndEncryptedURL` with the `cf.pubKey` read in step 2 before - 3. -4. ### Stage3 - Autorized Business Communication From 66d077c256897501d89f15998d8610c89bb4e159 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:37:14 +0100 Subject: [PATCH 11/49] Update docu/Concepts/TechnicalRequirements/Federation.md Co-authored-by: Hannes Heine --- docu/Concepts/TechnicalRequirements/Federation.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docu/Concepts/TechnicalRequirements/Federation.md b/docu/Concepts/TechnicalRequirements/Federation.md index 6ba5589e3..f9a94d7a1 100644 --- a/docu/Concepts/TechnicalRequirements/Federation.md +++ b/docu/Concepts/TechnicalRequirements/Federation.md @@ -228,7 +228,6 @@ For the first federation release the *DHT-Node* will be part of the *apollo serv | communityApiVersion.apiversion | keep existing value | | communityApiVersion.validFrom | exchangedData.API.validFrom | | communityApiVersion.verifiedAt | keep existing value | - * 3. After all received data is stored successfully, the *DHT-Node* starts the *stage2 - Authentication* of the federation handshake ### Stage2 - Authentication From abcad503b000c97315104321c7350aa06c1e0428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Mon, 6 Mar 2023 22:40:41 +0100 Subject: [PATCH 12/49] optimize log-output --- federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts index 53f0d0bd4..8670c3d1d 100644 --- a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts @@ -7,12 +7,12 @@ import { GetPublicKeyResult } from '../model/GetPublicKeyResult' export class PublicKeyResolver { @Query(() => GetPublicKeyResult) async getPublicKey(): Promise { - logger.info(`getPublicKey()...`) + logger.debug(`getPublicKey() via apiVersion=1_0 ...`) const homeCom = await DbCommunity.findOneOrFail({ foreign: false, apiVersion: '1_0', }) - logger.info(`getPublicKey()... with publicKey=${homeCom.publicKey}`) + logger.info(`getPublicKey()-1_0... return publicKey=${homeCom.publicKey}`) return new GetPublicKeyResult(homeCom.publicKey.toString()) } } From 46831167bc905345283bfd0807a81c2d2744a893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Mar 2023 01:14:18 +0100 Subject: [PATCH 13/49] new testclass --- .../1_0/resolver/PublicKeyResolver.test.ts | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts new file mode 100644 index 000000000..1622c7be4 --- /dev/null +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts @@ -0,0 +1,54 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { createTestClient } from 'apollo-server-testing' +import createServer from '@/server/createServer' +import { Community as DbCommunity } from '@entity/Community' + +let query: any +let testEnv: any + +// to do: We need a setup for the tests that closes the connection +let con: any + +beforeAll(async () => { + const server = await createServer() + con = server.con + query = createTestClient(server.apollo).query + DbCommunity.clear() +}) + +afterAll(async () => { + await con.close() +}) + +describe('PublicKeyResolver', () => { + const getPublicKeyQuery = ` + query { + getPublicKey + { + publicKey + } + } + ` + + describe('getPublicKey', () => { + beforeEach(async () => { + const homeCom = new DbCommunity() + homeCom.foreign = false + homeCom.apiVersion = '1_0' + homeCom.endPoint = 'endpoint-url' + homeCom.publicKey = Buffer.from('homeCommunity-publicKey') + await DbCommunity.insert(homeCom) + }) + + it('returns homeCommunity-publicKey', async () => { + await expect(query({ query: getPublicKeyQuery })).resolves.toMatchObject({ + data: { + getPublicKey: { + publicKey: 'homeCommunity-publicKey', + }, + }, + }) + }) + }) +}) From c71e293e6732ae68ca7673c6698e445f6d311d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Mar 2023 03:48:43 +0100 Subject: [PATCH 14/49] next try for test --- .../src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts index 1622c7be4..25fde9f3c 100644 --- a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts @@ -42,13 +42,14 @@ describe('PublicKeyResolver', () => { }) it('returns homeCommunity-publicKey', async () => { - await expect(query({ query: getPublicKeyQuery })).resolves.toMatchObject({ + await expect(query({ query: getPublicKeyQuery })).resolves.toEqual(expect.objectContaining({ data: { getPublicKey: { publicKey: 'homeCommunity-publicKey', }, }, }) + ) }) }) }) From 9d0a62033101b003d2574c4605612d1d19995a90 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 6 Mar 2023 14:00:54 +0100 Subject: [PATCH 15/49] prefix admin right with ADMIN_ --- backend/src/auth/RIGHTS.ts | 26 +++++++++---------- .../resolver/ContributionLinkResolver.ts | 6 ++--- .../graphql/resolver/ContributionResolver.ts | 8 +++--- .../resolver/TransactionLinkResolver.ts | 2 +- backend/src/graphql/resolver/UserResolver.ts | 10 +++---- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/backend/src/auth/RIGHTS.ts b/backend/src/auth/RIGHTS.ts index 8b0e82c86..f6db44b90 100644 --- a/backend/src/auth/RIGHTS.ts +++ b/backend/src/auth/RIGHTS.ts @@ -37,21 +37,21 @@ export enum RIGHTS { LIST_ALL_CONTRIBUTION_MESSAGES = 'LIST_ALL_CONTRIBUTION_MESSAGES', OPEN_CREATIONS = 'OPEN_CREATIONS', // Admin - SEARCH_USERS = 'SEARCH_USERS', - SET_USER_ROLE = 'SET_USER_ROLE', - DELETE_USER = 'DELETE_USER', - UNDELETE_USER = 'UNDELETE_USER', + ADMIN_SEARCH_USERS = 'SEARCH_USERS', + ADMIN_SET_USER_ROLE = 'SET_USER_ROLE', + ADMIN_DELETE_USER = 'DELETE_USER', + ADMIN_UNDELETE_USER = 'UNDELETE_USER', ADMIN_CREATE_CONTRIBUTION = 'ADMIN_CREATE_CONTRIBUTION', ADMIN_UPDATE_CONTRIBUTION = 'ADMIN_UPDATE_CONTRIBUTION', ADMIN_DELETE_CONTRIBUTION = 'ADMIN_DELETE_CONTRIBUTION', - LIST_UNCONFIRMED_CONTRIBUTIONS = 'LIST_UNCONFIRMED_CONTRIBUTIONS', - CONFIRM_CONTRIBUTION = 'CONFIRM_CONTRIBUTION', - SEND_ACTIVATION_EMAIL = 'SEND_ACTIVATION_EMAIL', - CREATION_TRANSACTION_LIST = 'CREATION_TRANSACTION_LIST', - LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN', - CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', - DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK', - UPDATE_CONTRIBUTION_LINK = 'UPDATE_CONTRIBUTION_LINK', + ADMIN_LIST_UNCONFIRMED_CONTRIBUTIONS = 'LIST_UNCONFIRMED_CONTRIBUTIONS', + ADMIN_CONFIRM_CONTRIBUTION = 'CONFIRM_CONTRIBUTION', + ADMIN_SEND_ACTIVATION_EMAIL = 'SEND_ACTIVATION_EMAIL', + ADMIN_CREATION_TRANSACTION_LIST = 'CREATION_TRANSACTION_LIST', + ADMIN_LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN', + ADMIN_CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', + ADMIN_DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK', + ADMIN_UPDATE_CONTRIBUTION_LINK = 'UPDATE_CONTRIBUTION_LINK', ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE', - DENY_CONTRIBUTION = 'DENY_CONTRIBUTION', + ADMIN_DENY_CONTRIBUTION = 'DENY_CONTRIBUTION', } diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.ts b/backend/src/graphql/resolver/ContributionLinkResolver.ts index 39f202848..d3c77cb82 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.ts @@ -24,7 +24,7 @@ import LogError from '@/server/LogError' @Resolver() export class ContributionLinkResolver { - @Authorized([RIGHTS.CREATE_CONTRIBUTION_LINK]) + @Authorized([RIGHTS.ADMIN_CREATE_CONTRIBUTION_LINK]) @Mutation(() => ContributionLink) async createContributionLink( @Args() @@ -90,7 +90,7 @@ export class ContributionLinkResolver { } } - @Authorized([RIGHTS.DELETE_CONTRIBUTION_LINK]) + @Authorized([RIGHTS.ADMIN_DELETE_CONTRIBUTION_LINK]) @Mutation(() => Date, { nullable: true }) async deleteContributionLink(@Arg('id', () => Int) id: number): Promise { const contributionLink = await DbContributionLink.findOne(id) @@ -103,7 +103,7 @@ export class ContributionLinkResolver { return newContributionLink ? newContributionLink.deletedAt : null } - @Authorized([RIGHTS.UPDATE_CONTRIBUTION_LINK]) + @Authorized([RIGHTS.ADMIN_UPDATE_CONTRIBUTION_LINK]) @Mutation(() => ContributionLink) async updateContributionLink( @Args() diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 1b8d24d2b..0d27739f9 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -390,7 +390,7 @@ export class ContributionResolver { return result } - @Authorized([RIGHTS.LIST_UNCONFIRMED_CONTRIBUTIONS]) + @Authorized([RIGHTS.ADMIN_LIST_UNCONFIRMED_CONTRIBUTIONS]) @Query(() => ContributionListResult) // [UnconfirmedContribution] async adminListAllContributions( @Args() @@ -461,7 +461,7 @@ export class ContributionResolver { return !!res } - @Authorized([RIGHTS.CONFIRM_CONTRIBUTION]) + @Authorized([RIGHTS.ADMIN_CONFIRM_CONTRIBUTION]) @Mutation(() => Boolean) async confirmContribution( @Arg('id', () => Int) id: number, @@ -566,7 +566,7 @@ export class ContributionResolver { return true } - @Authorized([RIGHTS.CREATION_TRANSACTION_LIST]) + @Authorized([RIGHTS.ADMIN_CREATION_TRANSACTION_LIST]) @Query(() => ContributionListResult) async creationTransactionList( @Args() @@ -612,7 +612,7 @@ export class ContributionResolver { }) } - @Authorized([RIGHTS.DENY_CONTRIBUTION]) + @Authorized([RIGHTS.ADMIN_DENY_CONTRIBUTION]) @Mutation(() => Boolean) async denyContribution( @Arg('id', () => Int) id: number, diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index ab5b52bad..66d0fbb4b 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -336,7 +336,7 @@ export class TransactionLinkResolver { ) } - @Authorized([RIGHTS.LIST_TRANSACTION_LINKS_ADMIN]) + @Authorized([RIGHTS.ADMIN_LIST_TRANSACTION_LINKS_ADMIN]) @Query(() => TransactionLinkResult) async listTransactionLinksAdmin( @Args() diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 435ca3c82..d79b0444e 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -640,7 +640,7 @@ export class UserResolver { } } - @Authorized([RIGHTS.SEARCH_USERS]) + @Authorized([RIGHTS.ADMIN_SEARCH_USERS]) @Query(() => SearchUsersResult) async searchUsers( @Args() @@ -706,7 +706,7 @@ export class UserResolver { } } - @Authorized([RIGHTS.SET_USER_ROLE]) + @Authorized([RIGHTS.ADMIN_SET_USER_ROLE]) @Mutation(() => Date, { nullable: true }) async setUserRole( @Arg('userId', () => Int) @@ -748,7 +748,7 @@ export class UserResolver { return newUser ? newUser.isAdmin : null } - @Authorized([RIGHTS.DELETE_USER]) + @Authorized([RIGHTS.ADMIN_DELETE_USER]) @Mutation(() => Date, { nullable: true }) async deleteUser( @Arg('userId', () => Int) userId: number, @@ -770,7 +770,7 @@ export class UserResolver { return newUser ? newUser.deletedAt : null } - @Authorized([RIGHTS.UNDELETE_USER]) + @Authorized([RIGHTS.ADMIN_UNDELETE_USER]) @Mutation(() => Date, { nullable: true }) async unDeleteUser(@Arg('userId', () => Int) userId: number): Promise { const user = await DbUser.findOne({ id: userId }, { withDeleted: true }) @@ -785,7 +785,7 @@ export class UserResolver { } // TODO this is an admin function - needs refactor - @Authorized([RIGHTS.SEND_ACTIVATION_EMAIL]) + @Authorized([RIGHTS.ADMIN_SEND_ACTIVATION_EMAIL]) @Mutation(() => Boolean) async sendActivationEmail( @Arg('email') email: string, From d204e79cd5ddbdbfe2eb01a07c86ca96c52e2ba3 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 6 Mar 2023 15:29:37 +0100 Subject: [PATCH 16/49] rename eventProtocolType to eventType --- backend/src/event/Event.ts | 64 ++++++------------- .../{EventProtocolType.ts => EventType.ts} | 2 +- .../resolver/ContributionResolver.test.ts | 22 +++---- .../resolver/TransactionResolver.test.ts | 6 +- .../src/graphql/resolver/UserResolver.test.ts | 20 +++--- backend/src/graphql/resolver/UserResolver.ts | 4 +- 6 files changed, 45 insertions(+), 73 deletions(-) rename backend/src/event/{EventProtocolType.ts => EventType.ts} (98%) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 7ed75fd45..720cb2799 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -4,10 +4,10 @@ import { ContributionMessage as DbContributionMessage } from '@entity/Contributi import { Contribution as DbContribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' import Decimal from 'decimal.js-light' -import { EventProtocolType } from './EventProtocolType' +import { EventType } from './EventType' export const Event = ( - type: EventProtocolType, + type: EventType, affectedUser: DbUser, actingUser: DbUser, involvedUser: DbUser | null = null, @@ -33,48 +33,21 @@ export const EVENT_CONTRIBUTION_CREATE = async ( contribution: DbContribution, amount: Decimal, ): Promise => - Event( - EventProtocolType.CONTRIBUTION_CREATE, - user, - user, - null, - null, - contribution, - null, - amount, - ).save() + Event(EventType.CONTRIBUTION_CREATE, user, user, null, null, contribution, null, amount).save() export const EVENT_CONTRIBUTION_DELETE = async ( user: DbUser, contribution: DbContribution, amount: Decimal, ): Promise => - Event( - EventProtocolType.CONTRIBUTION_DELETE, - user, - user, - null, - null, - contribution, - null, - amount, - ).save() + Event(EventType.CONTRIBUTION_DELETE, user, user, null, null, contribution, null, amount).save() export const EVENT_CONTRIBUTION_UPDATE = async ( user: DbUser, contribution: DbContribution, amount: Decimal, ): Promise => - Event( - EventProtocolType.CONTRIBUTION_UPDATE, - user, - user, - null, - null, - contribution, - null, - amount, - ).save() + Event(EventType.CONTRIBUTION_UPDATE, user, user, null, null, contribution, null, amount).save() export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( user: DbUser, @@ -83,7 +56,7 @@ export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_CREATE, + EventType.ADMIN_CONTRIBUTION_CREATE, user, moderator, null, @@ -100,7 +73,7 @@ export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, + EventType.ADMIN_CONTRIBUTION_UPDATE, user, moderator, null, @@ -117,7 +90,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_DELETE, + EventType.ADMIN_CONTRIBUTION_DELETE, user, moderator, null, @@ -134,7 +107,7 @@ export const EVENT_CONTRIBUTION_CONFIRM = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.CONTRIBUTION_CONFIRM, + EventType.CONTRIBUTION_CONFIRM, user, moderator, null, @@ -151,7 +124,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_DENY, + EventType.ADMIN_CONTRIBUTION_DENY, user, moderator, null, @@ -168,7 +141,7 @@ export const EVENT_TRANSACTION_SEND = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.TRANSACTION_SEND, + EventType.TRANSACTION_SEND, user, user, involvedUser, @@ -185,7 +158,7 @@ export const EVENT_TRANSACTION_RECEIVE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.TRANSACTION_RECEIVE, + EventType.TRANSACTION_RECEIVE, user, involvedUser, involvedUser, @@ -196,22 +169,21 @@ export const EVENT_TRANSACTION_RECEIVE = async ( ).save() export const EVENT_LOGIN = async (user: DbUser): Promise => - Event(EventProtocolType.LOGIN, user, user).save() + Event(EventType.LOGIN, user, user).save() export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (user: DbUser): Promise => - Event(EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save() + Event(EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save() export const EVENT_SEND_CONFIRMATION_EMAIL = async (user: DbUser): Promise => - Event(EventProtocolType.SEND_CONFIRMATION_EMAIL, user, user).save() + Event(EventType.SEND_CONFIRMATION_EMAIL, user, user).save() export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async ( user: DbUser, moderator: DbUser, -): Promise => - Event(EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save() +): Promise => Event(EventType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save() export const EVENT_REGISTER = async (user: DbUser): Promise => - Event(EventProtocolType.REGISTER, user, user).save() + Event(EventType.REGISTER, user, user).save() export const EVENT_ACTIVATE_ACCOUNT = async (user: DbUser): Promise => - Event(EventProtocolType.ACTIVATE_ACCOUNT, user, user).save() + Event(EventType.ACTIVATE_ACCOUNT, user, user).save() diff --git a/backend/src/event/EventProtocolType.ts b/backend/src/event/EventType.ts similarity index 98% rename from backend/src/event/EventProtocolType.ts rename to backend/src/event/EventType.ts index 3a4c914c1..360d5efb4 100644 --- a/backend/src/event/EventProtocolType.ts +++ b/backend/src/event/EventType.ts @@ -1,4 +1,4 @@ -export enum EventProtocolType { +export enum EventType { // VISIT_GRADIDO = 'VISIT_GRADIDO', REGISTER = 'REGISTER', REDEEM_REGISTER = 'REDEEM_REGISTER', diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index def4fdf96..cc2115f3f 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -45,7 +45,7 @@ import { Event as DbEvent } from '@entity/Event' import { Contribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' import { User } from '@entity/User' -import { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' import { logger, i18n as localization } from '@test/testSetup' import { UserInputError } from 'apollo-server-express' import { raeuberHotzenplotz } from '@/seeds/users/raeuber-hotzenplotz' @@ -276,7 +276,7 @@ describe('ContributionResolver', () => { it('stores the CONTRIBUTION_CREATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_CREATE, + type: EventType.CONTRIBUTION_CREATE, affectedUserId: bibi.id, actingUserId: bibi.id, involvedContributionId: pendingContribution.data.createContribution.id, @@ -582,7 +582,7 @@ describe('ContributionResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_UPDATE, + type: EventType.CONTRIBUTION_UPDATE, affectedUserId: bibi.id, actingUserId: bibi.id, involvedContributionId: pendingContribution.data.createContribution.id, @@ -813,7 +813,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_DENY event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_DENY, + type: EventType.ADMIN_CONTRIBUTION_DENY, affectedUserId: bibi.id, actingUserId: admin.id, involvedContributionId: contributionToDeny.data.createContribution.id, @@ -941,7 +941,7 @@ describe('ContributionResolver', () => { it('stores the CONTRIBUTION_DELETE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_DELETE, + type: EventType.CONTRIBUTION_DELETE, affectedUserId: bibi.id, actingUserId: bibi.id, involvedContributionId: contributionToDelete.data.createContribution.id, @@ -2032,7 +2032,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_CREATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_CREATE, + type: EventType.ADMIN_CONTRIBUTION_CREATE, affectedUserId: bibi.id, actingUserId: admin.id, amount: expect.decimalEqual(200), @@ -2258,7 +2258,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, + type: EventType.ADMIN_CONTRIBUTION_UPDATE, affectedUserId: creation?.userId, actingUserId: admin.id, amount: 300, @@ -2300,7 +2300,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, + type: EventType.ADMIN_CONTRIBUTION_UPDATE, affectedUserId: creation?.userId, actingUserId: admin.id, amount: expect.decimalEqual(200), @@ -2386,7 +2386,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_DELETE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE, + type: EventType.ADMIN_CONTRIBUTION_DELETE, affectedUserId: creation?.userId, actingUserId: admin.id, involvedContributionId: creation?.id, @@ -2544,7 +2544,7 @@ describe('ContributionResolver', () => { it('stores the CONTRIBUTION_CONFIRM event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_CONFIRM, + type: EventType.CONTRIBUTION_CONFIRM, }), ) }) @@ -2576,7 +2576,7 @@ describe('ContributionResolver', () => { it('stores the SEND_CONFIRMATION_EMAIL event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.SEND_CONFIRMATION_EMAIL, + type: EventType.SEND_CONFIRMATION_EMAIL, }), ) }) diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index 6ddbb8191..590a1fca3 100644 --- a/backend/src/graphql/resolver/TransactionResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionResolver.test.ts @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import Decimal from 'decimal.js-light' -import { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' import { userFactory } from '@/seeds/factory/user' import { confirmContribution, @@ -339,7 +339,7 @@ describe('send coins', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.TRANSACTION_SEND, + type: EventType.TRANSACTION_SEND, affectedUserId: user[1].id, actingUserId: user[1].id, involvedUserId: user[0].id, @@ -357,7 +357,7 @@ describe('send coins', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.TRANSACTION_RECEIVE, + type: EventType.TRANSACTION_RECEIVE, affectedUserId: user[0].id, actingUserId: user[1].id, involvedUserId: user[1].id, diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index e627f4f0f..36a591a49 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -34,7 +34,7 @@ import { contributionLinkFactory } from '@/seeds/factory/contributionLink' import { transactionLinkFactory } from '@/seeds/factory/transactionLink' import { ContributionLink } from '@model/ContributionLink' import { TransactionLink } from '@entity/TransactionLink' -import { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' import { Event as DbEvent } from '@entity/Event' import { validate as validateUUID, version as versionUUID } from 'uuid' import { peterLustig } from '@/seeds/users/peter-lustig' @@ -184,7 +184,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.REGISTER, + type: EventType.REGISTER, affectedUserId: userConatct.user.id, actingUserId: userConatct.user.id, }), @@ -214,7 +214,7 @@ describe('UserResolver', () => { it('stores the SEND_CONFIRMATION_EMAIL event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.SEND_CONFIRMATION_EMAIL, + type: EventType.SEND_CONFIRMATION_EMAIL, affectedUserId: user[0].id, actingUserId: user[0].id, }), @@ -260,7 +260,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, + type: EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, affectedUserId: userConatct.user.id, actingUserId: 0, }), @@ -361,7 +361,7 @@ describe('UserResolver', () => { it('stores the ACTIVATE_ACCOUNT event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ACTIVATE_ACCOUNT, + type: EventType.ACTIVATE_ACCOUNT, affectedUserId: user[0].id, actingUserId: user[0].id, }), @@ -371,7 +371,7 @@ describe('UserResolver', () => { it('stores the REDEEM_REGISTER event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.REDEEM_REGISTER, + type: EventType.REDEEM_REGISTER, affectedUserId: result.data.createUser.id, actingUserId: result.data.createUser.id, involvedContributionId: link.id, @@ -456,7 +456,7 @@ describe('UserResolver', () => { it('stores the REDEEM_REGISTER event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.REDEEM_REGISTER, + type: EventType.REDEEM_REGISTER, affectedUserId: newUser.data.createUser.id, actingUserId: newUser.data.createUser.id, involvedTransactionId: transactionLink.id, @@ -689,7 +689,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.LOGIN, + type: EventType.LOGIN, affectedUserId: userConatct.user.id, actingUserId: userConatct.user.id, }), @@ -938,7 +938,7 @@ describe('UserResolver', () => { it('stores the LOGIN event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.LOGIN, + type: EventType.LOGIN, affectedUserId: user[0].id, actingUserId: user[0].id, }), @@ -1858,7 +1858,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, + type: EventType.ADMIN_SEND_CONFIRMATION_EMAIL, affectedUserId: userConatct.user.id, actingUserId: admin.id, }), diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index d79b0444e..67f263709 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -65,7 +65,7 @@ import { FULL_CREATION_AVAILABLE } from './const/const' import { encryptPassword, verifyPassword } from '@/password/PasswordEncryptor' import { PasswordEncryptionType } from '../enum/PasswordEncryptionType' import LogError from '@/server/LogError' -import { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' // eslint-disable-next-line @typescript-eslint/no-var-requires const sodium = require('sodium-native') @@ -269,7 +269,7 @@ export class UserResolver { const gradidoID = await newGradidoID() const eventRegisterRedeem = Event( - EventProtocolType.REDEEM_REGISTER, + EventType.REDEEM_REGISTER, { id: 0 } as DbUser, { id: 0 } as DbUser, ) From 17992d75ef102ac652bd6da2619d478cb792e0d4 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 6 Mar 2023 16:02:31 +0100 Subject: [PATCH 17/49] separate events into their own file, some nameing conventions --- backend/src/event/EVENT_ACTIVATE_ACCOUNT.ts | 6 + .../event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts | 22 +++ .../event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts | 22 +++ .../event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts | 22 +++ .../event/EVENT_ADMIN_CONTRIBUTION_DENY.ts | 22 +++ .../event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts | 22 +++ .../EVENT_ADMIN_SEND_CONFIRMATION_EMAIL.ts | 8 + .../src/event/EVENT_CONTRIBUTION_CREATE.ts | 12 ++ .../src/event/EVENT_CONTRIBUTION_DELETE.ts | 12 ++ .../src/event/EVENT_CONTRIBUTION_UPDATE.ts | 12 ++ backend/src/event/EVENT_LOGIN.ts | 6 + backend/src/event/EVENT_REGISTER.ts | 6 + ...NT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL.ts | 6 + .../event/EVENT_SEND_CONFIRMATION_EMAIL.ts | 6 + .../src/event/EVENT_TRANSACTION_RECEIVE.ts | 22 +++ backend/src/event/EVENT_TRANSACTION_SEND.ts | 22 +++ backend/src/event/Event.ts | 177 ++---------------- .../resolver/ContributionResolver.test.ts | 2 +- .../graphql/resolver/ContributionResolver.ts | 4 +- .../resolver/TransactionResolver.test.ts | 2 +- .../src/graphql/resolver/UserResolver.test.ts | 2 +- backend/src/graphql/resolver/UserResolver.ts | 2 +- 22 files changed, 252 insertions(+), 165 deletions(-) create mode 100644 backend/src/event/EVENT_ACTIVATE_ACCOUNT.ts create mode 100644 backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts create mode 100644 backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts create mode 100644 backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts create mode 100644 backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts create mode 100644 backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts create mode 100644 backend/src/event/EVENT_ADMIN_SEND_CONFIRMATION_EMAIL.ts create mode 100644 backend/src/event/EVENT_CONTRIBUTION_CREATE.ts create mode 100644 backend/src/event/EVENT_CONTRIBUTION_DELETE.ts create mode 100644 backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts create mode 100644 backend/src/event/EVENT_LOGIN.ts create mode 100644 backend/src/event/EVENT_REGISTER.ts create mode 100644 backend/src/event/EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL.ts create mode 100644 backend/src/event/EVENT_SEND_CONFIRMATION_EMAIL.ts create mode 100644 backend/src/event/EVENT_TRANSACTION_RECEIVE.ts create mode 100644 backend/src/event/EVENT_TRANSACTION_SEND.ts diff --git a/backend/src/event/EVENT_ACTIVATE_ACCOUNT.ts b/backend/src/event/EVENT_ACTIVATE_ACCOUNT.ts new file mode 100644 index 000000000..755cc8fe2 --- /dev/null +++ b/backend/src/event/EVENT_ACTIVATE_ACCOUNT.ts @@ -0,0 +1,6 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ACTIVATE_ACCOUNT = async (user: DbUser): Promise => + Event(EventType.ACTIVATE_ACCOUNT, user, user).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts new file mode 100644 index 000000000..52fd2264f --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_CONFIRM = async ( + user: DbUser, + moderator: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event( + EventType.CONTRIBUTION_CONFIRM, + user, + moderator, + null, + null, + contribution, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts new file mode 100644 index 000000000..c95ba5b9b --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( + user: DbUser, + moderator: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_CREATE, + user, + moderator, + null, + null, + contribution, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts new file mode 100644 index 000000000..30cfd8b93 --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( + user: DbUser, + moderator: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_DELETE, + user, + moderator, + null, + null, + contribution, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts new file mode 100644 index 000000000..d84467f4f --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( + user: DbUser, + moderator: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_DENY, + user, + moderator, + null, + null, + contribution, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts new file mode 100644 index 000000000..3fc17f7d2 --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( + user: DbUser, + moderator: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_UPDATE, + user, + moderator, + null, + null, + contribution, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_SEND_CONFIRMATION_EMAIL.ts b/backend/src/event/EVENT_ADMIN_SEND_CONFIRMATION_EMAIL.ts new file mode 100644 index 000000000..da4907930 --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_SEND_CONFIRMATION_EMAIL.ts @@ -0,0 +1,8 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async ( + user: DbUser, + moderator: DbUser, +): Promise => Event(EventType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts b/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts new file mode 100644 index 000000000..cbc514dc8 --- /dev/null +++ b/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts @@ -0,0 +1,12 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_CONTRIBUTION_CREATE = async ( + user: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event(EventType.CONTRIBUTION_CREATE, user, user, null, null, contribution, null, amount).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts b/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts new file mode 100644 index 000000000..b15e57ea8 --- /dev/null +++ b/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts @@ -0,0 +1,12 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_CONTRIBUTION_DELETE = async ( + user: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event(EventType.CONTRIBUTION_DELETE, user, user, null, null, contribution, null, amount).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts b/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts new file mode 100644 index 000000000..2fb56dc77 --- /dev/null +++ b/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts @@ -0,0 +1,12 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_CONTRIBUTION_UPDATE = async ( + user: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event(EventType.CONTRIBUTION_UPDATE, user, user, null, null, contribution, null, amount).save() diff --git a/backend/src/event/EVENT_LOGIN.ts b/backend/src/event/EVENT_LOGIN.ts new file mode 100644 index 000000000..2c1e763ec --- /dev/null +++ b/backend/src/event/EVENT_LOGIN.ts @@ -0,0 +1,6 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_LOGIN = async (user: DbUser): Promise => + Event(EventType.LOGIN, user, user).save() diff --git a/backend/src/event/EVENT_REGISTER.ts b/backend/src/event/EVENT_REGISTER.ts new file mode 100644 index 000000000..73c6bf4f9 --- /dev/null +++ b/backend/src/event/EVENT_REGISTER.ts @@ -0,0 +1,6 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_REGISTER = async (user: DbUser): Promise => + Event(EventType.REGISTER, user, user).save() diff --git a/backend/src/event/EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL.ts b/backend/src/event/EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL.ts new file mode 100644 index 000000000..3110ece1f --- /dev/null +++ b/backend/src/event/EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL.ts @@ -0,0 +1,6 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (user: DbUser): Promise => + Event(EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save() diff --git a/backend/src/event/EVENT_SEND_CONFIRMATION_EMAIL.ts b/backend/src/event/EVENT_SEND_CONFIRMATION_EMAIL.ts new file mode 100644 index 000000000..b387c0e60 --- /dev/null +++ b/backend/src/event/EVENT_SEND_CONFIRMATION_EMAIL.ts @@ -0,0 +1,6 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_SEND_CONFIRMATION_EMAIL = async (user: DbUser): Promise => + Event(EventType.SEND_CONFIRMATION_EMAIL, user, user).save() diff --git a/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts b/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts new file mode 100644 index 000000000..78f561148 --- /dev/null +++ b/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Transaction as DbTransaction } from '@entity/Transaction' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_TRANSACTION_RECEIVE = async ( + user: DbUser, + involvedUser: DbUser, + transaction: DbTransaction, + amount: Decimal, +): Promise => + Event( + EventType.TRANSACTION_RECEIVE, + user, + involvedUser, + involvedUser, + transaction, + null, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_TRANSACTION_SEND.ts b/backend/src/event/EVENT_TRANSACTION_SEND.ts new file mode 100644 index 000000000..e281b0d30 --- /dev/null +++ b/backend/src/event/EVENT_TRANSACTION_SEND.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Transaction as DbTransaction } from '@entity/Transaction' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_TRANSACTION_SEND = async ( + user: DbUser, + involvedUser: DbUser, + transaction: DbTransaction, + amount: Decimal, +): Promise => + Event( + EventType.TRANSACTION_SEND, + user, + user, + involvedUser, + transaction, + null, + null, + amount, + ).save() diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 720cb2799..163b0b646 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -4,7 +4,7 @@ import { ContributionMessage as DbContributionMessage } from '@entity/Contributi import { Contribution as DbContribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' import Decimal from 'decimal.js-light' -import { EventType } from './EventType' +import { EventType } from './Event' export const Event = ( type: EventType, @@ -28,162 +28,21 @@ export const Event = ( return event } -export const EVENT_CONTRIBUTION_CREATE = async ( - user: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event(EventType.CONTRIBUTION_CREATE, user, user, null, null, contribution, null, amount).save() +export { EventType } from './EventType' -export const EVENT_CONTRIBUTION_DELETE = async ( - user: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event(EventType.CONTRIBUTION_DELETE, user, user, null, null, contribution, null, amount).save() - -export const EVENT_CONTRIBUTION_UPDATE = async ( - user: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event(EventType.CONTRIBUTION_UPDATE, user, user, null, null, contribution, null, amount).save() - -export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( - user: DbUser, - moderator: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event( - EventType.ADMIN_CONTRIBUTION_CREATE, - user, - moderator, - null, - null, - contribution, - null, - amount, - ).save() - -export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( - user: DbUser, - moderator: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event( - EventType.ADMIN_CONTRIBUTION_UPDATE, - user, - moderator, - null, - null, - contribution, - null, - amount, - ).save() - -export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( - user: DbUser, - moderator: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event( - EventType.ADMIN_CONTRIBUTION_DELETE, - user, - moderator, - null, - null, - contribution, - null, - amount, - ).save() - -export const EVENT_CONTRIBUTION_CONFIRM = async ( - user: DbUser, - moderator: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event( - EventType.CONTRIBUTION_CONFIRM, - user, - moderator, - null, - null, - contribution, - null, - amount, - ).save() - -export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( - user: DbUser, - moderator: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event( - EventType.ADMIN_CONTRIBUTION_DENY, - user, - moderator, - null, - null, - contribution, - null, - amount, - ).save() - -export const EVENT_TRANSACTION_SEND = async ( - user: DbUser, - involvedUser: DbUser, - transaction: DbTransaction, - amount: Decimal, -): Promise => - Event( - EventType.TRANSACTION_SEND, - user, - user, - involvedUser, - transaction, - null, - null, - amount, - ).save() - -export const EVENT_TRANSACTION_RECEIVE = async ( - user: DbUser, - involvedUser: DbUser, - transaction: DbTransaction, - amount: Decimal, -): Promise => - Event( - EventType.TRANSACTION_RECEIVE, - user, - involvedUser, - involvedUser, - transaction, - null, - null, - amount, - ).save() - -export const EVENT_LOGIN = async (user: DbUser): Promise => - Event(EventType.LOGIN, user, user).save() - -export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (user: DbUser): Promise => - Event(EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save() - -export const EVENT_SEND_CONFIRMATION_EMAIL = async (user: DbUser): Promise => - Event(EventType.SEND_CONFIRMATION_EMAIL, user, user).save() - -export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async ( - user: DbUser, - moderator: DbUser, -): Promise => Event(EventType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save() - -export const EVENT_REGISTER = async (user: DbUser): Promise => - Event(EventType.REGISTER, user, user).save() - -export const EVENT_ACTIVATE_ACCOUNT = async (user: DbUser): Promise => - Event(EventType.ACTIVATE_ACCOUNT, user, user).save() +export { EVENT_ACTIVATE_ACCOUNT } from './EVENT_ACTIVATE_ACCOUNT' +export { EVENT_ADMIN_CONTRIBUTION_CONFIRM } from './EVENT_ADMIN_CONTRIBUTION_CONFIRM' +export { EVENT_ADMIN_CONTRIBUTION_CREATE } from './EVENT_ADMIN_CONTRIBUTION_CREATE' +export { EVENT_ADMIN_CONTRIBUTION_DELETE } from './EVENT_ADMIN_CONTRIBUTION_DELETE' +export { EVENT_ADMIN_CONTRIBUTION_DENY } from './EVENT_ADMIN_CONTRIBUTION_DENY' +export { EVENT_ADMIN_CONTRIBUTION_UPDATE } from './EVENT_ADMIN_CONTRIBUTION_UPDATE' +export { EVENT_ADMIN_SEND_CONFIRMATION_EMAIL } from './EVENT_ADMIN_SEND_CONFIRMATION_EMAIL' +export { EVENT_CONTRIBUTION_CREATE } from './EVENT_CONTRIBUTION_CREATE' +export { EVENT_CONTRIBUTION_DELETE } from './EVENT_CONTRIBUTION_DELETE' +export { EVENT_CONTRIBUTION_UPDATE } from './EVENT_CONTRIBUTION_UPDATE' +export { EVENT_LOGIN } from './EVENT_LOGIN' +export { EVENT_REGISTER } from './EVENT_REGISTER' +export { EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL } from './EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL' +export { EVENT_SEND_CONFIRMATION_EMAIL } from './EVENT_SEND_CONFIRMATION_EMAIL' +export { EVENT_TRANSACTION_SEND } from './EVENT_TRANSACTION_SEND' +export { EVENT_TRANSACTION_RECEIVE } from './EVENT_TRANSACTION_RECEIVE' diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index cc2115f3f..ac177c228 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -45,7 +45,7 @@ import { Event as DbEvent } from '@entity/Event' import { Contribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' import { User } from '@entity/User' -import { EventType } from '@/event/EventType' +import { EventType } from '@/event/Event' import { logger, i18n as localization } from '@test/testSetup' import { UserInputError } from 'apollo-server-express' import { raeuberHotzenplotz } from '@/seeds/users/raeuber-hotzenplotz' diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 0d27739f9..62c53d993 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -41,7 +41,7 @@ import { EVENT_ADMIN_CONTRIBUTION_CREATE, EVENT_ADMIN_CONTRIBUTION_UPDATE, EVENT_ADMIN_CONTRIBUTION_DELETE, - EVENT_CONTRIBUTION_CONFIRM, + EVENT_ADMIN_CONTRIBUTION_CONFIRM, EVENT_ADMIN_CONTRIBUTION_DENY, } from '@/event/Event' import { calculateDecay } from '@/util/decay' @@ -559,7 +559,7 @@ export class ContributionResolver { await queryRunner.release() } - await EVENT_CONTRIBUTION_CONFIRM(user, moderatorUser, contribution, contribution.amount) + await EVENT_ADMIN_CONTRIBUTION_CONFIRM(user, moderatorUser, contribution, contribution.amount) } finally { releaseLock() } diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index 590a1fca3..d8f249e05 100644 --- a/backend/src/graphql/resolver/TransactionResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionResolver.test.ts @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import Decimal from 'decimal.js-light' -import { EventType } from '@/event/EventType' +import { EventType } from '@/event/Event' import { userFactory } from '@/seeds/factory/user' import { confirmContribution, diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 36a591a49..3bcc229b1 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -34,7 +34,7 @@ import { contributionLinkFactory } from '@/seeds/factory/contributionLink' import { transactionLinkFactory } from '@/seeds/factory/transactionLink' import { ContributionLink } from '@model/ContributionLink' import { TransactionLink } from '@entity/TransactionLink' -import { EventType } from '@/event/EventType' +import { EventType } from '@/event/Event' import { Event as DbEvent } from '@entity/Event' import { validate as validateUUID, version as versionUUID } from 'uuid' import { peterLustig } from '@/seeds/users/peter-lustig' diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 67f263709..1ddcc942a 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -52,6 +52,7 @@ import { RIGHTS } from '@/auth/RIGHTS' import { hasElopageBuys } from '@/util/hasElopageBuys' import { Event, + EventType, EVENT_LOGIN, EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, EVENT_SEND_CONFIRMATION_EMAIL, @@ -65,7 +66,6 @@ import { FULL_CREATION_AVAILABLE } from './const/const' import { encryptPassword, verifyPassword } from '@/password/PasswordEncryptor' import { PasswordEncryptionType } from '../enum/PasswordEncryptionType' import LogError from '@/server/LogError' -import { EventType } from '@/event/EventType' // eslint-disable-next-line @typescript-eslint/no-var-requires const sodium = require('sodium-native') From 630a37cc51d3bb0e919b0fc6fe1fed5b20f66800 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 6 Mar 2023 16:31:28 +0100 Subject: [PATCH 18/49] rename event CONTRIBUTION_CONFIRM to ADMIN_CONTRIBUTION_CONFIRM, clean Eventtypes enum --- .../event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts | 2 +- backend/src/event/EventType.ts | 72 ++++++++++--------- .../resolver/ContributionResolver.test.ts | 2 +- .../0062-event_contribution_confirm.ts | 20 ++++++ 4 files changed, 61 insertions(+), 35 deletions(-) create mode 100644 database/migrations/0062-event_contribution_confirm.ts diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts index 52fd2264f..140ba8497 100644 --- a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts @@ -11,7 +11,7 @@ export const EVENT_ADMIN_CONTRIBUTION_CONFIRM = async ( amount: Decimal, ): Promise => Event( - EventType.CONTRIBUTION_CONFIRM, + EventType.ADMIN_CONTRIBUTION_CONFIRM, user, moderator, null, diff --git a/backend/src/event/EventType.ts b/backend/src/event/EventType.ts index 360d5efb4..241923ffd 100644 --- a/backend/src/event/EventType.ts +++ b/backend/src/event/EventType.ts @@ -1,42 +1,48 @@ +export { EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL } from './EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL' +export { EVENT_SEND_CONFIRMATION_EMAIL } from './EVENT_SEND_CONFIRMATION_EMAIL' +export { EVENT_TRANSACTION_SEND } from './EVENT_TRANSACTION_SEND' +export { EVENT_TRANSACTION_RECEIVE } from './EVENT_TRANSACTION_RECEIVE' + export enum EventType { - // VISIT_GRADIDO = 'VISIT_GRADIDO', - REGISTER = 'REGISTER', - REDEEM_REGISTER = 'REDEEM_REGISTER', - // VERIFY_REDEEM = 'VERIFY_REDEEM', - // INACTIVE_ACCOUNT = 'INACTIVE_ACCOUNT', - SEND_CONFIRMATION_EMAIL = 'SEND_CONFIRMATION_EMAIL', - ADMIN_SEND_CONFIRMATION_EMAIL = 'ADMIN_SEND_CONFIRMATION_EMAIL', - SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = 'SEND_ACCOUNT_MULTIREGISTRATION_EMAIL', - // CONFIRM_EMAIL = 'CONFIRM_EMAIL', - // REGISTER_EMAIL_KLICKTIPP = 'REGISTER_EMAIL_KLICKTIPP', - LOGIN = 'LOGIN', - // LOGOUT = 'LOGOUT', - // REDEEM_LOGIN = 'REDEEM_LOGIN', ACTIVATE_ACCOUNT = 'ACTIVATE_ACCOUNT', - // SEND_FORGOT_PASSWORD_EMAIL = 'SEND_FORGOT_PASSWORD_EMAIL', - // PASSWORD_CHANGE = 'PASSWORD_CHANGE', - // 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', - // 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', - // CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE', - // CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM', - CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE', - CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE', + // TODO CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM', + ADMIN_CONTRIBUTION_CONFIRM = 'ADMIN_CONTRIBUTION_CONFIRM', ADMIN_CONTRIBUTION_CREATE = 'ADMIN_CONTRIBUTION_CREATE', ADMIN_CONTRIBUTION_DELETE = 'ADMIN_CONTRIBUTION_DELETE', ADMIN_CONTRIBUTION_DENY = 'ADMIN_CONTRIBUTION_DENY', ADMIN_CONTRIBUTION_UPDATE = 'ADMIN_CONTRIBUTION_UPDATE', + ADMIN_SEND_CONFIRMATION_EMAIL = 'ADMIN_SEND_CONFIRMATION_EMAIL', + CONTRIBUTION_CREATE = 'CONTRIBUTION_CREATE', + CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE', + CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE', + LOGIN = 'LOGIN', + REGISTER = 'REGISTER', + REDEEM_REGISTER = 'REDEEM_REGISTER', + SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = 'SEND_ACCOUNT_MULTIREGISTRATION_EMAIL', + SEND_CONFIRMATION_EMAIL = 'SEND_CONFIRMATION_EMAIL', + TRANSACTION_SEND = 'TRANSACTION_SEND', + TRANSACTION_RECEIVE = 'TRANSACTION_RECEIVE', + // VISIT_GRADIDO = 'VISIT_GRADIDO', + // VERIFY_REDEEM = 'VERIFY_REDEEM', + // INACTIVE_ACCOUNT = 'INACTIVE_ACCOUNT', + // CONFIRM_EMAIL = 'CONFIRM_EMAIL', + // REGISTER_EMAIL_KLICKTIPP = 'REGISTER_EMAIL_KLICKTIPP', + // LOGOUT = 'LOGOUT', + // REDEEM_LOGIN = 'REDEEM_LOGIN', + // SEND_FORGOT_PASSWORD_EMAIL = 'SEND_FORGOT_PASSWORD_EMAIL', + // PASSWORD_CHANGE = 'PASSWORD_CHANGE', + // SEND_TRANSACTION_SEND_EMAIL = 'SEND_TRANSACTION_SEND_EMAIL', + // SEND_TRANSACTION_RECEIVE_EMAIL = 'SEND_TRANSACTION_RECEIVE_EMAIL', + // TRANSACTION_SEND_REDEEM = 'TRANSACTION_SEND_REDEEM', + // TRANSACTION_REPEATE_REDEEM = 'TRANSACTION_REPEATE_REDEEM', + // TRANSACTION_CREATION = 'TRANSACTION_CREATION', + // TRANSACTION_RECEIVE_REDEEM = 'TRANSACTION_RECEIVE_REDEEM', + // 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_DENY = 'CONTRIBUTION_DENY', + // CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE', + // CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM', // USER_CREATE_CONTRIBUTION_MESSAGE = 'USER_CREATE_CONTRIBUTION_MESSAGE', // ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE', // DELETE_USER = 'DELETE_USER', diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index ac177c228..053e434ea 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -2544,7 +2544,7 @@ describe('ContributionResolver', () => { it('stores the CONTRIBUTION_CONFIRM event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventType.CONTRIBUTION_CONFIRM, + type: EventType.ADMIN_CONTRIBUTION_CONFIRM, }), ) }) diff --git a/database/migrations/0062-event_contribution_confirm.ts b/database/migrations/0062-event_contribution_confirm.ts new file mode 100644 index 000000000..97635b359 --- /dev/null +++ b/database/migrations/0062-event_contribution_confirm.ts @@ -0,0 +1,20 @@ +/* MIGRATION TO RENAME CONTRIBUTION_CONFIRM EVENT + * + * This migration renames the CONTRIBUTION_CONFIRM Event + * to ADMIN_CONTRIBUTION_CONFIRM + */ + +/* 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( + 'UPDATE `events` SET `type` = "ADMIN_CONTRIBUTION_CONFIRM" WHERE `type` = "CONTRIBUTION_CONFIRM";', + ) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn( + 'UPDATE `events` SET `type` = "CONTRIBUTION_CONFIRM" WHERE `type` = "ADMIN_CONTRIBUTION_CONFIRM";', + ) +} From cbec3384e3f65c9635d7096bdef77078ef40c12b Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 6 Mar 2023 16:33:01 +0100 Subject: [PATCH 19/49] update DB_VERSIOn config requirement --- backend/src/config/index.ts | 2 +- dht-node/src/config/index.ts | 2 +- federation/src/config/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 961d83219..9aabaf4ad 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -10,7 +10,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0061-event_refactoring', + DB_VERSION: '0062-event_contribution_confirm', 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 diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index 6ba9493ac..7ca44e52c 100644 --- a/dht-node/src/config/index.ts +++ b/dht-node/src/config/index.ts @@ -3,7 +3,7 @@ import dotenv from 'dotenv' dotenv.config() const constants = { - DB_VERSION: '0061-event_refactoring', + DB_VERSION: '0062-event_contribution_confirm', LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info LOG_LEVEL: process.env.LOG_LEVEL || 'info', diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index 52c73ef0a..b3b529e20 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -11,7 +11,7 @@ Decimal.set({ */ const constants = { - DB_VERSION: '0061-event_refactoring', + DB_VERSION: '0062-event_contribution_confirm', // 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 b604be584780e774789e3a52dd333cb0c6011e4f Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 7 Mar 2023 17:16:53 +0100 Subject: [PATCH 20/49] object as arg for find contributions --- .../graphql/resolver/ContributionResolver.ts | 27 +++++++++---------- .../resolver/util/findContributions.ts | 27 ++++++++++++------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index ab177d759..5946b0237 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -135,15 +135,15 @@ export class ContributionResolver { ): Promise { const user = getUser(context) - const [dbContributions, count] = await findContributions( + const [dbContributions, count] = await findContributions({ order, currentPage, pageSize, - true, - ['messages'], - user.id, + withDeleted: true, + relations: ['messages'], + userId: user.id, statusFilter, - ) + }) return new ContributionListResult( count, dbContributions.map((contribution) => new Contribution(contribution, user)), @@ -158,15 +158,13 @@ export class ContributionResolver { @Arg('statusFilter', () => [ContributionStatus], { nullable: true }) statusFilter?: ContributionStatus[], ): Promise { - const [dbContributions, count] = await findContributions( + const [dbContributions, count] = await findContributions({ order, currentPage, pageSize, - false, - ['user'], - undefined, + relations: ['user'], statusFilter, - ) + }) return new ContributionListResult( count, @@ -386,15 +384,14 @@ export class ContributionResolver { @Arg('statusFilter', () => [ContributionStatus], { nullable: true }) statusFilter?: ContributionStatus[], ): Promise { - const [dbContributions, count] = await findContributions( + const [dbContributions, count] = await findContributions({ order, currentPage, pageSize, - true, - ['user'], - undefined, + withDeleted: true, + relations: ['user'], statusFilter, - ) + }) return new ContributionListResult( count, diff --git a/backend/src/graphql/resolver/util/findContributions.ts b/backend/src/graphql/resolver/util/findContributions.ts index 5201284aa..48f08f041 100644 --- a/backend/src/graphql/resolver/util/findContributions.ts +++ b/backend/src/graphql/resolver/util/findContributions.ts @@ -3,16 +3,24 @@ import { Order } from '@enum/Order' import { Contribution as DbContribution } from '@entity/Contribution' import { In } from '@dbTools/typeorm' +interface FindContributionsOptions { + order: Order + currentPage: number + pageSize: number + withDeleted?: boolean + relations?: string[] + userId?: number + statusFilter?: ContributionStatus[] +} + export const findContributions = async ( - order: Order, - currentPage: number, - pageSize: number, - withDeleted: boolean, - relations: string[], - userId?: number, - statusFilter?: ContributionStatus[], -): Promise<[DbContribution[], number]> => - DbContribution.findAndCount({ + options: FindContributionsOptions, +): Promise<[DbContribution[], number]> => { + const { order, currentPage, pageSize, withDeleted, relations, userId, statusFilter } = { + withDeleted: false, + ...options, + } + return DbContribution.findAndCount({ where: { ...(statusFilter && statusFilter.length && { contributionStatus: In(statusFilter) }), ...(userId && { userId }), @@ -26,3 +34,4 @@ export const findContributions = async ( skip: (currentPage - 1) * pageSize, take: pageSize, }) +} From e48bbd7b47baf70857aac67506018b1aa52e29ae Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 7 Mar 2023 17:33:18 +0100 Subject: [PATCH 21/49] rename admin list all contributions query --- ...ributions.js => adminListContributions.js} | 4 ++-- admin/src/pages/CreationConfirm.spec.js | 20 +++++++++---------- admin/src/pages/CreationConfirm.vue | 10 +++++----- admin/src/pages/Overview.spec.js | 14 ++++++------- admin/src/pages/Overview.vue | 8 ++++---- backend/src/auth/RIGHTS.ts | 2 +- .../resolver/ContributionResolver.test.ts | 20 +++++++++---------- .../graphql/resolver/ContributionResolver.ts | 6 +++--- backend/src/seeds/graphql/queries.ts | 4 ++-- 9 files changed, 44 insertions(+), 44 deletions(-) rename admin/src/graphql/{adminListAllContributions.js => adminListContributions.js} (88%) diff --git a/admin/src/graphql/adminListAllContributions.js b/admin/src/graphql/adminListContributions.js similarity index 88% rename from admin/src/graphql/adminListAllContributions.js rename to admin/src/graphql/adminListContributions.js index cd47cd1d4..7b6848bd5 100644 --- a/admin/src/graphql/adminListAllContributions.js +++ b/admin/src/graphql/adminListContributions.js @@ -1,13 +1,13 @@ import gql from 'graphql-tag' -export const adminListAllContributions = gql` +export const adminListContributions = gql` query ( $currentPage: Int = 1 $pageSize: Int = 25 $order: Order = DESC $statusFilter: [ContributionStatus!] ) { - adminListAllContributions( + adminListContributions( currentPage: $currentPage pageSize: $pageSize order: $order diff --git a/admin/src/pages/CreationConfirm.spec.js b/admin/src/pages/CreationConfirm.spec.js index 87f94e91f..c9d9661c2 100644 --- a/admin/src/pages/CreationConfirm.spec.js +++ b/admin/src/pages/CreationConfirm.spec.js @@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils' import CreationConfirm from './CreationConfirm' import { adminDeleteContribution } from '../graphql/adminDeleteContribution' import { denyContribution } from '../graphql/denyContribution' -import { adminListAllContributions } from '../graphql/adminListAllContributions' +import { adminListContributions } from '../graphql/adminListContributions' import { confirmContribution } from '../graphql/confirmContribution' import { toastErrorSpy, toastSuccessSpy } from '../../test/testSetup' import VueApollo from 'vue-apollo' @@ -38,7 +38,7 @@ const mocks = { const defaultData = () => { return { - adminListAllContributions: { + adminListContributions: { contributionCount: 2, contributionList: [ { @@ -92,14 +92,14 @@ const defaultData = () => { describe('CreationConfirm', () => { let wrapper - const adminListAllContributionsMock = jest.fn() + const adminListContributionsMock = jest.fn() const adminDeleteContributionMock = jest.fn() const adminDenyContributionMock = jest.fn() const confirmContributionMock = jest.fn() mockClient.setRequestHandler( - adminListAllContributions, - adminListAllContributionsMock + adminListContributions, + adminListContributionsMock .mockRejectedValueOnce({ message: 'Ouch!' }) .mockResolvedValue({ data: defaultData() }), ) @@ -337,7 +337,7 @@ describe('CreationConfirm', () => { }) it('refetches contributions with proper filter', () => { - expect(adminListAllContributionsMock).toBeCalledWith({ + expect(adminListContributionsMock).toBeCalledWith({ currentPage: 1, order: 'DESC', pageSize: 25, @@ -352,7 +352,7 @@ describe('CreationConfirm', () => { }) it('refetches contributions with proper filter', () => { - expect(adminListAllContributionsMock).toBeCalledWith({ + expect(adminListContributionsMock).toBeCalledWith({ currentPage: 1, order: 'DESC', pageSize: 25, @@ -368,7 +368,7 @@ describe('CreationConfirm', () => { }) it('refetches contributions with proper filter', () => { - expect(adminListAllContributionsMock).toBeCalledWith({ + expect(adminListContributionsMock).toBeCalledWith({ currentPage: 1, order: 'DESC', pageSize: 25, @@ -384,7 +384,7 @@ describe('CreationConfirm', () => { }) it('refetches contributions with proper filter', () => { - expect(adminListAllContributionsMock).toBeCalledWith({ + expect(adminListContributionsMock).toBeCalledWith({ currentPage: 1, order: 'DESC', pageSize: 25, @@ -400,7 +400,7 @@ describe('CreationConfirm', () => { }) it('refetches contributions with proper filter', () => { - expect(adminListAllContributionsMock).toBeCalledWith({ + expect(adminListContributionsMock).toBeCalledWith({ currentPage: 1, order: 'DESC', pageSize: 25, diff --git a/admin/src/pages/CreationConfirm.vue b/admin/src/pages/CreationConfirm.vue index 55b819268..aad03ffde 100644 --- a/admin/src/pages/CreationConfirm.vue +++ b/admin/src/pages/CreationConfirm.vue @@ -73,7 +73,7 @@