-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1415: Revoke existing cards via user import endpoint #1674
Merged
seluianova
merged 7 commits into
main
from
1415-revoke-existing-cards-via-http-endpoint
Oct 28, 2024
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4fd7777
1415: Revoke existing cards when user entitlements are revoked or exp…
seluianova 657d842
Merge branch 'main' into 1415-revoke-existing-cards-via-http-endpoint
ztefanie 3cafca5
1415: Do not revoke cards when the user's entitlement expiry date is …
seluianova 7da480f
1415: Refactor UserImportHandler.importData() function
seluianova 775f035
1415: Update the error message when the user entitlement is not found
seluianova a0c605a
1415: Add USER_ENTITLEMENT_EXPIRED error
seluianova f3290de
Merge branch 'main' into 1415-revoke-existing-cards-via-http-endpoint
seluianova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 16 additions & 17 deletions
33
...rc/main/kotlin/app/ehrenamtskarte/backend/userdata/database/UserEntitlementsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
package app.ehrenamtskarte.backend.userdata.database | ||
|
||
import org.jetbrains.exposed.sql.booleanLiteral | ||
import org.jetbrains.exposed.sql.intLiteral | ||
import org.jetbrains.exposed.sql.javatime.dateLiteral | ||
import org.jetbrains.exposed.sql.javatime.timestampLiteral | ||
import org.jetbrains.exposed.sql.upsert | ||
import org.jetbrains.exposed.sql.insert | ||
import org.jetbrains.exposed.sql.update | ||
import java.time.Instant | ||
import java.time.LocalDate | ||
|
||
object UserEntitlementsRepository { | ||
|
||
fun insertOrUpdateUserData(userHash: ByteArray, startDate: LocalDate, endDate: LocalDate, revoked: Boolean, regionId: Int) { | ||
UserEntitlements.upsert( | ||
UserEntitlements.userHash, | ||
onUpdate = listOf( | ||
UserEntitlements.startDate to dateLiteral(startDate), | ||
UserEntitlements.endDate to dateLiteral(endDate), | ||
UserEntitlements.revoked to booleanLiteral(revoked), | ||
UserEntitlements.regionId to intLiteral(regionId), | ||
UserEntitlements.lastUpdated to timestampLiteral(Instant.now()) | ||
) | ||
) { | ||
fun insert(userHash: ByteArray, startDate: LocalDate, endDate: LocalDate, revoked: Boolean, regionId: Int) { | ||
UserEntitlements.insert { | ||
it[UserEntitlements.userHash] = userHash | ||
it[UserEntitlements.startDate] = startDate | ||
it[UserEntitlements.endDate] = endDate | ||
it[UserEntitlements.revoked] = revoked | ||
it[UserEntitlements.regionId] = regionId | ||
it[lastUpdated] = Instant.now() | ||
} | ||
} | ||
|
||
fun findUserEntitlements(userHash: ByteArray): UserEntitlementsEntity? { | ||
fun update(userHash: ByteArray, startDate: LocalDate, endDate: LocalDate, revoked: Boolean, regionId: Int) { | ||
UserEntitlements.update({ UserEntitlements.userHash eq userHash }) { | ||
it[UserEntitlements.startDate] = startDate | ||
it[UserEntitlements.endDate] = endDate | ||
it[UserEntitlements.revoked] = revoked | ||
it[UserEntitlements.regionId] = regionId | ||
it[lastUpdated] = Instant.now() | ||
} | ||
} | ||
|
||
fun findByUserHash(userHash: ByteArray): UserEntitlementsEntity? { | ||
return UserEntitlementsEntity.find { UserEntitlements.userHash eq userHash }.firstOrNull() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to throw different exceptions here. At least we should create a TODO and ticket if it will not be done here.
We have to distinguish between the input data does not match the entitlement hash then we throw
UserEntitlementNotFoundException()
If revoked or expired i would throw
UserEntitlementExpiredException
or sth similar with a separate messageThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will need to associate a new exception with some error message.
Do you think
Sie sind nicht mehr berechtigt, einen KoblenzPass zu erstellen
is fine?