Include applicant's username in staff application emails and Discord notifications.
This commit is contained in:
+21
-3
@@ -3,6 +3,7 @@ package com.alttd.altitudeweb.controllers.forms;
|
||||
import com.alttd.altitudeweb.api.ApplicationsApi;
|
||||
import com.alttd.altitudeweb.controllers.data_from_auth.AuthenticatedUuid;
|
||||
import com.alttd.altitudeweb.database.Databases;
|
||||
import com.alttd.altitudeweb.database.luckperms.UUIDUsernameMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.forms.StaffApplication;
|
||||
import com.alttd.altitudeweb.database.web_db.forms.StaffApplicationMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.mail.EmailVerification;
|
||||
@@ -17,7 +18,6 @@ import com.alttd.altitudeweb.setup.Connection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -68,8 +68,10 @@ public class ApplicationController implements ApplicationsApi {
|
||||
StaffApplication application = staffApplicationDataMapper.map(userUuid, staffApplicationDto);
|
||||
saveApplication(application);
|
||||
|
||||
String username = getUsername(userUuid);
|
||||
|
||||
try {
|
||||
if (!staffApplicationMail.sendApplicationEmail(application)) {
|
||||
if (!staffApplicationMail.sendApplicationEmail(username, application)) {
|
||||
log.warn("Failed to send staff application email for {}", application.id());
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}
|
||||
@@ -79,7 +81,7 @@ public class ApplicationController implements ApplicationsApi {
|
||||
}
|
||||
|
||||
try {
|
||||
staffApplicationDiscord.sendApplicationToDiscord(application);
|
||||
staffApplicationDiscord.sendApplicationToDiscord(username, application);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to send staff application {} to Discord", application.id(), e);
|
||||
return ResponseEntity.internalServerError().build();
|
||||
@@ -133,4 +135,20 @@ public class ApplicationController implements ApplicationsApi {
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
private String getUsername(UUID uuid) {
|
||||
CompletableFuture<String> usernameFuture = new CompletableFuture<>();
|
||||
Connection.getConnection(Databases.LUCK_PERMS)
|
||||
.runQuery(sqlSession -> {
|
||||
log.debug("Loading username for uuid {}", uuid);
|
||||
try {
|
||||
String username = sqlSession.getMapper(UUIDUsernameMapper.class).getUsernameFromUUID(uuid.toString());
|
||||
usernameFuture.complete(username);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to load username for uuid {}", uuid, e);
|
||||
usernameFuture.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
return usernameFuture.join();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ public class StaffApplicationDiscord {
|
||||
|
||||
private static final String OUTPUT_TYPE = "STAFF_APPLICATION";
|
||||
|
||||
public void sendApplicationToDiscord(StaffApplication application) {
|
||||
public void sendApplicationToDiscord(String username, StaffApplication application) {
|
||||
// Fetch channels for staff applications
|
||||
CompletableFuture<List<OutputChannel>> channelsFuture = new CompletableFuture<>();
|
||||
Connection.getConnection(Databases.DISCORD).runQuery(sql -> {
|
||||
@@ -46,7 +46,7 @@ public class StaffApplicationDiscord {
|
||||
List<DiscordSender.EmbedField> fields = new ArrayList<>();
|
||||
fields.add(new DiscordSender.EmbedField(
|
||||
"Applicant",
|
||||
"UUID: " + safe(String.valueOf(application.uuid())) + "\n" +
|
||||
"Username: " + safe(username) + "\n" +
|
||||
"Discord: " + safe(application.discordUsername()) + "\n" +
|
||||
"Email: " + safe(application.email()) + "\n" +
|
||||
"Age: " + safe(String.valueOf(application.age())) + "\n" +
|
||||
|
||||
@@ -32,9 +32,9 @@ public class StaffApplicationMail {
|
||||
* Sends an email with the staff application details to the staff applications team mailbox.
|
||||
* Returns true if the email was sent successfully.
|
||||
*/
|
||||
public boolean sendApplicationEmail(StaffApplication application) {
|
||||
public boolean sendApplicationEmail(String username, StaffApplication application) {
|
||||
try {
|
||||
doSend(application);
|
||||
doSend(username, application);
|
||||
log.info("Staff application email sent successfully for application ID: {}", application.id());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
@@ -43,7 +43,7 @@ public class StaffApplicationMail {
|
||||
}
|
||||
}
|
||||
|
||||
private void doSend(StaffApplication application) throws MessagingException {
|
||||
private void doSend(String username, StaffApplication application) throws MessagingException {
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||
|
||||
@@ -59,6 +59,7 @@ public class StaffApplicationMail {
|
||||
Context context = new Context();
|
||||
context.setVariable("application", application);
|
||||
context.setVariable("createdAt", createdAt);
|
||||
context.setVariable("username", username);
|
||||
|
||||
String content = templateEngine.process("staff-application-email", context);
|
||||
helper.setText(content, true);
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
<div>
|
||||
<h2>Applicant</h2>
|
||||
<ul>
|
||||
<li><strong>UUID:</strong> <span th:text="${application.uuid}">uuid</span></li>
|
||||
<li><strong>Username:</strong> <span th:text="${username}">uuid</span></li>
|
||||
<li><strong>Email:</strong> <span th:text="${application.email}">email</span></li>
|
||||
<li><strong>Discord:</strong> <span th:text="${application.discordUsername}">discord</span></li>
|
||||
<li><strong>Age:</strong> <span th:text="${application.age}">age</span></li>
|
||||
|
||||
Reference in New Issue
Block a user