Skip to content

Commit

Permalink
use mail template for mail validation process
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinovega committed Jul 17, 2023
1 parent bfa613c commit dd35109
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions daikoku/app/domain/json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,7 @@ object json {
case "canceled" => JsSuccess(SubscriptionDemandState.Canceled)
case "accepted" => JsSuccess(SubscriptionDemandState.Accepted)
case "refused" => JsSuccess(SubscriptionDemandState.Refused)
case "blocked" => JsSuccess(SubscriptionDemandState.Blocked)
case str => JsError(s"Bad SubscriptionDemandState value: $str")
}

Expand Down
13 changes: 10 additions & 3 deletions daikoku/app/utils/ApiService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import fr.maif.otoroshi.daikoku.domain.UsagePlan._
import fr.maif.otoroshi.daikoku.domain.{DatastoreId, _}
import fr.maif.otoroshi.daikoku.env.Env
import fr.maif.otoroshi.daikoku.logger.AppLogger
import fr.maif.otoroshi.daikoku.utils.Cypher.encrypt
import fr.maif.otoroshi.daikoku.utils.Cypher.{decrypt, encrypt}
import fr.maif.otoroshi.daikoku.utils.StringImplicits._
import jobs.{ApiKeyStatsJob, OtoroshiVerifierJob}
import org.joda.time.DateTime
Expand Down Expand Up @@ -892,6 +892,8 @@ class ApiService(env: Env,

val value: EitherT[Future, AppError, Result] = for {
title <- EitherT.liftF(translator.translate("mail.subscription.validation.title", tenant))
user <- EitherT.fromOptionF(env.dataStore.userRepo.findByIdNotDeleted(demand.from), AppError.UserNotFound)
team <- EitherT.fromOptionF(env.dataStore.teamRepo.forTenant(tenant).findByIdNotDeleted(demand.team), AppError.TeamNotFound)
_ <- EitherT.liftF(Future.sequence(emails.map(email => {
val stepValidator = StepValidator(
id = DatastoreId(BSONObjectID.generate().stringify),
Expand All @@ -906,9 +908,14 @@ class ApiService(env: Env,
val pathAccept = s"/api/subscription/_validate?token=$cipheredValidationToken"
val pathDecline = s"/api/subscription/_decline?token=$cipheredValidationToken"

//FIXME: use template
translator.translate("mail.subscription.validation.body", tenant,
Map("urlAccept" -> env.getDaikokuUrl(tenant, pathAccept), "urlDecline" -> env.getDaikokuUrl(tenant, pathDecline)))
Map(
"urlAccept" -> env.getDaikokuUrl(tenant, pathAccept),
"urlDecline" -> env.getDaikokuUrl(tenant, pathDecline),
"user" -> user.name,
"team" -> team.name,
"body" -> template.getOrElse("")
))
.flatMap(body => env.dataStore.stepValidatorRepo.forTenant(tenant).save(stepValidator).map(_ => body))
.flatMap(body => tenant.mailer.send(title, Seq(email), body, tenant))
})))
Expand Down
4 changes: 1 addition & 3 deletions daikoku/conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ You need to verify your mail for the team [team].\
mail.subscription.validation.title = Validate a subscription
mail.subscription.validation.body = Hello,\
<br/>\
Somebody want to subscribe your API,\
[user] for the team [team] wants to subscribe your API,\
<br>\
<div>\
[user] :\
<br>\
[body]\
</div>\
<a href="[urlAccept]">Accept</a> or <a href="[urlDecline]">Reject</a>
Expand Down
4 changes: 1 addition & 3 deletions daikoku/conf/messages.fr
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ Vous devez vérifier votre mail pour l'équipe [team].\
mail.subscription.validation.title = Validation de souscription
mail.subscription.validation.body = Bonjour,\
<br/>\
Quelqu'un voudrait souscrire a l'API [apiName],\
[user] pour l'équipe [team] voudrait souscrire a l'API [apiName],\
<br>\
<div>\
[user] :\
<br>\
[body]\
</div>\
<a href="[urlAccept]">Accept</a> or <a href="[urlDecline]">Reject</a>
Expand Down

0 comments on commit dd35109

Please sign in to comment.