fix: Allow guest to comment on Web Page & Blog Post
This commit is contained in:
parent
878ac658b2
commit
1fbb22d36f
4 changed files with 18 additions and 7 deletions
|
|
@ -49,8 +49,10 @@
|
|||
{% endif %}
|
||||
<script>
|
||||
frappe.ready(function() {
|
||||
let guest_allowed = "{{ guest_allowed or ''}}";
|
||||
|
||||
if (!frappe.is_user_logged_in()) {
|
||||
$(".login-required, .comment-form-wrapper").toggleClass("hidden");
|
||||
!guest_allowed && $(".login-required, .comment-form-wrapper").toggleClass("hidden");
|
||||
} else {
|
||||
$('input.comment_by').prop("disabled", true);
|
||||
$('input.comment_email').prop("disabled", true);
|
||||
|
|
@ -91,6 +93,16 @@
|
|||
route: "{{ pathname }}",
|
||||
}
|
||||
|
||||
if(!args.comment_by || !args.comment_email || !args.comment) {
|
||||
frappe.msgprint("{{ _("All fields are necessary to submit the comment.") }}");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.comment_email!=='Administrator' && !validate_email(args.comment_email)) {
|
||||
frappe.msgprint("{{ _("Please enter a valid email address.") }}");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!args.comment || !args.comment.trim()) {
|
||||
frappe.msgprint("{{ _("Please add a valid comment.") }}");
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from frappe.utils import add_to_date, now
|
|||
|
||||
from frappe import _
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def add_comment(comment, comment_email, comment_by, reference_doctype, reference_name, route):
|
||||
doc = frappe.get_doc(reference_doctype, reference_name)
|
||||
|
||||
|
|
@ -24,17 +24,14 @@ def add_comment(comment, comment_email, comment_by, reference_doctype, reference
|
|||
frappe.msgprint(_('Comments cannot have links or email addresses'))
|
||||
return False
|
||||
|
||||
if not comment_email == frappe.session.user:
|
||||
comment_email = frappe.session.user
|
||||
|
||||
comments_count = frappe.db.count("Comment", {
|
||||
"comment_type": "Comment",
|
||||
"comment_email": frappe.session.user,
|
||||
"comment_email": comment_email,
|
||||
"creation": (">", add_to_date(now(), hours=-1))
|
||||
})
|
||||
|
||||
if comments_count > 20:
|
||||
frappe.msgprint(_('Hourly comment limit reached for: {0}').format(frappe.bold(frappe.session.user)))
|
||||
frappe.msgprint(_('Hourly comment limit reached for: {0}').format(frappe.bold(comment_email)))
|
||||
return False
|
||||
|
||||
comment = doc.add_comment(
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ class BlogPost(WebsiteGenerator):
|
|||
context.parents = [{"name": _("Home"), "route":"/"},
|
||||
{"name": "Blog", "route": "/blog"},
|
||||
{"label": context.category.title, "route":context.category.route}]
|
||||
context.guest_allowed = True
|
||||
|
||||
def fetch_cta(self):
|
||||
if frappe.db.get_single_value("Blog Settings", "show_cta_in_blog", cache=True):
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class WebPage(WebsiteGenerator):
|
|||
|
||||
if self.enable_comments:
|
||||
context.comment_list = get_comment_list(self.doctype, self.name)
|
||||
context.guest_allowed = True
|
||||
|
||||
context.update({
|
||||
"style": self.css or "",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue