Enhance DiscordAppeal submission process by adding username retrieval and updating email notifications with Minecraft username. Refactor for clarity and consistency in variable usage.
This commit is contained in:
parent
c56f5f9fe1
commit
525116e89b
|
|
@ -2,6 +2,7 @@ package com.alttd.altitudeweb.services.forms;
|
||||||
|
|
||||||
import com.alttd.altitudeweb.controllers.data_from_auth.AuthenticatedUuid;
|
import com.alttd.altitudeweb.controllers.data_from_auth.AuthenticatedUuid;
|
||||||
import com.alttd.altitudeweb.database.Databases;
|
import com.alttd.altitudeweb.database.Databases;
|
||||||
|
import com.alttd.altitudeweb.database.luckperms.UUIDUsernameMapper;
|
||||||
import com.alttd.altitudeweb.database.web_db.forms.DiscordAppealMapper;
|
import com.alttd.altitudeweb.database.web_db.forms.DiscordAppealMapper;
|
||||||
import com.alttd.altitudeweb.database.web_db.mail.EmailVerification;
|
import com.alttd.altitudeweb.database.web_db.mail.EmailVerification;
|
||||||
import com.alttd.altitudeweb.database.web_db.mail.EmailVerificationMapper;
|
import com.alttd.altitudeweb.database.web_db.mail.EmailVerificationMapper;
|
||||||
|
|
@ -56,11 +57,11 @@ public class DiscordAppeal {
|
||||||
}
|
}
|
||||||
BannedUser bannedUser = join.get();
|
BannedUser bannedUser = join.get();
|
||||||
|
|
||||||
Optional<UUID> uuid = authenticatedUuid.tryGetAuthenticatedUserUuid();
|
Optional<UUID> optionalUUID = authenticatedUuid.tryGetAuthenticatedUserUuid();
|
||||||
if (uuid.isEmpty()) {
|
if (optionalUUID.isEmpty()) {
|
||||||
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "User not authenticated");
|
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "User not authenticated");
|
||||||
}
|
}
|
||||||
|
UUID uuid = optionalUUID.get();
|
||||||
CompletableFuture<com.alttd.altitudeweb.database.web_db.forms.DiscordAppeal> appealCompletableFuture = new CompletableFuture<>();
|
CompletableFuture<com.alttd.altitudeweb.database.web_db.forms.DiscordAppeal> appealCompletableFuture = new CompletableFuture<>();
|
||||||
|
|
||||||
Connection.getConnection(Databases.DEFAULT)
|
Connection.getConnection(Databases.DEFAULT)
|
||||||
|
|
@ -68,7 +69,7 @@ public class DiscordAppeal {
|
||||||
log.debug("Loading history by id");
|
log.debug("Loading history by id");
|
||||||
try {
|
try {
|
||||||
com.alttd.altitudeweb.database.web_db.forms.DiscordAppeal discordAppealRecord = discordAppealDtoToDiscordAppealMapper
|
com.alttd.altitudeweb.database.web_db.forms.DiscordAppeal discordAppealRecord = discordAppealDtoToDiscordAppealMapper
|
||||||
.map(discordAppealDto, uuid.get(), bannedUser.name());
|
.map(discordAppealDto, uuid, bannedUser.name());
|
||||||
sqlSession.getMapper(DiscordAppealMapper.class).createDiscordAppeal(discordAppealRecord);
|
sqlSession.getMapper(DiscordAppealMapper.class).createDiscordAppeal(discordAppealRecord);
|
||||||
appealCompletableFuture.complete(discordAppealRecord);
|
appealCompletableFuture.complete(discordAppealRecord);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -104,7 +105,8 @@ public class DiscordAppeal {
|
||||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to send appeal to Discord");
|
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to send appeal to Discord");
|
||||||
}
|
}
|
||||||
//TODO verify mail
|
//TODO verify mail
|
||||||
appealMail.sendAppealNotification(discordAppeal);
|
String username = getUsername(uuid);
|
||||||
|
appealMail.sendAppealNotification(discordAppeal, username);
|
||||||
|
|
||||||
Connection.getConnection(Databases.DEFAULT)
|
Connection.getConnection(Databases.DEFAULT)
|
||||||
.runQuery(sqlSession -> {
|
.runQuery(sqlSession -> {
|
||||||
|
|
@ -117,4 +119,20 @@ public class DiscordAppeal {
|
||||||
"Your appeal has been submitted. You will be notified when it has been reviewed.",
|
"Your appeal has been submitted. You will be notified when it has been reviewed.",
|
||||||
true);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,9 @@ public class AppealMail {
|
||||||
*
|
*
|
||||||
* @param appeal The appeal object containing all necessary information
|
* @param appeal The appeal object containing all necessary information
|
||||||
*/
|
*/
|
||||||
public void sendAppealNotification(DiscordAppeal appeal) {
|
public void sendAppealNotification(DiscordAppeal appeal, String username) {
|
||||||
try {
|
try {
|
||||||
sendEmailToAppealsTeam(appeal);
|
sendEmailToAppealsTeam(appeal, username);
|
||||||
|
|
||||||
log.info("Discord Appeal notification emails sent successfully for appeal ID: {}", appeal.id());
|
log.info("Discord Appeal notification emails sent successfully for appeal ID: {}", appeal.id());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -81,7 +81,7 @@ public class AppealMail {
|
||||||
mailSender.send(message);
|
mailSender.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendEmailToAppealsTeam(DiscordAppeal appeal) throws MessagingException {
|
private void sendEmailToAppealsTeam(DiscordAppeal appeal, String username) throws MessagingException {
|
||||||
MimeMessage message = mailSender.createMimeMessage();
|
MimeMessage message = mailSender.createMimeMessage();
|
||||||
MimeMessageHelper helper = getAppealMimeMessageHelper(appeal, message);
|
MimeMessageHelper helper = getAppealMimeMessageHelper(appeal, message);
|
||||||
|
|
||||||
|
|
@ -90,6 +90,8 @@ public class AppealMail {
|
||||||
context.setVariable("createdAt", appeal.createdAt()
|
context.setVariable("createdAt", appeal.createdAt()
|
||||||
.atZone(ZoneId.of("UTC"))
|
.atZone(ZoneId.of("UTC"))
|
||||||
.format(DateTimeFormatter.ofPattern("yyyy MMMM dd hh:mm a '(UTC)'")));
|
.format(DateTimeFormatter.ofPattern("yyyy MMMM dd hh:mm a '(UTC)'")));
|
||||||
|
|
||||||
|
context.setVariable("minecraftName", username);
|
||||||
String content = templateEngine.process("discord-appeal-email", context);
|
String content = templateEngine.process("discord-appeal-email", context);
|
||||||
|
|
||||||
helper.setText(content, true);
|
helper.setText(content, true);
|
||||||
|
|
|
||||||
|
|
@ -102,8 +102,9 @@
|
||||||
<div>
|
<div>
|
||||||
<h2>User information</h2>
|
<h2>User information</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>Username:</strong> <span th:text="${appeal.discordUsername}">username</span></li>
|
<li><strong>Discord Username:</strong> <span th:text="${appeal.discordUsername}">dc username</span></li>
|
||||||
<li><strong>UUID:</strong> <span th:text="${appeal.uuid}">uuid</span></li>
|
<li><strong>UUID:</strong> <span th:text="${appeal.uuid}">uuid</span></li>
|
||||||
|
<li><strong>Minecraft Username:</strong> <span th:text="${minecraftName}">mc username</span></li>
|
||||||
<li><strong>Email:</strong> <span th:text="${appeal.email}">email</span></li>
|
<li><strong>Email:</strong> <span th:text="${appeal.email}">email</span></li>
|
||||||
<li><strong>Submitted at:</strong> <span th:text="${createdAt}">date</span></li>
|
<li><strong>Submitted at:</strong> <span th:text="${createdAt}">date</span></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user