Include applicant's username in staff application emails and Discord notifications.

This commit is contained in:
akastijn 2025-10-18 23:07:03 +02:00
parent f8157e997a
commit 6f6801c728
7 changed files with 44 additions and 10 deletions

View File

@ -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();
}
}

View File

@ -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" +

View File

@ -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);

View File

@ -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>

View File

@ -0,0 +1,13 @@
package com.alttd.altitudeweb.database.luckperms;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
public interface UUIDUsernameMapper {
@Select("""
SELECT username
FROM luckperms_players
WHERE uuid = #{uuid}
""")
String getUsernameFromUUID(@Param("uuid") String uuid);
}

View File

@ -2,6 +2,7 @@ package com.alttd.altitudeweb.setup;
import com.alttd.altitudeweb.database.Databases;
import com.alttd.altitudeweb.database.luckperms.TeamMemberMapper;
import com.alttd.altitudeweb.database.luckperms.UUIDUsernameMapper;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@ -11,6 +12,7 @@ public class InitializeLuckPerms {
log.info("Initializing LuckPerms");
Connection.getConnection(Databases.LUCK_PERMS, (configuration) -> {
configuration.addMapper(TeamMemberMapper.class);
configuration.addMapper(UUIDUsernameMapper.class);
}).join();
log.debug("Initialized LuckPerms");
}

View File

@ -335,7 +335,7 @@ export class StaffApplicationComponent implements OnInit, OnDestroy, AfterViewIn
joinDate: joinDateString,
weeklyPlaytime: Number(formData.weeklyPlaytime),
availableDays: formData.availableDays,
availableTimes: `Timezone: ${this.userTimezone}\nAvailable Times:${formData.availableTimes}`,
availableTimes: `Timezone: ${this.userTimezone}\nAvailable Times: ${formData.availableTimes}`,
previousExperience: formData.previousExperience,
pluginExperience: formData.pluginExperience,
moderatorExpectations: formData.moderatorExpectations,