Skip to content

Commit

Permalink
Merge pull request #1036 from digitalfabrik/1035-notification-sent-to…
Browse files Browse the repository at this point in the history
…-all-users

1035: Notification sent to all users
  • Loading branch information
f1sh1918 authored Jun 30, 2023
2 parents 9353212 + 6be380a commit 9467b57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
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) and (Administrators.deleted eq false)
}.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) and (Administrators.deleted eq false)
}.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

0 comments on commit 9467b57

Please sign in to comment.