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

feat(wiki): add rate limiting for feedback submissions #275

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions wiki/wiki/doctype/wiki_feedback/wiki_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@

import frappe
from frappe.model.document import Document
from frappe.rate_limiter import rate_limit
from frappe.utils import validate_email_address


class WikiFeedback(Document):
pass


def get_feedback_limit():
wiki_settings = frappe.get_single("Wiki Settings")
return wiki_settings.feedback_submission_limit or 3


@frappe.whitelist(allow_guest=True)
@rate_limit(limit=get_feedback_limit, seconds=60 * 60)
def submit_feedback(name, feedback, rating, email=None, feedback_index=None):
email = validate_email_address(email)
doc = frappe.get_doc(
Expand Down
13 changes: 11 additions & 2 deletions wiki/wiki/doctype/wiki_settings/wiki_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"feedback_tab",
"feedback_section",
"enable_feedback",
"feedback_submission_limit",
"ask_for_contact_details",
"section_break_mmtu",
"javascript"
Expand Down Expand Up @@ -140,7 +141,6 @@
},
{
"default": "0",
"depends_on": "eval:doc.enable_feedback",
"fieldname": "ask_for_contact_details",
"fieldtype": "Check",
"label": "Ask for contact details"
Expand All @@ -149,12 +149,21 @@
"fieldname": "feedback_tab",
"fieldtype": "Tab Break",
"label": "Feedback"
},
{
"default": "3",
"depends_on": "enable_feedback",
"description": "Hourly rate limit on submitting feedbacks",
"fieldname": "feedback_submission_limit",
"fieldtype": "Int",
"label": "Feedback Submission Limit",
"non_negative": 1
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2024-06-03 16:19:02.137667",
"modified": "2024-09-29 14:05:32.587922",
"modified_by": "Administrator",
"module": "Wiki",
"name": "Wiki Settings",
Expand Down
Loading