Add historyType and historyId to Appeal, update database schema, API, and email templates to include punishment details.
This commit is contained in:
parent
c3f3b20807
commit
de1876c90c
|
|
@ -2,6 +2,9 @@ package com.alttd.altitudeweb.controllers.forms;
|
|||
|
||||
import com.alttd.altitudeweb.api.AppealsApi;
|
||||
import com.alttd.altitudeweb.database.Databases;
|
||||
import com.alttd.altitudeweb.database.litebans.HistoryRecord;
|
||||
import com.alttd.altitudeweb.database.litebans.HistoryType;
|
||||
import com.alttd.altitudeweb.database.litebans.IdHistoryMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.forms.Appeal;
|
||||
import com.alttd.altitudeweb.database.web_db.forms.AppealMapper;
|
||||
import com.alttd.altitudeweb.mappers.AppealDataMapper;
|
||||
|
|
@ -56,8 +59,12 @@ public class AppealController implements AppealsApi {
|
|||
}
|
||||
});
|
||||
Appeal appeal = appealCompletableFuture.join();
|
||||
HistoryRecord history = getHistory(appeal.historyType(), appeal.historyId());
|
||||
if (history == null) {
|
||||
throw new ResponseStatusException(HttpStatusCode.valueOf(404), "History not found");
|
||||
}
|
||||
|
||||
appealMail.sendAppealNotification(appeal);
|
||||
appealMail.sendAppealNotification(appeal, history);
|
||||
|
||||
AppealResponseDto appealResponseDto = new AppealResponseDto(
|
||||
appeal.id().toString(),
|
||||
|
|
@ -71,4 +78,23 @@ public class AppealController implements AppealsApi {
|
|||
public ResponseEntity<AppealResponseDto> updateMail(UpdateMailDto updateMailDto) {
|
||||
throw new ResponseStatusException(HttpStatusCode.valueOf(501), "Updating mail is not yet supported");
|
||||
}
|
||||
|
||||
private HistoryRecord getHistory(String type, int id) {
|
||||
HistoryType historyTypeEnum = HistoryType.getHistoryType(type);
|
||||
CompletableFuture<HistoryRecord> historyRecordCompletableFuture = new CompletableFuture<>();
|
||||
|
||||
Connection.getConnection(Databases.LITE_BANS)
|
||||
.runQuery(sqlSession -> {
|
||||
log.debug("Loading history by id");
|
||||
try {
|
||||
HistoryRecord punishment = sqlSession.getMapper(IdHistoryMapper.class)
|
||||
.getRecentHistory(historyTypeEnum, id);
|
||||
historyRecordCompletableFuture.complete(punishment);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to load history count", e);
|
||||
historyRecordCompletableFuture.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
return historyRecordCompletableFuture.join();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.alttd.altitudeweb.services.mail;
|
||||
|
||||
import com.alttd.altitudeweb.database.litebans.HistoryRecord;
|
||||
import com.alttd.altitudeweb.database.web_db.forms.Appeal;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
|
|
@ -30,9 +31,9 @@ public class AppealMail {
|
|||
*
|
||||
* @param appeal The appeal object containing all necessary information
|
||||
*/
|
||||
public void sendAppealNotification(Appeal appeal) {
|
||||
public void sendAppealNotification(Appeal appeal, HistoryRecord history) {
|
||||
try {
|
||||
sendEmailToAppealsTeam(appeal);
|
||||
sendEmailToAppealsTeam(appeal, history);
|
||||
|
||||
log.info("Appeal notification emails sent successfully for appeal ID: {}", appeal.id());
|
||||
} catch (Exception e) {
|
||||
|
|
@ -40,7 +41,7 @@ public class AppealMail {
|
|||
}
|
||||
}
|
||||
|
||||
private void sendEmailToAppealsTeam(Appeal appeal) throws MessagingException {
|
||||
private void sendEmailToAppealsTeam(Appeal appeal, HistoryRecord history) throws MessagingException {
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||
|
||||
|
|
@ -51,6 +52,9 @@ public class AppealMail {
|
|||
|
||||
Context context = new Context();
|
||||
context.setVariable("appeal", appeal);
|
||||
context.setVariable("history", history);
|
||||
context.setVariable("createdAt", appeal.createdAt().toString());
|
||||
context.setVariable("active", history.getUntil() <= 0 || history.getUntil() > System.currentTimeMillis());
|
||||
String content = templateEngine.process("appeal-email", context);
|
||||
|
||||
helper.setText(content, true);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@
|
|||
<li><strong>Username:</strong> <span th:text="${appeal.username}">username</span></li>
|
||||
<li><strong>UUID:</strong> <span th:text="${appeal.uuid}">uuid</span></li>
|
||||
<li><strong>Email:</strong> <span th:text="${appeal.email}">email</span></li>
|
||||
<li><strong>Submitted:</strong> <span th:text="${appeal.createdAt}">date</span></li>
|
||||
<li><strong>Submitted at:</strong> <span th:text="${createdAt}">date</span></li>
|
||||
<li><strong>Reason:</strong> <span th:text="${history.reason}">reason</span></li>
|
||||
<li><strong>Active:</strong> <span th:text="${active}">unknown</span></li>
|
||||
</ul>
|
||||
<h3>Appeal:</h3>
|
||||
<p th:text="${appeal.reason}">Reason text</p>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import java.util.UUID;
|
|||
public record Appeal(
|
||||
UUID id,
|
||||
UUID uuid,
|
||||
String historyType,
|
||||
Integer historyId,
|
||||
String username,
|
||||
String reason,
|
||||
Instant createdAt,
|
||||
|
|
|
|||
|
|
@ -2,38 +2,26 @@ package com.alttd.altitudeweb.database.web_db.forms;
|
|||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AppealMapper {
|
||||
|
||||
@Insert("""
|
||||
INSERT INTO appeals (uuid, username, reason, created_at, send_at, e_mail, assigned_to)
|
||||
VALUES (#{uuid}, #{username}, #{reason}, #{createdAt}, #{sendAt}, #{email}, #{assignedTo})
|
||||
INSERT INTO appeals (uuid, username, historyType, historyId, reason, created_at, send_at, e_mail, assigned_to)
|
||||
VALUES (#{uuid}, #{username}, #{historyType}, #{historyId}, #{reason}, #{createdAt}, #{sendAt}, #{email}, #{assignedTo})
|
||||
""")
|
||||
void createAppeal(Appeal appeal);
|
||||
|
||||
@Update("""
|
||||
UPDATE appeals
|
||||
SET reason = #{reason},
|
||||
created_at = #{createdAt},
|
||||
send_at = #{sendAt},
|
||||
e_mail = #{email},
|
||||
assigned_to = #{assignedTo}
|
||||
WHERE id = #{id}
|
||||
""")
|
||||
void updateAppeal(Appeal appeal);
|
||||
|
||||
@Select("""
|
||||
SELECT id, uuid, reason, created_at AS createdAt, send_at AS sendAt, e_mail AS email, assigned_to AS assignedTo
|
||||
SELECT id, uuid, historyType, historyId, reason, created_at AS createdAt, send_at AS sendAt, e_mail AS email, assigned_to AS assignedTo
|
||||
FROM appeals
|
||||
WHERE id = #{id}
|
||||
""")
|
||||
Appeal getAppealById(int id);
|
||||
|
||||
@Select("""
|
||||
SELECT id, uuid, reason, created_at AS createdAt, send_at AS sendAt, e_mail AS email, assigned_to AS assignedTo
|
||||
SELECT id, uuid, historyType, historyId, reason, created_at AS createdAt, send_at AS sendAt, e_mail AS email, assigned_to AS assignedTo
|
||||
FROM appeals
|
||||
WHERE uuid = #{uuid}
|
||||
""")
|
||||
|
|
|
|||
|
|
@ -107,6 +107,8 @@ public class InitializeWebDb {
|
|||
CREATE TABLE IF NOT EXISTS appeals (
|
||||
id UUID NOT NULL DEFAULT (UUID()) PRIMARY KEY,
|
||||
uuid UUID NOT NULL,
|
||||
historyType VARCHAR(16) NOT NULL,
|
||||
historyId BIGINT UNSIGNED NOT NULL,
|
||||
username VARCHAR(16) NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
|
|
|
|||
|
|
@ -145,6 +145,7 @@ export class AppealComponent implements OnInit, AfterViewInit {
|
|||
appeal: rawValue.appeal,
|
||||
email: rawValue.email,
|
||||
punishmentId: this.selectedPunishment()!.id,
|
||||
punishmentType: this.selectedPunishment()!.type,
|
||||
username: this.authService.username()!,
|
||||
uuid: uuid
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ components:
|
|||
- username
|
||||
- email
|
||||
- punishmentId
|
||||
- punishmentType
|
||||
- appeal
|
||||
properties:
|
||||
username:
|
||||
|
|
@ -107,6 +108,10 @@ components:
|
|||
punishmentId:
|
||||
type: integer
|
||||
description: Unique identifier of the punishment being appealed
|
||||
punishmentType:
|
||||
type: string
|
||||
enum: [ ban, mute, kick, warn ]
|
||||
description: Unique identifier of the punishment being appealed
|
||||
appeal:
|
||||
type: string
|
||||
description: Appeal text explaining why the punishment should be reconsidered
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user