Skip to content
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

836: Send verification emails #870

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const ApplyController = (): React.ReactElement | null => {
const [regionId, application] = validationResult.value

addBlueEakApplication({
variables: { regionId, application },
variables: { regionId, application, project: projectId },
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mutation addEakApplication($regionId: Int!, $application: ApplicationInput!) {
result: addEakApplication(regionId: $regionId, application: $application)
mutation addEakApplication($regionId: Int!, $application: ApplicationInput!, $project: String!) {
result: addEakApplication(regionId: $regionId, application: $application, project: $project)
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package app.ehrenamtskarte.backend.application.webservice

import app.ehrenamtskarte.backend.application.database.ApplicationEntity
import app.ehrenamtskarte.backend.application.database.ApplicationVerificationEntity
import app.ehrenamtskarte.backend.application.database.repos.ApplicationRepository
import app.ehrenamtskarte.backend.application.webservice.schema.create.Application
import app.ehrenamtskarte.backend.auth.database.AdministratorEntity
import app.ehrenamtskarte.backend.auth.service.Authorizer.mayDeleteApplicationsInRegion
import app.ehrenamtskarte.backend.common.webservice.GraphQLContext
import app.ehrenamtskarte.backend.common.webservice.UnauthorizedException
import app.ehrenamtskarte.backend.mail.Mailer
import com.expediagroup.graphql.generator.annotations.GraphQLDescription
import graphql.schema.DataFetchingEnvironment
import org.jetbrains.exposed.sql.transactions.transaction
import java.net.URLEncoder
import java.nio.charset.StandardCharsets

@Suppress("unused")
class EakApplicationMutationService {
Expand All @@ -18,29 +22,63 @@ class EakApplicationMutationService {
fun addEakApplication(
regionId: Int,
application: Application,
project: String,
dfe: DataFetchingEnvironment,
): Boolean {
val context = dfe.getContext<GraphQLContext>()
val backendConfig = context.backendConfiguration
val projectConfig = backendConfig.projects.first { it.id == project }
sarahsporck marked this conversation as resolved.
Show resolved Hide resolved

// Validate that all files are png, jpeg or pdf files and at most 5MB.
val allowedContentTypes = setOf("application/pdf", "image/png", "image/jpeg")
val maxFileSizeBytes = 5 * 1000 * 1000
if (!context.files.all { it.contentType in allowedContentTypes && it.size <= maxFileSizeBytes }) {
throw IllegalArgumentException("An uploaded file does not adhere to the file upload requirements.")
}

val (applicationEntity, verificationEntities) = ApplicationRepository.persistApplication(
application.toJsonField(),
application.extractApplicationVerifications(),
regionId,
context.applicationData,
context.files,
)
transaction {
val (applicationEntity, verificationEntities) = ApplicationRepository.persistApplication(
application.toJsonField(),
application.extractApplicationVerifications(),
regionId,
context.applicationData,
context.files,
)

// TODO: Send mails
for (applicationVerification in verificationEntities) {
Mailer.sendMail(
backendConfig,
projectConfig.smtp,
projectConfig.administrationName,
applicationVerification.contactEmailAddress,
"Antrag Verifizieren",
generateApplicationVerificationMailMessage(projectConfig.administrationName, projectConfig.administrationBaseUrl, applicationVerification)
)
}
}

return true
}

private fun generateApplicationVerificationMailMessage(
administrationName: String,
administrationBaseUrl: String,
applicationVerification: ApplicationVerificationEntity
): String {
return """
Guten Tag ${applicationVerification.contactName},

Sie wurden gebeten, die Angaben eines Antrags auf Ehrenamtskarte zu bestätigen. Die Antragsstellerin oder der
Antragssteller hat Sie als Kontaktperson der Organisation ${applicationVerification.organizationName} angegeben.
Sie können den Antrag unter folgendem Link einsehen und die Angaben bestätigen oder ihnen widersprechen:
$administrationBaseUrl/antrag-verifizieren/${URLEncoder.encode(applicationVerification.accessKey, StandardCharsets.UTF_8)}

Dies ist eine automatisierte Nachricht. Antworten Sie nicht auf diese Email.

- $administrationName
""".trimIndent()
}

@GraphQLDescription("Deletes the application with specified id")
fun deleteApplication(
applicationId: Int,
Expand Down
2 changes: 1 addition & 1 deletion specs/backend-api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type Mutation {
"Stores a batch of new digital entitlementcards"
addCards(cards: [CardGenerationModelInput!]!): Boolean!
"Stores a new application for an EAK"
addEakApplication(application: ApplicationInput!, regionId: Int!): Boolean!
addEakApplication(application: ApplicationInput!, project: String!, regionId: Int!): Boolean!
"Changes an administrator's password"
changePassword(currentPassword: String!, email: String!, newPassword: String!, project: String!): Boolean!
"Creates a new administrator"
Expand Down