Skip to content

Commit 98588bf

Browse files
feat(amber): include requester name in account email (#7639)
### What changes were proposed in this PR? The account-request notification only forwarded the requester's email address to the template. Although the stored user record already contains the requester's name, the notification path never retrieved it. ```text Before: account request -> email only -> admin notification omits name After: account request -> stored user lookup -> admin receives name and email ``` This change looks up the stored requester by email and includes the name in the admin notification. Missing or blank names render as `Not provided`. The requester-facing acknowledgement remains unchanged and does not expose the name field. Tests cover the positive stored-name path, the missing-requester fallback, blank and absent names, and the negative requester-facing template case. ### Any related issues, documentation, discussions? Closes #7595 ### How was this PR tested? ```bash sbt "WorkflowExecutionService / Test / testOnly org.apache.texera.web.resource.EmailTemplateSpec org.apache.texera.web.resource.GmailResourceSpec" sbt scalafmtCheckAll sbt "scalafixAll --check" ``` The focused suite passed 12 tests. Scala formatting and Scalafix checks also passed. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-5)
1 parent 14a574f commit 98588bf

4 files changed

Lines changed: 61 additions & 9 deletions

File tree

‎amber/src/main/scala/org/apache/texera/web/resource/EmailTemplate.scala‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ object EmailTemplate {
4141
*
4242
* @param receiverEmail the email address of the receiver (admin or user)
4343
* @param userEmail optional; the email address of the user requesting an account (only needed if toAdmin is true)
44+
* @param userName optional; the stored name of the user requesting an account (only needed if toAdmin is true)
4445
* @param toAdmin flag indicating whether the notification is for the admin (true) or the user (false)
4546
* @return an EmailMessage ready to be sent
4647
*/
4748
def userRegistrationNotification(
4849
receiverEmail: String,
4950
userEmail: Option[String],
51+
userName: Option[String],
5052
affiliation: Option[String],
5153
reason: Option[String],
5254
toAdmin: Boolean
@@ -62,6 +64,7 @@ object EmailTemplate {
6264
|A new user has attempted to log in or register, but their account is not yet approved.
6365
|Please review the account request for the following user:
6466
|
67+
|Name: ${userName.filter(_.trim.nonEmpty).getOrElse("Not provided")}
6568
|Email: ${userEmail.getOrElse("Unknown")}
6669
|Affiliation: ${affiliation.filter(_.trim.nonEmpty).getOrElse("Not provided")}
6770
|Reason: ${reason.filter(_.trim.nonEmpty).getOrElse("Not provided")}

‎amber/src/main/scala/org/apache/texera/web/resource/GmailResource.scala‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import org.apache.texera.dao.SqlServer
2626
import org.apache.texera.dao.jooq.generated.enums.UserRoleEnum
2727
import org.apache.texera.dao.jooq.generated.tables.daos.UserDao
2828
import org.apache.texera.web.resource.EmailTemplate.userRegistrationNotification
29-
import org.apache.texera.web.resource.GmailResource.{isValidEmail, sendEmail, senderGmail, userDao}
29+
import org.apache.texera.web.resource.GmailResource.{
30+
adminRegistrationNotification,
31+
isValidEmail,
32+
sendEmail,
33+
senderGmail,
34+
userDao
35+
}
3036
import org.slf4j.LoggerFactory
3137

3238
import javax.annotation.security.RolesAllowed
@@ -51,6 +57,22 @@ object GmailResource {
5157
.createDSLContext()
5258
private def userDao = new UserDao(context.configuration)
5359

60+
private[resource] def adminRegistrationNotification(
61+
adminEmail: String,
62+
emailMessage: EmailMessage
63+
): EmailMessage = {
64+
val requesterName =
65+
Option(userDao.fetchOneByEmail(emailMessage.receiver)).flatMap(user => Option(user.getName))
66+
userRegistrationNotification(
67+
receiverEmail = adminEmail,
68+
userEmail = Some(emailMessage.receiver),
69+
userName = requesterName,
70+
affiliation = emailMessage.affiliation,
71+
reason = emailMessage.reason,
72+
toAdmin = true
73+
)
74+
}
75+
5476
private lazy val senderGmail: String = UserSystemConfig.gmail
5577
private val smtpProperties = Map(
5678
"mail.smtp.host" -> "smtp.gmail.com",
@@ -179,13 +201,7 @@ class GmailResource {
179201

180202
try {
181203
sendEmail(
182-
userRegistrationNotification(
183-
receiverEmail = adminEmail,
184-
userEmail = Some(emailMessage.receiver),
185-
affiliation = emailMessage.affiliation,
186-
reason = emailMessage.reason,
187-
toAdmin = true
188-
),
204+
adminRegistrationNotification(adminEmail, emailMessage),
189205
adminEmail
190206
)
191207
} catch {
@@ -199,6 +215,7 @@ class GmailResource {
199215
userRegistrationNotification(
200216
receiverEmail = emailMessage.receiver,
201217
userEmail = None,
218+
userName = None,
202219
affiliation = None,
203220
reason = None,
204221
toAdmin = false

‎amber/src/test/scala/org/apache/texera/web/resource/EmailTemplateSpec.scala‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ class EmailTemplateSpec extends AnyFlatSpec with Matchers {
3838
val msg = EmailTemplate.userRegistrationNotification(
3939
receiverEmail = "[email protected]",
4040
userEmail = Some("[email protected]"),
41+
userName = Some("Alice Example"),
4142
affiliation = Some("UC Irvine"),
4243
reason = Some("research"),
4344
toAdmin = true
4445
)
4546
msg.receiver shouldBe "[email protected]"
4647
msg.subject should startWith("New Account Request Pending Approval")
48+
msg.content should include("Name: Alice Example")
4749
msg.content should include("Email: [email protected]")
4850
msg.content should include("Affiliation: UC Irvine")
4951
msg.content should include("Reason: research")
@@ -54,27 +56,31 @@ class EmailTemplateSpec extends AnyFlatSpec with Matchers {
5456
val msg = EmailTemplate.userRegistrationNotification(
5557
receiverEmail = "[email protected]",
5658
userEmail = None,
59+
userName = None,
5760
affiliation = Some("UC Irvine"),
5861
reason = Some("research"),
5962
toAdmin = true
6063
)
6164
msg.content should include("Email: Unknown")
6265
}
6366

64-
it should "render 'Not provided' for affiliation/reason when None or whitespace-only" in {
67+
it should "render 'Not provided' for name, affiliation, and reason when blank" in {
6568
val withNone = EmailTemplate.userRegistrationNotification(
6669
receiverEmail = "[email protected]",
6770
userEmail = Some("[email protected]"),
71+
userName = None,
6872
affiliation = None,
6973
reason = None,
7074
toAdmin = true
7175
)
7276
withNone.content should include("Affiliation: Not provided")
7377
withNone.content should include("Reason: Not provided")
78+
withNone.content should include("Name: Not provided")
7479

7580
val withBlank = EmailTemplate.userRegistrationNotification(
7681
receiverEmail = "[email protected]",
7782
userEmail = Some("[email protected]"),
83+
userName = Some(" "),
7884
affiliation = Some(" "),
7985
reason = Some(""),
8086
toAdmin = true
@@ -83,6 +89,7 @@ class EmailTemplateSpec extends AnyFlatSpec with Matchers {
8389
// strings the same as None.
8490
withBlank.content should include("Affiliation: Not provided")
8591
withBlank.content should include("Reason: Not provided")
92+
withBlank.content should include("Name: Not provided")
8693
}
8794

8895
// -- userRegistrationNotification (user branch) -----------------------------
@@ -92,6 +99,7 @@ class EmailTemplateSpec extends AnyFlatSpec with Matchers {
9299
val msg = EmailTemplate.userRegistrationNotification(
93100
receiverEmail = "[email protected]",
94101
userEmail = Some("[email protected]"),
102+
userName = Some("Ignored Name"),
95103
affiliation = Some("ignored"),
96104
reason = Some("ignored"),
97105
toAdmin = false
@@ -103,6 +111,7 @@ class EmailTemplateSpec extends AnyFlatSpec with Matchers {
103111
// fields back to the requester — if a refactor accidentally surfaces
104112
// them, this assertion will catch the leak.
105113
msg.content should not include "Email: ignored"
114+
msg.content should not include "Name: Ignored Name"
106115
msg.content should not include "Affiliation: ignored"
107116
msg.content should not include "Reason: ignored"
108117
}

‎amber/src/test/scala/org/apache/texera/web/resource/GmailResourceSpec.scala‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,27 @@ class GmailResourceSpec
301301
}
302302
assert(ex.getResponse.getStatus == 403)
303303
}
304+
305+
"adminRegistrationNotification" should "resolve the requester's stored name by email" in {
306+
val requesterEmail = s"gmailspec-requester-$runId@example.com"
307+
val requesterName = s"gmailspec_requester_$runId"
308+
seedUser("requester", UserRoleEnum.REGULAR, requesterEmail)
309+
310+
val message = GmailResource.adminRegistrationNotification(
311+
312+
EmailMessage(receiver = requesterEmail, subject = "", content = "")
313+
)
314+
315+
message.content should include(s"Name: $requesterName")
316+
message.content should include(s"Email: $requesterEmail")
317+
}
318+
319+
it should "render the fallback when no user matches the requester email" in {
320+
val message = GmailResource.adminRegistrationNotification(
321+
322+
EmailMessage(receiver = "[email protected]", subject = "", content = "")
323+
)
324+
325+
message.content should include("Name: Not provided")
326+
}
304327
}

0 commit comments

Comments
 (0)