Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Restructure non-notification mails to use data transfer objects #10219

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from

Conversation

xHadie
Copy link

@xHadie xHadie commented Jan 27, 2025

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I documented the Java code using JavaDoc style.

Motivation and Context

The usage of DTOs prevents the leakage of potentially sensitive information, makes use cases clearer, and results in more efficient data transfer.
In the context of the mail service, it allows developers to easily see what information is actually being transferred in a mail.

Furthermore, this PR introduces a straightforward testing strategy for HTML mail content generated by thymeleaf.
This ensures that the shift to DTOs within this PR did not break the interpretation and send logic of the mail messages. In addition, it allows us to test that DTO content is really being used within the mail content, making editing the scopes of DTOs and sending methods more convenient.

During development, it revealed, for instance, that the dataExportFailedAdminEmail.html template used the recipient username instead of the username connected to the data export.

In case this PR gets accepted, we can apply the same approach to the notification-based mails and also refactor the underlying bulk of thymeleaf fragments.

Implements a part of #9524

Description

Architecture:

  • Implemented AbstractMailContentTest, which allows testing HTML content generated by thymeleaf via getGeneratedEmailTemplateText for the correct rendering of text
  • Implemented IMailRecipientUserDTO, which contains the minimal set of required attributes a mail receiver needs to have to be compatible with MailSendingService. Individual mail templates will implement this interface in a dedicated recipient record, which may be extended with additional attributes
  • Adjusted MailSendingService::sendMail to use IMailRecipientUserDTO instead of User
  • Adjusted MailService::createBaseContext, MailService::sendEmailFromTemplate, MailService::prepareTemplateAndSendEmail and MailService::prepareTemplateAndSendEmailWithArgumentInSubject to use IMailRecipientUserDTO instead of User

[Use case] Activation mail:

  • Added ActivationMailRecipientDTO and the accompanying ActivationMailTest and adjusted MailService::sendActivationEmail to use the DTO
  • Adjusted activationEmail.html

[Use case] Password reset mail:

  • same as activation mail

[Use case] SAML2 password reset mail:

  • same as activation mail

[Use case] Data export failed mail:

  • Added DataExportFailedContentDTO, which contains only information that is relevant to the template
  • Added DataExportFailedMailAdminRecipientDTO and the accompanying ActivationMailTest and adjusted MailService::sendActivationEmail to use the DTOs
  • Adjusted the parameter list of MailService::sendDataExportFailedEmailForAdmin
  • Adjusted dataExportFailedAdminEmail.html

[Use case] Data export successful mail:

  • Added DataExportSuccessfulContentsDTO and DataExportSuccessfulContentDTO, which contain only information that is relevant to the template.
  • Added DataExportSuccessfulMailAdminRecipientDTO and the accompanying DataExportSuccessfulMailTest and adjusted MailService::sendSuccessfulDataExportsEmailToAdmin to use the dto
  • Adjusted the parameter list of MailService::sendSuccessfulDataExportsEmailToAdmin
  • Adjusted successfulDataExportsAdminEmail.html

[Use case] Notifications mails:

  • Added NotificationMailRecipientDTO and adjusted MailService::sendNotification
  • This is a minimal required change. Notifications will be adjusted to use DTOs in a separate PR

Additional Improvements:

  • Reduced the visibility of MailService::sendSuccessfulDataExportsEmailToAdmin from public to private and adjusted DataExportScheduleServiceTest to use the parent method with an equal name
  • Reduced the visibility of MailService::sendDataExportFailedEmailForAdmin from public to private
  • Reduced the visibility of MailService::sendEmailFromTemplate from public to private
  • Fixed wrong username usage in dataExportFailedAdminEmail.html

Identified issues:

  • creationEmail.html is not being used
  • Missing structures and naming conventions for mail templates and in general, mail-related project substructures
  • MailService needs refactoring and is doing too much. Some of the private methods are relevant only for single-use cases. In my opinion, it would make sense to extract individual mail construction into their own classes and let MailService delegate the constructed mails to MailSendingService.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

Use Case Instructions Manual Test - Local Manual Test - Server
Password Reset Email 1. Log out from Artemis.
2. Click "Forgot Password?".
3. Enter your registered email.
4. Click [Reset Password].
5. Verify that you receive a password reset email and check its content for accuracy.
Account Activation Email This test can only be performed locally. -
SAML2 Password Reset Email This test can only be performed locally. -
Data Export Failed Email This test can only be performed locally. -
Data Export Successful Email 1. Navigate to a test server with a Privacy Notice (e.g., TS3).
2. Click on Privacy in the footer.
3. Click Request Data Export.
4. Enter your geXXYYY username.
5. Verify that you receive an email (this may take a few days).
Notification Emails 1. Create a Text Exercise.
2. Wait a few minutes.
3. Verify that you receive an "Exercise Released" email notification.

Test Coverage

Class/File Line Coverage Confirmation (assert/expect)
ActivationMailRecipientDTO.java 100%
DataExportFailedContentDTO.java 100%
DataExportSuccessfulContentDTO.java 100%
DataExportSuccessfulContentsDTO.java 100%
DataExportSuccessfulMailAdminRecipientDTO.java 100%
NotificationMailRecipientDTO.java 100%
PasswordResetRecipientDTO.java 100%
SAML2SetPasswordMailRecipientDTO.java 100%
WeeklyExerciseSummaryDTO.java 100%
WeeklySummaryMailContentDTO.java 100%
WeeklySummaryMailRecipientDTO.java 100%
IMailRecipientUserDTO.java 100%
MailSendingService.java 100%
MailService.java 95%

Summary by CodeRabbit

  • New Features
    • Enhanced email notifications with improved content presentation for activations, password resets, data export alerts, and weekly summaries.
    • Introduction of new data transfer objects (DTOs) for email recipient handling, improving structure and clarity.
  • Bug Fixes
    • Updated email templates to correctly reference new data structures for user information and failure reasons.
  • Refactor
    • Updated the handling of email recipient data to ensure consistency and streamlined message formatting across all notifications.
  • Tests
    • Expanded automated tests to validate the correct injection and display of user data within all email templates.

@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) template communication Pull requests that affect the corresponding module core Pull requests that affect the corresponding module labels Jan 27, 2025
@xHadie xHadie temporarily deployed to artemis-test2.artemis.cit.tum.de January 27, 2025 10:38 — with GitHub Actions Inactive
@xHadie xHadie temporarily deployed to artemis-test3.artemis.cit.tum.de January 28, 2025 07:33 — with GitHub Actions Inactive
@xHadie xHadie temporarily deployed to artemis-test1.artemis.cit.tum.de January 28, 2025 10:16 — with GitHub Actions Inactive
Copy link

github-actions bot commented Feb 5, 2025

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@github-actions github-actions bot added the stale label Feb 5, 2025
@xHadie xHadie marked this pull request as ready for review February 5, 2025 21:30
@xHadie xHadie requested a review from a team as a code owner February 5, 2025 21:30
Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

The changes refactor the email notification functionality in the application. The updates modify method signatures in email-sending services to use specialized Data Transfer Objects (DTOs) instead of the User entity. A new DTO interface and multiple implementations have been added to encapsulate recipient data. In addition, email templates have been updated to reference the new DTO properties, and corresponding tests have been adjusted or added to validate that the correct variables are passed and rendered in the emails.

Changes

File(s) Change Summary
src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailSendingService.java
src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailService.java
Updated method signatures to accept DTOs rather than User objects; adjusted email address access from getEmail() to email(), and renamed several constants and parameters.
src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/... New interface and DTOs added: Introduced IMailRecipientUserDTO interface and multiple record/DTO classes (e.g., ActivationMailRecipientDTO, DataExportFailedContentDTO, DataExportFailedMailAdminRecipientDTO, DataExportSuccessfulContentDTO, DataExportSuccessfulContentsDTO, DataExportSuccessfulMailAdminRecipientDTO, NotificationMailRecipientDTO, PasswordResetRecipientDTO, SAML2SetPasswordMailRecipientDTO, WeeklyExerciseSummaryDTO, WeeklySummaryMailContentDTO, WeeklySummaryMailRecipientDTO) with static factory methods for conversion from User and DataExport objects.
src/main/resources/templates/mail/... Template updates: Updated variables in email HTML templates (for data export failure, successful exports, weekly summary, etc.) to use new DTO properties and direct property access rather than method calls.
src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/...
src/test/java/de/tum/cit/aet/artemis/core/service/DataExportScheduleServiceTest.java
Test updates and additions: Modified test cases to pass DTOs instead of User objects and added new tests (e.g., ActivationMailTest, DataExportFailedMailTest, DataExportSuccessfulMailTest, PasswordResetMailTest, SAML2SetPasswordMailTest, WeeklySummaryMailTest) as well as a new abstract test class for mail content.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant MS as MailService
    participant MTS as MailSendingService
    participant TE as TemplateEngine

    U->>MS: Request email action (e.g., activation)
    Note over MS: Convert User to proper DTO\n(e.g., ActivationMailRecipientDTO)
    MS->>MTS: Call sendEmail(DTO, subject, content, flags)
    MTS->>TE: Render email template using DTO properties
    TE-->>MTS: Return rendered email content
    MTS-->>MS: Confirm email sending
    MS-->>U: Email sent (logged or notified)
Loading

Suggested labels

tutorialgroup

Suggested reviewers

  • JohannesStoehr
  • BBesrour
  • iyannsch
  • cremertim

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 PMD (7.8.0)
src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java

[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitch instead of the deprecated Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt. PMD 8.0.0 will remove support for this deprecated Rule name usage.

67|
68|
[ERROR] Error at ruleset.xml:71:5
69|
70|
71|
^^^^^ Unable to find referenced rule DontImportJavaLang; perhaps the rule name is misspelled?

72|
73|
[ERROR] Error at ruleset.xml:75:5
73|
74|
75|
^^^^^ Unable to find referenced rule DuplicateImports; perhaps the rule name is misspelled?

76|
77|
[ERROR] Error at ruleset.xml:78:5
76|
77|
78|
^^^^^ Unable to find referenced rule EmptyFinallyBlock; perhaps the rule name is misspelled?

79|
80|
[ERROR] Error at ruleset.xml:79:5
77|
78|
79|
^^^^^ Unable to find referenced rule EmptyIfStmt; perhaps the rule name is misspelled?

80|
81|
[ERROR] Error at ruleset.xml:81:5
79|
80|
81|
^^^^^ Unable to find referenced rule EmptyInitializer; perhaps the rule name is misspelled?

82|
83|
[ERROR] Error at ruleset.xml:82:5
80|
81|
82|
^^^^^ Unable to find referenced rule EmptyStatementBlock; perhaps the rule name is misspelled?

83|
84|
[ERROR] Error at ruleset.xml:83:5
81|
82|
83|
^^^^^ Unable to find referenced rule EmptyStatementNotInLoop; perhaps the rule name is misspelled?

84|
85|
[ERROR] Error at ruleset.xml:84:5
82|
83|
84|
^^^^^ Unable to find referenced rule EmptySwitchStatements; perhaps the rule name is misspelled?

85|
86|
[ERROR] Error at ruleset.xml:85:5
83|
84|
85|
^^^^^ Unable to find referenced rule EmptySynchronizedBlock; perhaps the rule name is misspelled?

86|
87|
[ERROR] Error at ruleset.xml:86:5
84|
85|
86|
^^^^^ Unable to find referenced rule EmptyTryBlock; perhaps the rule name is misspelled?

87|
88|
[ERROR] Error at ruleset.xml:87:5
85|
86|
87|
^^^^^ Unable to find referenced rule EmptyWhileStmt; perhaps the rule name is misspelled?

88|
89|
[ERROR] Error at ruleset.xml:90:5
88|
89|
90|
^^^^^ Unable to find referenced rule ExcessiveClassLength; perhaps the rule name is misspelled?

91|
92|
[ERROR] Error at ruleset.xml:91:5
89|
90|
91|
^^^^^ Unable to find referenced rule ExcessiveMethodLength; perhaps the rule name is misspelled?

92|
93|
[ERROR] Error at ruleset.xml:106:5
104|
105|
106|
^^^^^ Unable to find referenced rule ImportFromSamePackage; perhaps the rule name is misspelled?

107|
108|
[ERROR] Error at ruleset.xml:119:5
117|
118|
119|
^^^^^ Unable to find referenced rule MissingBreakInSwitch; perhaps the rule name is misspelled?

120|
121|
[WARN] Warning at ruleset.xml:124:5
122|
123|
124|
^^^^^ Use Rule name category/java/errorprone.xml/NonCaseLabelInSwitch instead of the deprecated Rule name category/java/errorprone.xml/NonCaseLabelInSwitchStatement. PMD 8.0.0 will remove support for this deprecated Rule name usage.

125|
126|
[ERROR] Error at ruleset.xml:134:9
132|
133| // It's okay to use short variable names in DTOs, e.g. "id" or "name"
134| ./de/tum/in/www1/artemis/web/rest/dto/.
^^^^^^^^^^^^^^^^ Unexpected element 'exclude-pattern' in rule ShortVariable

135|
136|
[ERROR] Error at ruleset.xml:137:5
135|
136|
137|
^^^^^ Unable to find referenced rule SimplifyBooleanAssertion; perhaps the rule name is misspelled?

138|
139|
[WARN] Warning at ruleset.xml:184:5
182|
183|
184|
^^^^^ Use Rule name category/ecmascript/errorprone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java

[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitch instead of the deprecated Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt. PMD 8.0.0 will remove support for this deprecated Rule name usage.

67|
68|
[ERROR] Error at ruleset.xml:71:5
69|
70|
71|
^^^^^ Unable to find referenced rule DontImportJavaLang; perhaps the rule name is misspelled?

72|
73|
[ERROR] Error at ruleset.xml:75:5
73|
74|
75|
^^^^^ Unable to find referenced rule DuplicateImports; perhaps the rule name is misspelled?

76|
77|
[ERROR] Error at ruleset.xml:78:5
76|
77|
78|
^^^^^ Unable to find referenced rule EmptyFinallyBlock; perhaps the rule name is misspelled?

79|
80|
[ERROR] Error at ruleset.xml:79:5
77|
78|
79|
^^^^^ Unable to find referenced rule EmptyIfStmt; perhaps the rule name is misspelled?

80|
81|
[ERROR] Error at ruleset.xml:81:5
79|
80|
81|
^^^^^ Unable to find referenced rule EmptyInitializer; perhaps the rule name is misspelled?

82|
83|
[ERROR] Error at ruleset.xml:82:5
80|
81|
82|
^^^^^ Unable to find referenced rule EmptyStatementBlock; perhaps the rule name is misspelled?

83|
84|
[ERROR] Error at ruleset.xml:83:5
81|
82|
83|
^^^^^ Unable to find referenced rule EmptyStatementNotInLoop; perhaps the rule name is misspelled?

84|
85|
[ERROR] Error at ruleset.xml:84:5
82|
83|
84|
^^^^^ Unable to find referenced rule EmptySwitchStatements; perhaps the rule name is misspelled?

85|
86|
[ERROR] Error at ruleset.xml:85:5
83|
84|
85|
^^^^^ Unable to find referenced rule EmptySynchronizedBlock; perhaps the rule name is misspelled?

86|
87|
[ERROR] Error at ruleset.xml:86:5
84|
85|
86|
^^^^^ Unable to find referenced rule EmptyTryBlock; perhaps the rule name is misspelled?

87|
88|
[ERROR] Error at ruleset.xml:87:5
85|
86|
87|
^^^^^ Unable to find referenced rule EmptyWhileStmt; perhaps the rule name is misspelled?

88|
89|
[ERROR] Error at ruleset.xml:90:5
88|
89|
90|
^^^^^ Unable to find referenced rule ExcessiveClassLength; perhaps the rule name is misspelled?

91|
92|
[ERROR] Error at ruleset.xml:91:5
89|
90|
91|
^^^^^ Unable to find referenced rule ExcessiveMethodLength; perhaps the rule name is misspelled?

92|
93|
[ERROR] Error at ruleset.xml:106:5
104|
105|
106|
^^^^^ Unable to find referenced rule ImportFromSamePackage; perhaps the rule name is misspelled?

107|
108|
[ERROR] Error at ruleset.xml:119:5
117|
118|
119|
^^^^^ Unable to find referenced rule MissingBreakInSwitch; perhaps the rule name is misspelled?

120|
121|
[WARN] Warning at ruleset.xml:124:5
122|
123|
124|
^^^^^ Use Rule name category/java/errorprone.xml/NonCaseLabelInSwitch instead of the deprecated Rule name category/java/errorprone.xml/NonCaseLabelInSwitchStatement. PMD 8.0.0 will remove support for this deprecated Rule name usage.

125|
126|
[ERROR] Error at ruleset.xml:134:9
132|
133| // It's okay to use short variable names in DTOs, e.g. "id" or "name"
134| ./de/tum/in/www1/artemis/web/rest/dto/.
^^^^^^^^^^^^^^^^ Unexpected element 'exclude-pattern' in rule ShortVariable

135|
136|
[ERROR] Error at ruleset.xml:137:5
135|
136|
137|
^^^^^ Unable to find referenced rule SimplifyBooleanAssertion; perhaps the rule name is misspelled?

138|
139|
[WARN] Warning at ruleset.xml:184:5
182|
183|
184|
^^^^^ Use Rule name category/ecmascript/errorprone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java

[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitch instead of the deprecated Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt. PMD 8.0.0 will remove support for this deprecated Rule name usage.

67|
68|
[ERROR] Error at ruleset.xml:71:5
69|
70|
71|
^^^^^ Unable to find referenced rule DontImportJavaLang; perhaps the rule name is misspelled?

72|
73|
[ERROR] Error at ruleset.xml:75:5
73|
74|
75|
^^^^^ Unable to find referenced rule DuplicateImports; perhaps the rule name is misspelled?

76|
77|
[ERROR] Error at ruleset.xml:78:5
76|
77|
78|
^^^^^ Unable to find referenced rule EmptyFinallyBlock; perhaps the rule name is misspelled?

79|
80|
[ERROR] Error at ruleset.xml:79:5
77|
78|
79|
^^^^^ Unable to find referenced rule EmptyIfStmt; perhaps the rule name is misspelled?

80|
81|
[ERROR] Error at ruleset.xml:81:5
79|
80|
81|
^^^^^ Unable to find referenced rule EmptyInitializer; perhaps the rule name is misspelled?

82|
83|
[ERROR] Error at ruleset.xml:82:5
80|
81|
82|
^^^^^ Unable to find referenced rule EmptyStatementBlock; perhaps the rule name is misspelled?

83|
84|
[ERROR] Error at ruleset.xml:83:5
81|
82|
83|
^^^^^ Unable to find referenced rule EmptyStatementNotInLoop; perhaps the rule name is misspelled?

84|
85|
[ERROR] Error at ruleset.xml:84:5
82|
83|
84|
^^^^^ Unable to find referenced rule EmptySwitchStatements; perhaps the rule name is misspelled?

85|
86|
[ERROR] Error at ruleset.xml:85:5
83|
84|
85|
^^^^^ Unable to find referenced rule EmptySynchronizedBlock; perhaps the rule name is misspelled?

86|
87|
[ERROR] Error at ruleset.xml:86:5
84|
85|
86|
^^^^^ Unable to find referenced rule EmptyTryBlock; perhaps the rule name is misspelled?

87|
88|
[ERROR] Error at ruleset.xml:87:5
85|
86|
87|
^^^^^ Unable to find referenced rule EmptyWhileStmt; perhaps the rule name is misspelled?

88|
89|
[ERROR] Error at ruleset.xml:90:5
88|
89|
90|
^^^^^ Unable to find referenced rule ExcessiveClassLength; perhaps the rule name is misspelled?

91|
92|
[ERROR] Error at ruleset.xml:91:5
89|
90|
91|
^^^^^ Unable to find referenced rule ExcessiveMethodLength; perhaps the rule name is misspelled?

92|
93|
[ERROR] Error at ruleset.xml:106:5
104|
105|
106|
^^^^^ Unable to find referenced rule ImportFromSamePackage; perhaps the rule name is misspelled?

107|
108|
[ERROR] Error at ruleset.xml:119:5
117|
118|
119|
^^^^^ Unable to find referenced rule MissingBreakInSwitch; perhaps the rule name is misspelled?

120|
121|
[WARN] Warning at ruleset.xml:124:5
122|
123|
124|
^^^^^ Use Rule name category/java/errorprone.xml/NonCaseLabelInSwitch instead of the deprecated Rule name category/java/errorprone.xml/NonCaseLabelInSwitchStatement. PMD 8.0.0 will remove support for this deprecated Rule name usage.

125|
126|
[ERROR] Error at ruleset.xml:134:9
132|
133| // It's okay to use short variable names in DTOs, e.g. "id" or "name"
134| ./de/tum/in/www1/artemis/web/rest/dto/.
^^^^^^^^^^^^^^^^ Unexpected element 'exclude-pattern' in rule ShortVariable

135|
136|
[ERROR] Error at ruleset.xml:137:5
135|
136|
137|
^^^^^ Unable to find referenced rule SimplifyBooleanAssertion; perhaps the rule name is misspelled?

138|
139|
[WARN] Warning at ruleset.xml:184:5
182|
183|
184|
^^^^^ Use Rule name category/ecmascript/errorprone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

  • 1 others
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot]

This comment was marked as resolved.

xHadie and others added 4 commits February 6, 2025 20:15
…um/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailRecipientDTO.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…um/cit/aet/artemis/communication/service/notifications/mails/dto/notifications/NotificationMailRecipientDTO.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…um/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…um/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 6, 2025
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 7, 2025
@helios-aet helios-aet bot temporarily deployed to artemis-test7.artemis.cit.tum.de February 7, 2025 17:08 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java (1)

27-35: ⚠️ Potential issue

Add validation and sanitize exception message.

The current implementation has potential issues:

  1. No sanitization of exception messages
  2. Raw exception message might contain sensitive information

Apply this diff to implement message sanitization:

    public static DataExportFailedContentDTO of(Exception exception, DataExport dataExport) {
        if (exception == null || dataExport == null) {
            throw new IllegalArgumentException("Parameters cannot be null");
        }
        if (dataExport.getUser() == null) {
            throw new IllegalStateException("DataExport user cannot be null");
        }
+       // Sanitize exception message to prevent sensitive information leakage
+       String sanitizedMessage = sanitizeExceptionMessage(exception.getMessage());
-       return new DataExportFailedContentDTO(exception.getMessage(), dataExport.getUser().getLogin());
+       return new DataExportFailedContentDTO(sanitizedMessage, dataExport.getUser().getLogin());
    }

+   private static String sanitizeExceptionMessage(String message) {
+       if (message == null) {
+           return "Unknown error";
+       }
+       // Remove potential sensitive information
+       return message.replaceAll("(?i)(password|secret|key|token|credentials)=.*?(&|$)", "$1=*****$2")
+                    .replaceAll("(?i)(jdbc|ftp|sftp|smtp)://[^\\s]*", "[REDACTED_URL]")
+                    .replaceAll("\\d{4}[- ]?\\d{4}[- ]?\\d{4}[- ]?\\d{4}", "[REDACTED_CARD_NUMBER]");
+   }
🧹 Nitpick comments (1)
src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java (1)

8-12: LGTM! Well-structured DTO using Java record.

The implementation follows best practices:

  • Uses Java record for immutable data structure
  • Implements the DTO interface contract
  • Includes JSON serialization optimization

Consider enhancing the class-level JavaDoc to document the purpose of each field:

 /**
  * DTO for the password reset mail recipient
+ *
+ * @param langKey  The language key for localization
+ * @param email    The recipient's email address
+ * @param login    The recipient's login identifier
+ * @param resetKey The password reset token
  */
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f86988f and b65f74a.

📒 Files selected for processing (4)
  • src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/saml2_set_password_mail/SAML2SetPasswordMailRecipientDTO.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java
  • src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/saml2_set_password_mail/SAML2SetPasswordMailRecipientDTO.java
🧰 Additional context used
📓 Path-based instructions (1)
`src/main/java/**/*.java`: naming:CamelCase; principles:{sin...

src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

  • src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java
  • src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: Call Build Workflow / Build .war artifact
  • GitHub Check: client-tests
  • GitHub Check: client-style
  • GitHub Check: server-style
  • GitHub Check: server-tests
  • GitHub Check: Analyse
🔇 Additional comments (6)
src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java (2)

1-7: LGTM! Package structure and imports are well-organized.

The package structure follows Java conventions, and imports are specific without any star imports.


14-31: LGTM! Factory method includes proper validation.

The implementation includes appropriate null checks and validation as previously suggested, with clear error messages and well-documented exceptions.

src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java (4)

1-6: LGTM!

Package structure follows naming conventions and imports are properly organized without wildcards.


7-13: LGTM!

Documentation is clear and complete. The @JsonInclude annotation helps minimize the DTO payload.


14-14: LGTM!

Appropriate use of Java record for an immutable DTO with minimal data fields.


16-26: LGTM!

Factory method documentation is thorough and clearly describes parameters, return value, and potential exceptions.

Copy link
Contributor

@ole-ve ole-ve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the code, see my inline comments.

Really simplifies the mail templating, nice work 👍

}

private void prepareTemplateAndSendEmail(User admin, String templateName, String titleKey, Context context) {
private void prepareTemplateAndSendEmail(IMailRecipientUserDTO recipient, String templateName, String titleKey, Context context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recipientAdmin for consistency (also for other occurrences)

/**
* Retrieve the content of the interpreted thymeleaf template, which represents the mail content.
*/
protected String getGeneratedEmailTemplateText() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could image that this might introduce some flakyness to server tests by running two instances of getGeneratedEmailTemplateText in parallel. Could we maybe parameterize the method with something unique, like the subject for instance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
communication Pull requests that affect the corresponding module core Pull requests that affect the corresponding module ready for review server Pull requests that update Java code. (Added Automatically!) template tests
Projects
Status: Ready For Review
Status: Todo
Development

Successfully merging this pull request may close these issues.

2 participants