Skip to content

Commit

Permalink
1791: Create application verifications automatically for verein360 ap…
Browse files Browse the repository at this point in the history
…plications
  • Loading branch information
ztefanie committed Dec 3, 2024
1 parent e28c088 commit aac3e94
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class ApplicationEntity(id: EntityID<Int>) : IntEntity(id) {
var cardCreated by Applications.cardCreated
}

enum class ApplicationVerificationExternalSource {
VEREIN360,
NONE
}

object ApplicationVerifications : IntIdTable() {
val applicationId = reference("applicationId", Applications)
val contactEmailAddress = varchar("contactEmailAddress", 300)
Expand All @@ -43,6 +48,8 @@ object ApplicationVerifications : IntIdTable() {
val verifiedDate = timestamp("verifiedDate").nullable()
val rejectedDate = timestamp("rejectedDate").nullable()
val accessKey = varchar("accessKey", 100).uniqueIndex()
val automaticSource = enumerationByName("automaticSource", 20, ApplicationVerificationExternalSource::class)
.default(ApplicationVerificationExternalSource.NONE)

init {
check("notVerifiedAndRejected") {
Expand All @@ -63,4 +70,5 @@ class ApplicationVerificationEntity(id: EntityID<Int>) : IntEntity(id) {
var verifiedDate by ApplicationVerifications.verifiedDate
var rejectedDate by ApplicationVerifications.rejectedDate
var accessKey by ApplicationVerifications.accessKey
var automaticSource by ApplicationVerifications.automaticSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app.ehrenamtskarte.backend.application.database.repos

import app.ehrenamtskarte.backend.application.database.ApplicationEntity
import app.ehrenamtskarte.backend.application.database.ApplicationVerificationEntity
import app.ehrenamtskarte.backend.application.database.ApplicationVerificationExternalSource
import app.ehrenamtskarte.backend.application.database.ApplicationVerifications
import app.ehrenamtskarte.backend.application.database.Applications
import app.ehrenamtskarte.backend.application.webservice.schema.view.ApplicationView
Expand Down Expand Up @@ -60,6 +61,7 @@ object ApplicationRepository {
this.contactName = it.contactName
this.organizationName = it.organizationName
this.contactEmailAddress = it.contactEmailAddress
this.automaticSource = ApplicationVerificationExternalSource.NONE
}
}

Expand Down Expand Up @@ -151,6 +153,7 @@ object ApplicationRepository {
false
} else {
applicationVerification.verifiedDate = Instant.now()
applicationVerification.automaticSource = ApplicationVerificationExternalSource.VEREIN360
true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import app.ehrenamtskarte.backend.exception.webservice.exceptions.RegionNotFound
import app.ehrenamtskarte.backend.mail.Mailer
import app.ehrenamtskarte.backend.regions.database.repos.RegionsRepository
import graphql.execution.DataFetcherResult
import io.javalin.http.BadRequestResponse
import org.jetbrains.exposed.sql.transactions.transaction

class ApplicationHandler(
Expand Down Expand Up @@ -88,16 +89,16 @@ class ApplicationHandler(
}

fun isValidPreVerifiedApplication(): Boolean {
val isAlreadyVerifiedSet =
application.applicationDetails.blueCardEntitlement?.workAtOrganizationsEntitlement?.list?.any {
it.isAlreadyVerified == true
} ?: false
if (isAlreadyVerifiedSet) {
// check if api token is set and valid, if not throw unauthorized exception
// Will be done in #1790
throw UnauthorizedException()
val isAlreadyVerifiedList =
application.applicationDetails.blueCardEntitlement?.workAtOrganizationsEntitlement?.list?.map { it.isAlreadyVerified }
?: emptyList()
return when {
isAlreadyVerifiedList.all { it == true } -> {
throw UnauthorizedException()
}
isAlreadyVerifiedList.all { it == false || it == null } -> false
else -> throw BadRequestResponse("isAlreadyVerified must be the same for all entries")
}
return false
}

fun setApplicationVerificationToVerifiedNow(verificationEntities: List<ApplicationVerificationEntity>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object MigrationsRegistry {
V0021_AlterTokenHashColumn(),
V0022_AddTypeToApiToken(),
V0023_DropTypeDefaultOfApiToken(),
V0024_AddNewRoleToRoleRegionCombinationConstraint()
V0024_AddNewRoleToRoleRegionCombinationConstraint(),
V0025_AddSourceFieldToApplicationVerifications()
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app.ehrenamtskarte.backend.migration.migrations

import app.ehrenamtskarte.backend.migration.Migration
import app.ehrenamtskarte.backend.migration.Statement

/**
* Addes the automaticSource field to the applicationverifications table
*/
@Suppress("ClassName")
internal class V0025_AddSourceFieldToApplicationVerifications : Migration() {
override val migrate: Statement = {
exec(
"""
ALTER TABLE applicationverifications
ADD COLUMN "automaticSource" VARCHAR(20) NOT NULL DEFAULT 'NONE' CHECK ("automaticSource" IN ('VEREIN360', 'NONE'));
""".trimIndent()
)
}
}

0 comments on commit aac3e94

Please sign in to comment.