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

1035: Notification sent to all users #1036

Merged
merged 4 commits into from
Jun 30, 2023
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 @@ -2,6 +2,7 @@ package app.ehrenamtskarte.backend.application.webservice

import app.ehrenamtskarte.backend.application.database.ApplicationEntity
import app.ehrenamtskarte.backend.application.database.repos.ApplicationRepository
import app.ehrenamtskarte.backend.application.database.repos.ApplicationRepository.getApplicationByApplicationVerificationAccessKey
import app.ehrenamtskarte.backend.application.webservice.schema.create.Application
import app.ehrenamtskarte.backend.auth.database.AdministratorEntity
import app.ehrenamtskarte.backend.auth.service.Authorizer.mayDeleteApplicationsInRegion
Expand Down Expand Up @@ -68,7 +69,7 @@ class EakApplicationMutationService {
dataFetcherResultBuilder.error(exception)
}
}
Mailer.sendNotificationForApplicationMails(project, backendConfig, projectConfig)
Mailer.sendNotificationForApplicationMails(project, backendConfig, projectConfig, regionId)

return dataFetcherResultBuilder.data(true).build()
}
Expand Down Expand Up @@ -111,13 +112,14 @@ class EakApplicationMutationService {
verified: Boolean,
dfe: DataFetchingEnvironment
): Boolean {
val application = transaction { getApplicationByApplicationVerificationAccessKey(accessKey) }
return transaction {
if (verified) {
val context = dfe.getContext<GraphQLContext>()
val backendConfig = context.backendConfiguration
val projectConfig = backendConfig.projects.first { it.id == project }
val successful = ApplicationRepository.verifyApplicationVerification(accessKey)
Mailer.sendNotificationForVerificationMails(project, backendConfig, projectConfig)
Mailer.sendNotificationForVerificationMails(project, backendConfig, projectConfig, application.regionId)

successful
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ object AdministratorsRepository {
administrator.notificationOnVerification = notificationSettings.notificationOnVerification
}

fun getNotificationRecipientsForApplication(project: String): List<AdministratorEntity> =
fun getNotificationRecipientsForApplication(project: String, regionId: Int): List<AdministratorEntity> =
transaction {
(Administrators innerJoin Projects).select {
(Projects.project eq project) and (Administrators.notificationOnApplication eq true)
(Projects.project eq project) and (Administrators.notificationOnApplication eq true) and (Administrators.regionId eq regionId)
}.let { AdministratorEntity.wrapRows(it) }.toList()
}

fun getNotificationRecipientsForVerification(project: String): List<AdministratorEntity> =
fun getNotificationRecipientsForVerification(project: String, regionId: Int): List<AdministratorEntity> =
transaction {
(Administrators innerJoin Projects).select {
(Projects.project eq project) and (Administrators.notificationOnVerification eq true)
(Projects.project eq project) and (Administrators.notificationOnVerification eq true) and (Administrators.regionId eq regionId)
f1sh1918 marked this conversation as resolved.
Show resolved Hide resolved
}.let { AdministratorEntity.wrapRows(it) }.toList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ object Mailer {
fun sendNotificationForApplicationMails(
project: String,
backendConfig: BackendConfiguration,
projectConfig: ProjectConfig
projectConfig: ProjectConfig,
regionId: Int
) {
val recipients = AdministratorsRepository.getNotificationRecipientsForApplication(project)
val recipients = AdministratorsRepository.getNotificationRecipientsForApplication(project, regionId)
val message = """
Guten Tag,

Expand Down Expand Up @@ -99,9 +100,10 @@ object Mailer {
fun sendNotificationForVerificationMails(
project: String,
backendConfig: BackendConfiguration,
projectConfig: ProjectConfig
projectConfig: ProjectConfig,
regionId: Int
) {
val recipients = AdministratorsRepository.getNotificationRecipientsForVerification(project)
val recipients = AdministratorsRepository.getNotificationRecipientsForVerification(project, regionId)
val message = """
Guten Tag,

Expand Down