From 7fb996b18c043aa781da0e40c87b1eb91b96ddd2 Mon Sep 17 00:00:00 2001 From: Sarah Sporck Date: Mon, 12 Dec 2022 16:29:05 +0100 Subject: [PATCH 1/2] add creatorId --- .../ehrenamtskarte/backend/verification/database/Schema.kt | 3 +++ .../backend/verification/database/repos/CardRepository.kt | 4 +++- .../verification/webservice/schema/CardMutationService.kt | 4 ++-- docs/graphql_generation.md | 3 +-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/Schema.kt b/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/Schema.kt index fdb13c0b6..3904e93c0 100644 --- a/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/Schema.kt +++ b/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/Schema.kt @@ -1,5 +1,6 @@ package app.ehrenamtskarte.backend.verification.database +import app.ehrenamtskarte.backend.auth.database.Administrators import app.ehrenamtskarte.backend.regions.database.Regions import org.jetbrains.exposed.dao.IntEntity import org.jetbrains.exposed.dao.IntEntityClass @@ -19,6 +20,7 @@ object Cards : IntIdTable() { val issueDate = timestamp("issueDate").defaultExpression(CurrentTimestamp()) val revoked = bool("revoked") val regionId = reference("regionId", Regions) + val creatorId = reference("creatorId", Administrators) val cardDetailsHash = binary("cardDetailsHash", CARD_DETAILS_HASH_LENGTH).uniqueIndex() } @@ -31,4 +33,5 @@ class CardEntity(id: EntityID) : IntEntity(id) { var revoked by Cards.revoked var cardDetailsHash by Cards.cardDetailsHash var regionId by Cards.regionId + var creatorId by Cards.creatorId } diff --git a/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/repos/CardRepository.kt b/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/repos/CardRepository.kt index a5cb68e23..406861cd9 100644 --- a/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/repos/CardRepository.kt +++ b/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/repos/CardRepository.kt @@ -1,5 +1,6 @@ package app.ehrenamtskarte.backend.verification.database.repos +import app.ehrenamtskarte.backend.auth.database.Administrators import app.ehrenamtskarte.backend.projects.database.Projects import app.ehrenamtskarte.backend.regions.database.Regions import app.ehrenamtskarte.backend.verification.database.CardEntity @@ -19,13 +20,14 @@ object CardRepository { return if (query == null) null else CardEntity.wrapRow(query) } - fun insert(cardDetailsHash: ByteArray, totpSecret: ByteArray, expirationDay: Long?, regionId: Int) = + fun insert(cardDetailsHash: ByteArray, totpSecret: ByteArray, expirationDay: Long?, regionId: Int, creatorId: Int) = CardEntity.new { this.cardDetailsHash = cardDetailsHash this.totpSecret = totpSecret this.expirationDay = expirationDay this.issueDate = Instant.now() this.regionId = EntityID(regionId, Regions) + this.creatorId = EntityID(creatorId, Administrators) this.revoked = false } } diff --git a/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/webservice/schema/CardMutationService.kt b/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/webservice/schema/CardMutationService.kt index 116980ddd..5e8659115 100644 --- a/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/webservice/schema/CardMutationService.kt +++ b/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/webservice/schema/CardMutationService.kt @@ -23,12 +23,12 @@ class CardMutationService { if (!Authorizer.mayCreateCardInRegion(user, targetedRegionId)) { throw UnauthorizedException() } - CardRepository.insert( Base64.decode(card.cardDetailsHashBase64), Base64.decode(card.totpSecretBase64), card.cardExpirationDay, - card.regionId + card.regionId, + user.id.value ) } return true diff --git a/docs/graphql_generation.md b/docs/graphql_generation.md index cf720b0ce..298159eda 100644 --- a/docs/graphql_generation.md +++ b/docs/graphql_generation.md @@ -6,6 +6,5 @@ Queries are specified in [frontend/graphql_queries](../frontend/graphql_queries) ## Generate API Files 1. If schema changed: Generate updated GraphQL schema into [schema.graphql](../frontend/schema.graphql) Run "Generate GraphQL" in Intellij (or `./gradlew run --args="graphql-export ../specs/backend-api.graphql"` in the backend folder) -2. Run "Generate GraphQL Flutter Client" (or first copy `backend/schema.graphql` to `frontend/schema.graphql` and - run ```flutter pub run build_runner build``` in the `frontend` directory +2. Run any "Select" configuration in IntelliJ e.g. "Select bayern" (or `flutter pub run build_runner build` in the `frontend` directory) 3. Run "Generate GraphQL React Client" (or `npm generate-graphql` in the `administration` directory) From 0e6342a65f98bd7b444d41f62d8aecb37a8fa974 Mon Sep 17 00:00:00 2001 From: Sarah Sporck Date: Wed, 14 Dec 2022 10:12:16 +0100 Subject: [PATCH 2/2] 615: rename creator to issuer --- .../ehrenamtskarte/backend/verification/database/Schema.kt | 4 ++-- .../backend/verification/database/repos/CardRepository.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/Schema.kt b/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/Schema.kt index 3904e93c0..6af12e565 100644 --- a/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/Schema.kt +++ b/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/Schema.kt @@ -20,7 +20,7 @@ object Cards : IntIdTable() { val issueDate = timestamp("issueDate").defaultExpression(CurrentTimestamp()) val revoked = bool("revoked") val regionId = reference("regionId", Regions) - val creatorId = reference("creatorId", Administrators) + val issuerId = reference("issuerId", Administrators) val cardDetailsHash = binary("cardDetailsHash", CARD_DETAILS_HASH_LENGTH).uniqueIndex() } @@ -33,5 +33,5 @@ class CardEntity(id: EntityID) : IntEntity(id) { var revoked by Cards.revoked var cardDetailsHash by Cards.cardDetailsHash var regionId by Cards.regionId - var creatorId by Cards.creatorId + var issuerId by Cards.issuerId } diff --git a/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/repos/CardRepository.kt b/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/repos/CardRepository.kt index 406861cd9..144d67f82 100644 --- a/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/repos/CardRepository.kt +++ b/backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/database/repos/CardRepository.kt @@ -20,14 +20,14 @@ object CardRepository { return if (query == null) null else CardEntity.wrapRow(query) } - fun insert(cardDetailsHash: ByteArray, totpSecret: ByteArray, expirationDay: Long?, regionId: Int, creatorId: Int) = + fun insert(cardDetailsHash: ByteArray, totpSecret: ByteArray, expirationDay: Long?, regionId: Int, issuerId: Int) = CardEntity.new { this.cardDetailsHash = cardDetailsHash this.totpSecret = totpSecret this.expirationDay = expirationDay this.issueDate = Instant.now() this.regionId = EntityID(regionId, Regions) - this.creatorId = EntityID(creatorId, Administrators) + this.issuerId = EntityID(issuerId, Administrators) this.revoked = false } }