Skip to content

Commit

Permalink
Merge pull request #275 from AyshaHakeem/edit-feedback
Browse files Browse the repository at this point in the history
feat(wiki): add rate limiting for feedback submissions
  • Loading branch information
AyshaHakeem authored Sep 29, 2024
2 parents 993b354 + b58e9bc commit 7362ccc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit 7362ccc

Please sign in to comment.