Add JSON response handling for form activity check
Refactor `FormActiveController` to return JSON responses using `BooleanResponse`. Introduce exception handling for JSON processing errors and update `FormActiveData` to allow object initialization without parameters.
This commit is contained in:
parent
a9d4377599
commit
1a5be5021b
|
|
@ -4,10 +4,11 @@
|
|||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="ce59df2a-8d56-446a-867b-80e627daf479" name="Changes" comment="Correct regex pattern for case-insensitive match Updated the regex pattern in `StaffAppFormData.java` to ensure that the "yes" or "no" answers are case-insensitive. This improves the form validation to accept "Yes", "YES", "No", or "NO" without errors.">
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/mail/rate_limitter/RateLimitEntryDTO.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/mail/rate_limitter/RateLimitQuery.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<list default="true" id="ce59df2a-8d56-446a-867b-80e627daf479" name="Changes" comment="Ensure NOT NULL constraints in SQL tables Refactor SQL table creation scripts to add NOT NULL constraints where necessary. This change ensures data integrity by preventing null values in critical columns across the 'verify_form', 'form', 'rate_limit', and 'form_active' tables.">
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/controlers/form_active/BooleanResponse.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/controlers/form_active/FormActiveController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/controlers/form_active/FormActiveController.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/controlers/form_active/FormActiveData.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/controlers/form_active/FormActiveData.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/resources/application.properties" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/application.properties" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
|
@ -51,10 +52,16 @@
|
|||
<option value="package-info" />
|
||||
<option value="package.json" />
|
||||
<option value="Class" />
|
||||
<option value="Record" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="master" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="GitHubPullRequestSearchHistory">{
|
||||
|
|
@ -97,48 +104,56 @@
|
|||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"Gradle.Build forms.executor": "Run",
|
||||
"Gradle.TestForm.executor": "Run",
|
||||
"Gradle.TestForm.testFunctions.executor": "Debug",
|
||||
"Gradle.TestForm.testRetrieveForm.executor": "Run",
|
||||
"RequestMappingsPanelOrder0": "0",
|
||||
"RequestMappingsPanelOrder1": "1",
|
||||
"RequestMappingsPanelWidth0": "75",
|
||||
"RequestMappingsPanelWidth1": "75",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"Spring Boot.Main.executor": "Run",
|
||||
"Tomcat Server.Tomcat 10.1.17.executor": "Run",
|
||||
"git-widget-placeholder": "master",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "P:/Code/Plugins/forms",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"project.structure.last.edited": "Project",
|
||||
"project.structure.proportion": "0.0",
|
||||
"project.structure.side.proportion": "0.0",
|
||||
"run.code.analysis.last.selected.profile": "pProject Default",
|
||||
"settings.editor.selected.configurable": "preferences.lookFeel",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Downloaded.Files.Path.Enabled": "false",
|
||||
"Gradle.Build forms.executor": "Run",
|
||||
"Gradle.TestForm.executor": "Run",
|
||||
"Gradle.TestForm.testFunctions.executor": "Debug",
|
||||
"Gradle.TestForm.testRetrieveForm.executor": "Run",
|
||||
"Repository.Attach.Annotations": "false",
|
||||
"Repository.Attach.JavaDocs": "false",
|
||||
"Repository.Attach.Sources": "false",
|
||||
"RequestMappingsPanelOrder0": "0",
|
||||
"RequestMappingsPanelOrder1": "1",
|
||||
"RequestMappingsPanelWidth0": "75",
|
||||
"RequestMappingsPanelWidth1": "75",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"Spring Boot.Main.executor": "Run",
|
||||
"Tomcat Server.Tomcat 10.1.17.executor": "Run",
|
||||
"git-widget-placeholder": "rate__limit",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "P:/Code/Plugins/forms",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"project.structure.last.edited": "Project",
|
||||
"project.structure.proportion": "0.0",
|
||||
"project.structure.side.proportion": "0.0",
|
||||
"run.code.analysis.last.selected.profile": "pProject Default",
|
||||
"settings.editor.selected.configurable": "preferences.lookFeel",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
},
|
||||
"keyToStringList": {
|
||||
"DatabaseDriversLRU": [
|
||||
"mysql",
|
||||
"mariadb"
|
||||
"keyToStringList": {
|
||||
"DatabaseDriversLRU": [
|
||||
"mysql",
|
||||
"mariadb"
|
||||
]
|
||||
}
|
||||
}</component>
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CreateClassDialog.RecentsKey">
|
||||
<recent name="com.alttd.forms.apply" />
|
||||
</key>
|
||||
<key name="CopyClassDialog.RECENTS_KEY">
|
||||
<recent name="com.alttd.forms.controlers.form_active" />
|
||||
<recent name="com.alttd.forms.form" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager" selected="Spring Boot.Main">
|
||||
<configuration name="TestForm" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
||||
|
|
@ -369,6 +384,7 @@
|
|||
<workItem from="1723057624940" duration="2895000" />
|
||||
<workItem from="1723138548381" duration="1949000" />
|
||||
<workItem from="1723230192640" duration="55000" />
|
||||
<workItem from="1723242314809" duration="9799000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Initial commit for site for forms">
|
||||
<option name="closed" value="true" />
|
||||
|
|
@ -578,7 +594,63 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1723059265558</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="27" />
|
||||
<task id="LOCAL-00027" summary="Remove restriction on dot character in Discord name validation This change allows Discord names to include dots anywhere within the name, increasing flexibility for valid usernames. The previous regex pattern incorrectly restricted dots, affecting valid user entries.">
|
||||
<option name="closed" value="true" />
|
||||
<created>1723242929470</created>
|
||||
<option name="number" value="00027" />
|
||||
<option name="presentableId" value="LOCAL-00027" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1723242929470</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00028" summary="Add StaffAppFormData handling in FormQuery Imported StaffAppFormData and updated deserialization logic to include it as a case in the FormQuery class. This allows the processing of staff application forms when parsing form data from JSON.">
|
||||
<option name="closed" value="true" />
|
||||
<created>1723242942749</created>
|
||||
<option name="number" value="00028" />
|
||||
<option name="presentableId" value="LOCAL-00028" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1723242942749</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00029" summary="workspace.xml update">
|
||||
<option name="closed" value="true" />
|
||||
<created>1723242960642</created>
|
||||
<option name="number" value="00029" />
|
||||
<option name="presentableId" value="LOCAL-00029" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1723242960642</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00030" summary="Add rate limiting functionality Introduces a new 'rate_limit' table to track request counts by IP and email. Adds `RateLimitQuery` class for querying and inserting rate limits, and `RateLimitEntryDTO` for passing rate limit data.">
|
||||
<option name="closed" value="true" />
|
||||
<created>1723243853994</created>
|
||||
<option name="number" value="00030" />
|
||||
<option name="presentableId" value="LOCAL-00030" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1723243853994</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00031" summary="Refactor form request handling and add rate limiting. Consolidate email verification logic into FormRequestHandler to simplify code maintenance. Implement a new rate limiting feature to restrict form submissions based on IP and email address, improving server security and performance.">
|
||||
<option name="closed" value="true" />
|
||||
<created>1723247556185</created>
|
||||
<option name="number" value="00031" />
|
||||
<option name="presentableId" value="LOCAL-00031" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1723247556185</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00032" summary="Add form activity checking and global rate limiting Implemented new features to track form activity and enforce global rate limits. Added a `form_active` table and created endpoints to check form activity. Also, introduced a rate-limiting filter to restrict API requests to 30 per minute per IP.">
|
||||
<option name="closed" value="true" />
|
||||
<created>1723249700073</created>
|
||||
<option name="number" value="00032" />
|
||||
<option name="presentableId" value="LOCAL-00032" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1723249700073</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00033" summary="Ensure NOT NULL constraints in SQL tables Refactor SQL table creation scripts to add NOT NULL constraints where necessary. This change ensures data integrity by preventing null values in critical columns across the 'verify_form', 'form', 'rate_limit', and 'form_active' tables.">
|
||||
<option name="closed" value="true" />
|
||||
<created>1723249968746</created>
|
||||
<option name="number" value="00033" />
|
||||
<option name="presentableId" value="LOCAL-00033" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1723249968746</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="34" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
|
|
@ -596,14 +668,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="Remove unnecessary Gson imports in ContactFormData The Gson and GsonBuilder imports in the ContactFormData class were unused and have been removed. This cleanup simplifies the code and reduces unnecessary dependencies. " />
|
||||
<MESSAGE value="Mark fields as final in VerificationData and ContactFormData The 'code', 'eMail' fields in the VerificationData class and 'username', 'email', 'question' fields in the ContactFormData class are now marked as 'final'. At the same time, some unused imports from ContactController, ContactFormData, FormQuery, and VerifyController have been removed for code cleanliness." />
|
||||
<MESSAGE value="Update Form HTML output and disable validation auto-configuration The form-to-HTML output process has been switched from a `<div>` approach to using a `StringBuilder` with a table structure in `ContactFormData.java`. Also, the spring validation auto-configuration has been disabled by adding `exclude = ValidationAutoConfiguration.class` in the `@SpringBootApplication` annotation of `Main.java`. Some changes in `.idea/workspace.xml` and `VerifyController.java` were made as well." />
|
||||
<MESSAGE value="Add database configuration via command-line arguments A new configuration setup now allows specifying a path for database properties via command-line arguments during application startup. This update also changes the call signature for `DatabaseConnection.initialize()` method to accept a path argument. Similarly, methods in `PropertiesLoader`, `PropertiesWriter`, and `MailSettings` classes were also updated to use the specified path when working with properties files. The `TestForm` class's tests were updated accordingly to handle these changes." />
|
||||
<MESSAGE value="Add DB config via command-line arguments A new setup allows specifying database properties path using command-line arguments during startup. The `DatabaseConnection.initialize()` method signature has been updated to accept a path argument. Methods in `PropertiesLoader`, `PropertiesWriter`, and `MailSettings` classes, along with tests in the `TestForm` class, were adjusted accordingly." />
|
||||
<MESSAGE value="Add Jenkins pipeline for Gradle build and notifications This commit introduces a new Jenkinsfile configured to build the project using Gradle and archive the resulting artifacts. Additionally, it includes a stage to send build notifications to Discord with details about the build status." />
|
||||
<MESSAGE value="Disable database tests in Jenkins Disabled tests that require a database connection to prevent failures in Jenkins where there isn't a database. Updated Jenkinsfile to include a property that skips these tests during the build process." />
|
||||
<MESSAGE value="Fix typo in Gradle build command in Jenkinsfile Corrected the parameter for skipping database tests from `dontRunDatabaseTests` to `doNotRunDatabaseTests` in the Gradle build step. This ensures the intended tests are skipped during the build process." />
|
||||
<MESSAGE value="Configure system property for conditional test execution Added a system property 'doNotRunDatabaseTests' in the test configuration to allow conditional skipping of database tests. This helps in running tests selectively during different build scenarios." />
|
||||
<MESSAGE value="Add CORS support for production server Updated the CORS configuration to include the production server URL. This change ensures that requests from the production environment are properly handled." />
|
||||
<MESSAGE value="Refactor logging for better granularity Updated logging levels in multiple classes to differentiate between debug and trace information. Improved log messages to support parameterized logs, ensuring sensitive or variable information is handled appropriately without concatenation." />
|
||||
|
|
@ -621,6 +685,14 @@
|
|||
<MESSAGE value="Add validation exception handling to StaffAppController Introduced an `ExceptionHandler` for `MethodArgumentNotValidException` in `StaffAppController` to return detailed validation error messages. Updated the regex pattern in `StaffAppFormData` to be case-insensitive. This enhances error reporting and user input validation in the application." />
|
||||
<MESSAGE value="Refactor packages and add exception handler. Renamed various classes to follow the "controlers" package structure for better organization and consistency. Added `ControllerExceptionHandler` to manage validation exceptions globally and improve error logging." />
|
||||
<MESSAGE value="Correct regex pattern for case-insensitive match Updated the regex pattern in `StaffAppFormData.java` to ensure that the "yes" or "no" answers are case-insensitive. This improves the form validation to accept "Yes", "YES", "No", or "NO" without errors." />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Correct regex pattern for case-insensitive match Updated the regex pattern in `StaffAppFormData.java` to ensure that the "yes" or "no" answers are case-insensitive. This improves the form validation to accept "Yes", "YES", "No", or "NO" without errors." />
|
||||
<MESSAGE value="Remove restriction on dot character in Discord name validation This change allows Discord names to include dots anywhere within the name, increasing flexibility for valid usernames. The previous regex pattern incorrectly restricted dots, affecting valid user entries." />
|
||||
<MESSAGE value="Add StaffAppFormData handling in FormQuery Imported StaffAppFormData and updated deserialization logic to include it as a case in the FormQuery class. This allows the processing of staff application forms when parsing form data from JSON." />
|
||||
<MESSAGE value="workspace.xml update" />
|
||||
<MESSAGE value="Add rate limiting functionality Introduces a new 'rate_limit' table to track request counts by IP and email. Adds `RateLimitQuery` class for querying and inserting rate limits, and `RateLimitEntryDTO` for passing rate limit data." />
|
||||
<MESSAGE value="Add IP rate limiting for form submissions Added IP rate limiting to prevent abuse in form submissions by tracking IP and email address attempts. Updated the form submission methods to include IP in email verification and added detailed HTML email content." />
|
||||
<MESSAGE value="Refactor form request handling and add rate limiting. Consolidate email verification logic into FormRequestHandler to simplify code maintenance. Implement a new rate limiting feature to restrict form submissions based on IP and email address, improving server security and performance." />
|
||||
<MESSAGE value="Add form activity checking and global rate limiting Implemented new features to track form activity and enforce global rate limits. Added a `form_active` table and created endpoints to check form activity. Also, introduced a rate-limiting filter to restrict API requests to 30 per minute per IP." />
|
||||
<MESSAGE value="Ensure NOT NULL constraints in SQL tables Refactor SQL table creation scripts to add NOT NULL constraints where necessary. This change ensures data integrity by preventing null values in critical columns across the 'verify_form', 'form', 'rate_limit', and 'form_active' tables." />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Ensure NOT NULL constraints in SQL tables Refactor SQL table creation scripts to add NOT NULL constraints where necessary. This change ensures data integrity by preventing null values in critical columns across the 'verify_form', 'form', 'rate_limit', and 'form_active' tables." />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package com.alttd.forms.controlers.form_active;
|
||||
|
||||
public record BooleanResponse(boolean isActive) {
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package com.alttd.forms.controlers.form_active;
|
||||
|
||||
import com.alttd.forms.form.FormSettingsQuery;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.validation.Valid;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -21,7 +22,7 @@ public class FormActiveController {
|
|||
private static final Logger logger = LoggerFactory.getLogger(FormActiveController.class);
|
||||
|
||||
@PostMapping("/formActive")
|
||||
public CompletableFuture<ResponseEntity<String>> formActiveRequest(@Valid @RequestBody FormActiveData formData, HttpServletRequest request) {
|
||||
public CompletableFuture<ResponseEntity<String>> formActiveRequest(@Valid @RequestBody FormActiveData formData) {
|
||||
logger.debug("formActive");
|
||||
logger.trace(formData.toString());
|
||||
|
||||
|
|
@ -29,12 +30,17 @@ public class FormActiveController {
|
|||
return formSettingsQuery
|
||||
.isActive(formData.formName)
|
||||
.thenApply(result -> {
|
||||
if (result.isEmpty()) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to check if the form is active");
|
||||
} else if (result.get()) {
|
||||
return ResponseEntity.ok("yes");
|
||||
} else {
|
||||
return ResponseEntity.ok("no");
|
||||
try {
|
||||
if (result.isEmpty()) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to check if the form is active");
|
||||
} else if (result.get()) {
|
||||
return ResponseEntity.ok(new ObjectMapper().writeValueAsString(new BooleanResponse(true)));
|
||||
} else {
|
||||
return ResponseEntity.ok(new ObjectMapper().writeValueAsString(new BooleanResponse(false)));
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.error("Failed to parse BooleanResponse", e);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to respond");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import org.hibernate.validator.constraints.Length;
|
|||
|
||||
public class FormActiveData {
|
||||
|
||||
public FormActiveData() {}
|
||||
|
||||
public FormActiveData(String formName) {
|
||||
this.formName = formName;
|
||||
}
|
||||
|
|
@ -13,6 +15,6 @@ public class FormActiveData {
|
|||
@NotEmpty(message = "You have to provide a form name")
|
||||
@Length(min = 1, max = 64, message = "Usernames have to be between 3 and 16 characters")
|
||||
@Pattern(regexp = "[a-zA-Z]{1,64}", message = "This is an invalid form name")
|
||||
public final String formName;
|
||||
public String formName;
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
logging.level.com.alttd.forms=warn
|
||||
logging.level.com.alttd.forms=WARN
|
||||
server.port=8002
|
||||
spring.jackson.date-format=yyyy-MM-dd
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
||||
Loading…
Reference in New Issue
Block a user