From d38539df7ceda1cfcd6aeaaf2f6035f040d255a9 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 14 Feb 2023 12:09:29 +0100 Subject: [PATCH 01/50] 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/50] 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/50] 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/50] 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/50] 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/50] 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/50] 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/50] 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/50] 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/50] 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/50] 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 9d0a62033101b003d2574c4605612d1d19995a90 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 6 Mar 2023 14:00:54 +0100 Subject: [PATCH 12/50] 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 13/50] 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 14/50] 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 15/50] 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 16/50] 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 4a9f3e666d67f3b166f786fc5412dbe0b1794d46 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 00:02:31 +0100 Subject: [PATCH 17/50] database update, include contribution & transaction link ids --- backend/src/config/index.ts | 2 +- .../entity/0063-event_link_fields/Event.ts | 99 +++++++++++++++++++ database/entity/Event.ts | 2 +- database/migrations/0063-event_link_fields.ts | 29 ++++++ dht-node/src/config/index.ts | 2 +- federation/src/config/index.ts | 2 +- 6 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 database/entity/0063-event_link_fields/Event.ts create mode 100644 database/migrations/0063-event_link_fields.ts diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 9aabaf4ad..ef537d804 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -10,7 +10,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0062-event_contribution_confirm', + DB_VERSION: '0063-event_link_fields', 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/database/entity/0063-event_link_fields/Event.ts b/database/entity/0063-event_link_fields/Event.ts new file mode 100644 index 000000000..bd3616cf8 --- /dev/null +++ b/database/entity/0063-event_link_fields/Event.ts @@ -0,0 +1,99 @@ +import { Contribution } from '../Contribution' +import { ContributionMessage } from '../ContributionMessage' +import { User } from '../User' +import { Transaction } from '../Transaction' +import Decimal from 'decimal.js-light' +import { + BaseEntity, + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + ManyToOne, + JoinColumn, +} from 'typeorm' +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' +import { TransactionLink } from '../TransactionLink' +import { ContributionLink } from '../ContributionLink' + +@Entity('events') +export class Event extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' }) + type: string + + @CreateDateColumn({ + name: 'created_at', + type: 'datetime', + default: () => 'CURRENT_TIMESTAMP()', + nullable: false, + }) + createdAt: Date + + @Column({ name: 'affected_user_id', unsigned: true, nullable: false }) + affectedUserId: number + + @ManyToOne(() => User) + @JoinColumn({ name: 'affected_user_id', referencedColumnName: 'id' }) + affectedUser: User + + @Column({ name: 'acting_user_id', unsigned: true, nullable: false }) + actingUserId: number + + @ManyToOne(() => User) + @JoinColumn({ name: 'acting_user_id', referencedColumnName: 'id' }) + actingUser: User + + @Column({ name: 'involved_user_id', type: 'int', unsigned: true, nullable: true }) + involvedUserId: number | null + + @ManyToOne(() => User) + @JoinColumn({ name: 'involved_user_id', referencedColumnName: 'id' }) + involvedUser: User | null + + @Column({ name: 'involved_transaction_id', type: 'int', unsigned: true, nullable: true }) + involvedTransactionId: number | null + + @ManyToOne(() => Transaction) + @JoinColumn({ name: 'involved_transaction_id', referencedColumnName: 'id' }) + involvedTransaction: Transaction | null + + @Column({ name: 'involved_contribution_id', type: 'int', unsigned: true, nullable: true }) + involvedContributionId: number | null + + @ManyToOne(() => Contribution) + @JoinColumn({ name: 'involved_contribution_id', referencedColumnName: 'id' }) + involvedContribution: Contribution | null + + @Column({ name: 'involved_contribution_message_id', type: 'int', unsigned: true, nullable: true }) + involvedContributionMessageId: number | null + + @ManyToOne(() => ContributionMessage) + @JoinColumn({ name: 'involved_contribution_message_id', referencedColumnName: 'id' }) + involvedContributionMessage: ContributionMessage | null + + @Column({ name: 'involved_transaction_link_id', type: 'int', unsigned: true, nullable: true }) + involvedTransactionLinkId: number | null + + @ManyToOne(() => TransactionLink) + @JoinColumn({ name: 'involved_transaction_link_id', referencedColumnName: 'id' }) + involvedTransactionLink: TransactionLink | null + + @Column({ name: 'involved_contribution_link_id', type: 'int', unsigned: true, nullable: true }) + involvedContributionLinkId: number | null + + @ManyToOne(() => ContributionLink) + @JoinColumn({ name: 'involved_contribution_link_id', referencedColumnName: 'id' }) + involvedContributionLink: ContributionLink | null + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: true, + transformer: DecimalTransformer, + }) + amount: Decimal | null +} diff --git a/database/entity/Event.ts b/database/entity/Event.ts index e53085f2f..04cbaf458 100644 --- a/database/entity/Event.ts +++ b/database/entity/Event.ts @@ -1 +1 @@ -export { Event } from './0061-event_refactoring/Event' +export { Event } from './0063-event_link_fields/Event' diff --git a/database/migrations/0063-event_link_fields.ts b/database/migrations/0063-event_link_fields.ts new file mode 100644 index 000000000..3b383ad07 --- /dev/null +++ b/database/migrations/0063-event_link_fields.ts @@ -0,0 +1,29 @@ +/* MIGRATION TO ADD LINK ID FIELDS TO EVENT TABLE + * + * This migration add two fields to store a TransactionLinkId and a ContributionLinkId + * in the event table. Furthermore the event `REDEEM_REGISTER` is rewritten to use the + * new fields. + */ + +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn( + 'ALTER TABLE `events` ADD COLUMN `involved_transaction_link_id` int(10) unsigned DEFAULT NULL AFTER `involved_contribution_message_id`;', + ) + await queryFn( + 'ALTER TABLE `events` ADD COLUMN `involved_contribution_link_id` int(10) unsigned DEFAULT NULL AFTER `involved_transaction_link_id`;', + ) + await queryFn( + 'UPDATE `events` SET `involved_transaction_link_id` = `involved_transaction_id`, `involved_transaction_id` = NULL, `involved_contribution_link_id` = `involved_contribution_id`, `involved_contribution_id` = NULL WHERE `type` = "REDEEM_REGISTER";', + ) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn( + 'UPDATE `events` SET `involved_transaction_id` = `involved_transaction_link_id`, `involved_contribution_id` = `involved_contribution_link_id` WHERE `type` = "REDEEM_REGISTER";', + ) + await queryFn('ALTER TABLE `events` DROP COLUMN `involved_contribution_link_id`;') + await queryFn('ALTER TABLE `events` DROP COLUMN `involved_transaction_link_id`;') +} diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index 7ca44e52c..78f2b162c 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: '0062-event_contribution_confirm', + DB_VERSION: '0063-event_link_fields', 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 b3b529e20..61204ca37 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -11,7 +11,7 @@ Decimal.set({ */ const constants = { - DB_VERSION: '0062-event_contribution_confirm', + DB_VERSION: '0063-event_link_fields', // 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 e3377652d4aea0302ce00ab5fbb79f42d9d1b2b9 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 00:04:08 +0100 Subject: [PATCH 18/50] fix redeem event, new events for contribution links, refactor contribution links resolver --- .../event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts | 2 ++ .../event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts | 2 ++ .../event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts | 2 ++ .../event/EVENT_ADMIN_CONTRIBUTION_DENY.ts | 2 ++ .../EVENT_ADMIN_CONTRIBUTION_LINK_CREATE.ts | 23 +++++++++++++ .../EVENT_ADMIN_CONTRIBUTION_LINK_DELETE.ts | 20 +++++++++++ .../EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE.ts | 23 +++++++++++++ .../event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts | 2 ++ .../src/event/EVENT_CONTRIBUTION_CREATE.ts | 13 +++++++- .../src/event/EVENT_CONTRIBUTION_DELETE.ts | 13 +++++++- .../src/event/EVENT_CONTRIBUTION_UPDATE.ts | 13 +++++++- .../src/event/EVENT_TRANSACTION_RECEIVE.ts | 2 ++ backend/src/event/EVENT_TRANSACTION_SEND.ts | 2 ++ backend/src/event/Event.ts | 13 ++++++-- backend/src/event/EventType.ts | 5 +-- .../resolver/ContributionLinkResolver.ts | 33 ++++++++++++++----- backend/src/graphql/resolver/UserResolver.ts | 4 +-- 17 files changed, 156 insertions(+), 18 deletions(-) create mode 100644 backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_CREATE.ts create mode 100644 backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_DELETE.ts create mode 100644 backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE.ts diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts index 140ba8497..c85a7a12c 100644 --- a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts @@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_CONFIRM = async ( null, contribution, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts index c95ba5b9b..a10ff1a35 100644 --- a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts @@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( null, contribution, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts index 30cfd8b93..d3dd5508e 100644 --- a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts @@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( null, contribution, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts index d84467f4f..5f1203766 100644 --- a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts @@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( null, contribution, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_CREATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_CREATE.ts new file mode 100644 index 000000000..2ead791ed --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_CREATE.ts @@ -0,0 +1,23 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_LINK_CREATE = async ( + moderator: DbUser, + contributionLink: DbContributionLink, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_LINK_CREATE, + { id: 0 } as DbUser, + moderator, + null, + null, + null, + null, + null, + contributionLink, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_DELETE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_DELETE.ts new file mode 100644 index 000000000..b5816e45d --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_DELETE.ts @@ -0,0 +1,20 @@ +import { User as DbUser } from '@entity/User' +import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_LINK_DELETE = async ( + moderator: DbUser, + contributionLink: DbContributionLink, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_LINK_DELETE, + { id: 0 } as DbUser, + moderator, + null, + null, + null, + null, + null, + contributionLink, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE.ts new file mode 100644 index 000000000..6824833b8 --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE.ts @@ -0,0 +1,23 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE = async ( + moderator: DbUser, + contributionLink: DbContributionLink, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_LINK_UPDATE, + { id: 0 } as DbUser, + moderator, + null, + null, + null, + null, + null, + contributionLink, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts index 3fc17f7d2..60315249a 100644 --- a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts @@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( null, contribution, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts b/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts index cbc514dc8..50cdbcd18 100644 --- a/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts +++ b/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts @@ -9,4 +9,15 @@ export const EVENT_CONTRIBUTION_CREATE = async ( contribution: DbContribution, amount: Decimal, ): Promise => - Event(EventType.CONTRIBUTION_CREATE, user, user, null, null, contribution, null, amount).save() + Event( + EventType.CONTRIBUTION_CREATE, + user, + user, + null, + null, + contribution, + null, + null, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts b/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts index b15e57ea8..eab04bf47 100644 --- a/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts +++ b/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts @@ -9,4 +9,15 @@ export const EVENT_CONTRIBUTION_DELETE = async ( contribution: DbContribution, amount: Decimal, ): Promise => - Event(EventType.CONTRIBUTION_DELETE, user, user, null, null, contribution, null, amount).save() + Event( + EventType.CONTRIBUTION_DELETE, + user, + user, + null, + null, + contribution, + null, + null, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts b/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts index 2fb56dc77..82f14edd6 100644 --- a/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts +++ b/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts @@ -9,4 +9,15 @@ export const EVENT_CONTRIBUTION_UPDATE = async ( contribution: DbContribution, amount: Decimal, ): Promise => - Event(EventType.CONTRIBUTION_UPDATE, user, user, null, null, contribution, null, amount).save() + Event( + EventType.CONTRIBUTION_UPDATE, + user, + user, + null, + null, + contribution, + null, + null, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts b/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts index 78f561148..acb2f5881 100644 --- a/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts +++ b/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts @@ -18,5 +18,7 @@ export const EVENT_TRANSACTION_RECEIVE = async ( transaction, null, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_TRANSACTION_SEND.ts b/backend/src/event/EVENT_TRANSACTION_SEND.ts index e281b0d30..a342cb0aa 100644 --- a/backend/src/event/EVENT_TRANSACTION_SEND.ts +++ b/backend/src/event/EVENT_TRANSACTION_SEND.ts @@ -18,5 +18,7 @@ export const EVENT_TRANSACTION_SEND = async ( transaction, null, null, + null, + null, amount, ).save() diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 163b0b646..2e7cca6af 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -1,8 +1,10 @@ import { Event as DbEvent } from '@entity/Event' import { User as DbUser } from '@entity/User' -import { ContributionMessage as DbContributionMessage } from '@entity/ContributionMessage' -import { Contribution as DbContribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' +import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink' +import { Contribution as DbContribution } from '@entity/Contribution' +import { ContributionMessage as DbContributionMessage } from '@entity/ContributionMessage' +import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' import Decimal from 'decimal.js-light' import { EventType } from './Event' @@ -14,6 +16,8 @@ export const Event = ( involvedTransaction: DbTransaction | null = null, involvedContribution: DbContribution | null = null, involvedContributionMessage: DbContributionMessage | null = null, + involvedTransactionLink: DbTransactionLink | null = null, + involvedContributionLink: DbContributionLink | null = null, amount: Decimal | null = null, ): DbEvent => { const event = new DbEvent() @@ -24,6 +28,8 @@ export const Event = ( event.involvedTransaction = involvedTransaction event.involvedContribution = involvedContribution event.involvedContributionMessage = involvedContributionMessage + event.involvedTransactionLink = involvedTransactionLink + event.involvedContributionLink = involvedContributionLink event.amount = amount return event } @@ -36,6 +42,9 @@ export { EVENT_ADMIN_CONTRIBUTION_CREATE } from './EVENT_ADMIN_CONTRIBUTION_CREA 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_CONTRIBUTION_LINK_CREATE } from './EVENT_ADMIN_CONTRIBUTION_LINK_CREATE' +export { EVENT_ADMIN_CONTRIBUTION_LINK_DELETE } from './EVENT_ADMIN_CONTRIBUTION_LINK_DELETE' +export { EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE } from './EVENT_ADMIN_CONTRIBUTION_LINK_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' diff --git a/backend/src/event/EventType.ts b/backend/src/event/EventType.ts index 241923ffd..e40aa91ab 100644 --- a/backend/src/event/EventType.ts +++ b/backend/src/event/EventType.ts @@ -11,6 +11,9 @@ export enum EventType { ADMIN_CONTRIBUTION_DELETE = 'ADMIN_CONTRIBUTION_DELETE', ADMIN_CONTRIBUTION_DENY = 'ADMIN_CONTRIBUTION_DENY', ADMIN_CONTRIBUTION_UPDATE = 'ADMIN_CONTRIBUTION_UPDATE', + ADMIN_CONTRIBUTION_LINK_CREATE = 'ADMIN_CONTRIBUTION_LINK_CREATE', + ADMIN_CONTRIBUTION_LINK_DELETE = 'ADMIN_CONTRIBUTION_LINK_DELETE', + ADMIN_CONTRIBUTION_LINK_UPDATE = 'ADMIN_CONTRIBUTION_LINK_UPDATE', ADMIN_SEND_CONFIRMATION_EMAIL = 'ADMIN_SEND_CONFIRMATION_EMAIL', CONTRIBUTION_CREATE = 'CONTRIBUTION_CREATE', CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE', @@ -40,8 +43,6 @@ export enum EventType { // 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', diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.ts b/backend/src/graphql/resolver/ContributionLinkResolver.ts index d3c77cb82..850117084 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.ts @@ -1,5 +1,5 @@ import Decimal from 'decimal.js-light' -import { Resolver, Args, Arg, Authorized, Mutation, Query, Int } from 'type-graphql' +import { Resolver, Args, Arg, Authorized, Mutation, Query, Int, Ctx } from 'type-graphql' import { MoreThan, IsNull } from '@dbTools/typeorm' import { @@ -21,6 +21,12 @@ import Paginated from '@arg/Paginated' // TODO: this is a strange construct import { transactionLinkCode as contributionLinkCode } from './TransactionLinkResolver' import LogError from '@/server/LogError' +import { Context, getUser } from '@/server/context' +import { + EVENT_ADMIN_CONTRIBUTION_LINK_CREATE, + EVENT_ADMIN_CONTRIBUTION_LINK_DELETE, + EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE, +} from '@/event/Event' @Resolver() export class ContributionLinkResolver { @@ -38,6 +44,7 @@ export class ContributionLinkResolver { maxAmountPerMonth, maxPerCycle, }: ContributionLinkArgs, + @Ctx() context: Context, ): Promise { isStartEndDateValid(validFrom, validTo) if (name.length < CONTRIBUTIONLINK_NAME_MIN_CHARS) { @@ -68,7 +75,8 @@ export class ContributionLinkResolver { dbContributionLink.maxAmountPerMonth = maxAmountPerMonth dbContributionLink.maxPerCycle = maxPerCycle await dbContributionLink.save() - logger.debug(`createContributionLink successful!`) + await EVENT_ADMIN_CONTRIBUTION_LINK_CREATE(getUser(context), dbContributionLink, amount) + return new ContributionLink(dbContributionLink) } @@ -92,15 +100,18 @@ export class ContributionLinkResolver { @Authorized([RIGHTS.ADMIN_DELETE_CONTRIBUTION_LINK]) @Mutation(() => Date, { nullable: true }) - async deleteContributionLink(@Arg('id', () => Int) id: number): Promise { - const contributionLink = await DbContributionLink.findOne(id) - if (!contributionLink) { + async deleteContributionLink( + @Arg('id', () => Int) id: number, + @Ctx() context: Context, + ): Promise { + const dbContributionLink = await DbContributionLink.findOne(id) + if (!dbContributionLink) { throw new LogError('Contribution Link not found', id) } - await contributionLink.softRemove() - logger.debug(`deleteContributionLink successful!`) - const newContributionLink = await DbContributionLink.findOne({ id }, { withDeleted: true }) - return newContributionLink ? newContributionLink.deletedAt : null + await dbContributionLink.softRemove() + await EVENT_ADMIN_CONTRIBUTION_LINK_DELETE(getUser(context), dbContributionLink) + + return true } @Authorized([RIGHTS.ADMIN_UPDATE_CONTRIBUTION_LINK]) @@ -118,6 +129,7 @@ export class ContributionLinkResolver { maxPerCycle, }: ContributionLinkArgs, @Arg('id', () => Int) id: number, + @Ctx() context: Context, ): Promise { const dbContributionLink = await DbContributionLink.findOne(id) if (!dbContributionLink) { @@ -133,6 +145,9 @@ export class ContributionLinkResolver { dbContributionLink.maxPerCycle = maxPerCycle await dbContributionLink.save() logger.debug(`updateContributionLink successful!`) + + await EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE(getUser(context), dbContributionLink, amount) + return new ContributionLink(dbContributionLink) } } diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 1ddcc942a..d89e1c498 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -290,7 +290,7 @@ export class UserResolver { if (contributionLink) { dbUser.contributionLinkId = contributionLink.id // TODO this is so wrong - eventRegisterRedeem.involvedContribution = { id: contributionLink.id } as DbContribution + eventRegisterRedeem.involvedContributionLink = contributionLink } } else { const transactionLink = await DbTransactionLink.findOne({ code: redeemCode }) @@ -298,7 +298,7 @@ export class UserResolver { if (transactionLink) { dbUser.referrerId = transactionLink.userId // TODO this is so wrong - eventRegisterRedeem.involvedTransaction = { id: transactionLink.id } as DbTransaction + eventRegisterRedeem.involvedTransactionLink = transactionLink } } } From 49612871a310a76d040b7546ebca3ed84ca558cc Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 00:05:14 +0100 Subject: [PATCH 19/50] removed fixed todos --- backend/src/graphql/resolver/UserResolver.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index d89e1c498..f7d6be9fb 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -289,7 +289,6 @@ export class UserResolver { logger.info('redeemCode found contributionLink=' + contributionLink) if (contributionLink) { dbUser.contributionLinkId = contributionLink.id - // TODO this is so wrong eventRegisterRedeem.involvedContributionLink = contributionLink } } else { @@ -297,7 +296,6 @@ export class UserResolver { logger.info('redeemCode found transactionLink=' + transactionLink) if (transactionLink) { dbUser.referrerId = transactionLink.userId - // TODO this is so wrong eventRegisterRedeem.involvedTransactionLink = transactionLink } } From 8399363f05393c9a4604794b60890f5699a3d210 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 00:11:56 +0100 Subject: [PATCH 20/50] removed comments of already implemented event types --- backend/src/event/EventType.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/backend/src/event/EventType.ts b/backend/src/event/EventType.ts index e40aa91ab..5d69eba2d 100644 --- a/backend/src/event/EventType.ts +++ b/backend/src/event/EventType.ts @@ -49,9 +49,4 @@ export enum EventType { // DELETE_USER = 'DELETE_USER', // UNDELETE_USER = 'UNDELETE_USER', // CHANGE_USER_ROLE = 'CHANGE_USER_ROLE', - // ADMIN_UPDATE_CONTRIBUTION = 'ADMIN_UPDATE_CONTRIBUTION', - // ADMIN_DELETE_CONTRIBUTION = 'ADMIN_DELETE_CONTRIBUTION', - // CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', - // DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK', - // UPDATE_CONTRIBUTION_LINK = 'UPDATE_CONTRIBUTION_LINK', } From 3979e84a8c590c73973c74d06064fec15f2151ee Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 00:14:52 +0100 Subject: [PATCH 21/50] fixed lint --- backend/src/graphql/resolver/UserResolver.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index f7d6be9fb..2cd40938f 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -16,9 +16,7 @@ import { getConnection, getCustomRepository, IsNull, Not } from '@dbTools/typeor import { User as DbUser } from '@entity/User' import { UserContact as DbUserContact } from '@entity/UserContact' import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink' -import { Transaction as DbTransaction } from '@entity/Transaction' import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' -import { Contribution as DbContribution } from '@entity/Contribution' import { UserRepository } from '@repository/User' import { User } from '@model/User' From dac2cf7bba779ec800a4272d63b569a9fed2bfc0 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 11:27:47 +0100 Subject: [PATCH 22/50] fixed tests --- backend/src/graphql/resolver/ContributionLinkResolver.test.ts | 2 +- backend/src/graphql/resolver/ContributionLinkResolver.ts | 2 +- backend/src/graphql/resolver/UserResolver.test.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts index 62f273829..42966fa82 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts @@ -560,7 +560,7 @@ describe('Contribution Links', () => { ).resolves.toEqual( expect.objectContaining({ data: { - deleteContributionLink: expect.any(String), + deleteContributionLink: true, }, }), ) diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.ts b/backend/src/graphql/resolver/ContributionLinkResolver.ts index 850117084..3a8c6c85b 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.ts @@ -99,7 +99,7 @@ export class ContributionLinkResolver { } @Authorized([RIGHTS.ADMIN_DELETE_CONTRIBUTION_LINK]) - @Mutation(() => Date, { nullable: true }) + @Mutation(() => Boolean, { nullable: true }) async deleteContributionLink( @Arg('id', () => Int) id: number, @Ctx() context: Context, diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 3bcc229b1..b382b2627 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -374,7 +374,7 @@ describe('UserResolver', () => { type: EventType.REDEEM_REGISTER, affectedUserId: result.data.createUser.id, actingUserId: result.data.createUser.id, - involvedContributionId: link.id, + involvedContributionLinkId: link.id, }), ) }) @@ -459,7 +459,7 @@ describe('UserResolver', () => { type: EventType.REDEEM_REGISTER, affectedUserId: newUser.data.createUser.id, actingUserId: newUser.data.createUser.id, - involvedTransactionId: transactionLink.id, + involvedTransactionLinkId: transactionLink.id, }), ) }) From ccccf75fa5dd53afa3be60f867a681ea3d2d5ddb Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 11:32:39 +0100 Subject: [PATCH 23/50] removed automatically included files --- backend/src/event/EventType.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/backend/src/event/EventType.ts b/backend/src/event/EventType.ts index 5d69eba2d..b219a49ba 100644 --- a/backend/src/event/EventType.ts +++ b/backend/src/event/EventType.ts @@ -1,8 +1,3 @@ -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 { ACTIVATE_ACCOUNT = 'ACTIVATE_ACCOUNT', // TODO CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM', From ff9df408e30d76705bf494fe9099c9c7150564da Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 11:34:38 +0100 Subject: [PATCH 24/50] corrected test name --- backend/src/graphql/resolver/ContributionLinkResolver.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts index 42966fa82..3c95db047 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts @@ -554,7 +554,7 @@ describe('Contribution Links', () => { linkId = links.data.listContributionLinks.links[0].id }) - it('returns a date string', async () => { + it('returns true', async () => { await expect( mutate({ mutation: deleteContributionLink, variables: { id: linkId } }), ).resolves.toEqual( From fa2916ef4df08ab62fae31b7e3069cc6c0de3cf8 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 11:41:59 +0100 Subject: [PATCH 25/50] test for first event in ContributionLinkResolver --- .../resolver/ContributionLinkResolver.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts index 3c95db047..ed56fd5af 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts @@ -15,6 +15,8 @@ import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg' import { peterLustig } from '@/seeds/users/peter-lustig' import { userFactory } from '@/seeds/factory/user' import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' +import { EventType } from '@/event/Event' +import { Event as DbEvent } from '@entity/Event' let mutate: any, query: any, con: any let testEnv: any @@ -566,6 +568,17 @@ describe('Contribution Links', () => { ) }) + it('stores the ADMIN_CONTRIBUTION_LINK_DELETE event in the database', async () => { + await expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.ADMIN_CONTRIBUTION_LINK_DELETE, + affectedUserId: 0, + actingUserId: expect.any(Number), + involvedContributionLinkId: linkId, + }), + ) + }) + it('does not list this contribution link anymore', async () => { await expect(query({ query: listContributionLinks })).resolves.toEqual( expect.objectContaining({ From 7583619058fff4eb3baf2f26c612bb4b32ef41c7 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 11:49:04 +0100 Subject: [PATCH 26/50] test for the other two events --- .../resolver/ContributionLinkResolver.test.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts index ed56fd5af..3462a05a9 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts @@ -247,6 +247,18 @@ describe('Contribution Links', () => { ) }) + it('stores the ADMIN_CONTRIBUTION_LINK_CREATE event in the database', async () => { + await expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.ADMIN_CONTRIBUTION_LINK_CREATE, + affectedUserId: 0, + actingUserId: expect.any(Number), + involvedContributionLinkId: expect.any(Number), + amount: expect.decimalEqual(200), + }), + ) + }) + it('returns an error if missing startDate', async () => { jest.clearAllMocks() await expect( @@ -529,6 +541,18 @@ describe('Contribution Links', () => { }), ) }) + + it('stores the ADMIN_CONTRIBUTION_LINK_UPDATE event in the database', async () => { + await expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.ADMIN_CONTRIBUTION_LINK_UPDATE, + affectedUserId: 0, + actingUserId: expect.any(Number), + involvedContributionLinkId: expect.any(Number), + amount: expect.decimalEqual(400), + }), + ) + }) }) }) From d1f72891e03dec94a15b10ec18c3347204d26746 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 12:00:09 +0100 Subject: [PATCH 27/50] increase coverage requirement to 81% in backend --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5eadf1e94..a02aa4b5b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -427,7 +427,7 @@ jobs: report_name: Coverage Backend type: lcov result_path: ./backend/coverage/lcov.info - min_coverage: 80 + min_coverage: 81 token: ${{ github.token }} ########################################################################## From cf0af5dc856e4725c4b546b7e74e0f6830a7421c Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 12:35:40 +0100 Subject: [PATCH 28/50] missing change for changed event database model --- database/entity/0063-event_link_fields/Event.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/entity/0063-event_link_fields/Event.ts b/database/entity/0063-event_link_fields/Event.ts index bd3616cf8..dc7fa776c 100644 --- a/database/entity/0063-event_link_fields/Event.ts +++ b/database/entity/0063-event_link_fields/Event.ts @@ -27,7 +27,7 @@ export class Event extends BaseEntity { @CreateDateColumn({ name: 'created_at', type: 'datetime', - default: () => 'CURRENT_TIMESTAMP()', + default: () => 'CURRENT_TIMESTAMP(3)', nullable: false, }) createdAt: Date From d65948ed81738801d38e5540218ff4224fd436b9 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 12:47:44 +0100 Subject: [PATCH 29/50] cleanup --- backend/src/graphql/resolver/ContributionLinkResolver.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.ts b/backend/src/graphql/resolver/ContributionLinkResolver.ts index 3a8c6c85b..b5f423bda 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.ts @@ -144,8 +144,6 @@ export class ContributionLinkResolver { dbContributionLink.maxAmountPerMonth = maxAmountPerMonth dbContributionLink.maxPerCycle = maxPerCycle await dbContributionLink.save() - logger.debug(`updateContributionLink successful!`) - await EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE(getUser(context), dbContributionLink, amount) return new ContributionLink(dbContributionLink) From cdb7fe32c8f3ab0f303f5f5370f1d617c878a173 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Mar 2023 13:16:27 +0100 Subject: [PATCH 30/50] lint fixes --- backend/src/graphql/resolver/ContributionLinkResolver.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.ts b/backend/src/graphql/resolver/ContributionLinkResolver.ts index b5f423bda..6c396e73d 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.ts @@ -12,7 +12,6 @@ import { isStartEndDateValid } from './util/creations' import { ContributionLinkList } from '@model/ContributionLinkList' import { ContributionLink } from '@model/ContributionLink' import ContributionLinkArgs from '@arg/ContributionLinkArgs' -import { backendLogger as logger } from '@/server/logger' import { RIGHTS } from '@/auth/RIGHTS' import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' import { Order } from '@enum/Order' From b604be584780e774789e3a52dd333cb0c6011e4f Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 7 Mar 2023 17:16:53 +0100 Subject: [PATCH 31/50] 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 32/50] 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 @@