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

Allow users to fill out forms as GUEST and send email responses #870

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

Isti01
Copy link
Collaborator

@Isti01 Isti01 commented Feb 14, 2025

closes #859

@@ -67,21 +73,22 @@ open class FormService(
if (form.availableUntil < now)
return FormView(status = FormStatus.TOO_LATE)

if (form.allowedGroups.isNotBlank() && userRepository.findById(user.id)
if (user?.id != null && form.allowedGroups.isNotBlank() && userRepository.findById(user.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably works this way too, but I would probably only check on the user, not the id of it.

} else {
responseRepository.findByFormIdAndSubmitterUserId(form.id, user.id).orElse(null)
user?.id?.let { responseRepository.findByFormIdAndSubmitterUserId(form.id, it).getOrNull() }
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, this probably works just fine, but I don't think we need to check both the user and the id of the user.
By the way, will the submissionEntity default to null if the user is null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Passing null to an SQL query has a very different meaning than skipping the query if the parameter is null

Copy link
Contributor

@SzBeni2003 SzBeni2003 left a comment

Choose a reason for hiding this comment

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

Looks good to me

@albi005
Copy link
Member

albi005 commented Feb 15, 2025

One issue I see is that the POST /api/forms/{path} endpoint could be abused using a bot to send confirmation emails to random addresses, thereby hurting Kir-Mail's reputation. In StartSCH this is solved by requiring authentication through AuthSCH and throttling so that a user can only send an email every 30 seconds, but this is obviously not an option here.

A few ideas on how this could be handled:

  1. we could set a limit on how many messages can be triggered by unauthenticated users globally
    • This breaks when there are a lot of users signing up at the same time
  2. by limiting by IP address
    • can be exploited by using multiple IPs, but would be a lot harder than a simple script
  3. by adding a CAPTCHA

val form = formRepository.findAllByUrl(path).getOrNull(0)
?: return FormView(status = FormStatus.NOT_FOUND)

if ((form.minRole.value > user.role.value || form.maxRole.value < user.role.value) && !user.role.isAdmin)
val role = user?.role ?: RoleType.GUEST
Copy link
Member

@albi005 albi005 Feb 15, 2025

Choose a reason for hiding this comment

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

Just an idea:
We could have an UnauthenticatedUser : CmschUser instead of null for representing unauthenticated users, and then these null-checks wouldn't be needed. This would require making most of the attributes on CmschUser nullable, so might not be worth it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like it. I think it would improve the codebase. But it would be a part of a major, bigger scope refactor in my opinion

}


private fun getEmailForConfirmation(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private fun getEmailForConfirmation(
private fun getEmailAddressForConfirmation(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Send confirmation emails for form submissions
3 participants