diff --git a/backend/src/main/java/com/alttd/altitudeweb/controllers/forms/AppealController.java b/backend/src/main/java/com/alttd/altitudeweb/controllers/forms/AppealController.java index f019e01..b6e9e46 100644 --- a/backend/src/main/java/com/alttd/altitudeweb/controllers/forms/AppealController.java +++ b/backend/src/main/java/com/alttd/altitudeweb/controllers/forms/AppealController.java @@ -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 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 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(); + } } diff --git a/backend/src/main/java/com/alttd/altitudeweb/services/mail/AppealMail.java b/backend/src/main/java/com/alttd/altitudeweb/services/mail/AppealMail.java index ea919b5..fe5f130 100644 --- a/backend/src/main/java/com/alttd/altitudeweb/services/mail/AppealMail.java +++ b/backend/src/main/java/com/alttd/altitudeweb/services/mail/AppealMail.java @@ -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); diff --git a/backend/src/main/resources/templates/appeal-email.html b/backend/src/main/resources/templates/appeal-email.html index 56deb00..f6694a4 100644 --- a/backend/src/main/resources/templates/appeal-email.html +++ b/backend/src/main/resources/templates/appeal-email.html @@ -17,7 +17,9 @@
  • Username: username
  • UUID: uuid
  • Email: email
  • -
  • Submitted: date
  • +
  • Submitted at: date
  • +
  • Reason: reason
  • +
  • Active: unknown
  • Appeal:

    Reason text

    diff --git a/database/src/main/java/com/alttd/altitudeweb/database/web_db/forms/Appeal.java b/database/src/main/java/com/alttd/altitudeweb/database/web_db/forms/Appeal.java index 04a608e..cd7099d 100644 --- a/database/src/main/java/com/alttd/altitudeweb/database/web_db/forms/Appeal.java +++ b/database/src/main/java/com/alttd/altitudeweb/database/web_db/forms/Appeal.java @@ -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, diff --git a/database/src/main/java/com/alttd/altitudeweb/database/web_db/forms/AppealMapper.java b/database/src/main/java/com/alttd/altitudeweb/database/web_db/forms/AppealMapper.java index 09b6d34..edf5931 100644 --- a/database/src/main/java/com/alttd/altitudeweb/database/web_db/forms/AppealMapper.java +++ b/database/src/main/java/com/alttd/altitudeweb/database/web_db/forms/AppealMapper.java @@ -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} """) diff --git a/database/src/main/java/com/alttd/altitudeweb/setup/InitializeWebDb.java b/database/src/main/java/com/alttd/altitudeweb/setup/InitializeWebDb.java index a8aa398..b89c27d 100644 --- a/database/src/main/java/com/alttd/altitudeweb/setup/InitializeWebDb.java +++ b/database/src/main/java/com/alttd/altitudeweb/setup/InitializeWebDb.java @@ -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, diff --git a/frontend/src/app/pages/forms/appeal/appeal.component.ts b/frontend/src/app/pages/forms/appeal/appeal.component.ts index 195212d..489edfb 100644 --- a/frontend/src/app/pages/forms/appeal/appeal.component.ts +++ b/frontend/src/app/pages/forms/appeal/appeal.component.ts @@ -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 } diff --git a/open_api/src/main/resources/schemas/forms/appeal/appeal.yml b/open_api/src/main/resources/schemas/forms/appeal/appeal.yml index e54fce8..213eb26 100644 --- a/open_api/src/main/resources/schemas/forms/appeal/appeal.yml +++ b/open_api/src/main/resources/schemas/forms/appeal/appeal.yml @@ -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