fix: tests, check for spam comments

This commit is contained in:
Rushabh Mehta 2019-02-07 16:12:19 +05:30
parent 41d90fa6d1
commit ae097e5139
6 changed files with 28 additions and 13 deletions

View file

@ -22,7 +22,7 @@
"columns": 0,
"default": "Comment",
"fieldname": "comment_type",
"fieldtype": "Data",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
@ -476,7 +476,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2019-02-07 15:26:21.867083",
"modified": "2019-02-07 16:06:05.455876",
"modified_by": "Administrator",
"module": "Core",
"name": "Comment",

View file

@ -494,9 +494,9 @@ def sendmail(communication_name, print_html=None, print_format=None, attachments
communication._notify(print_html=print_html, print_format=print_format, attachments=attachments,
recipients=recipients, cc=cc, bcc=bcc)
except frappe.db.InternalError:
except frappe.db.InternalError as e:
# deadlock, try again
if frappe.db.is_deadlocked():
if frappe.db.is_deadlocked(e):
frappe.db.rollback()
time.sleep(1)
continue

View file

@ -112,7 +112,12 @@
if(r._server_messages)
frappe.msgprint(r._server_messages);
} else {
frappe.msgprint('{{ _("Thank you for your comment. It will be published after approval") }}');
if (r.message) {
$(r.message).appendTo("#comment-list");
} else {
// probably spam
frappe.msgprint('{{ _("Thank you for your comment. It will be published after approval") }}');
}
$(".no-comment, .add-comment").toggle(false);
$("#comment-form").toggle();
}

View file

@ -17,24 +17,34 @@ def add_comment(comment, comment_email, comment_by, reference_doctype, reference
comment_email = comment_email,
comment_by = comment_by)
blacklist = ['http://', 'https://', '@gmail.com']
if not any([b in comment.content for b in blacklist]):
# probably not spam!
comment.db_set('published', 1)
# since comments are embedded in the page, clear the web cache
clear_cache(route)
content = (doc.content
+ "<p><a href='{0}/desk/#Form/Comment/{1}' style='font-size: 80%'>{2}</a></p>".format(frappe.utils.get_request_site_address(),
doc.name,
route, _("Open Comment Form")))
route, _("View Comment")))
# notify creator
frappe.sendmail(
recipients = doc.owner,
subject = _('Please Approve New Comment on {0}: {1}').format(doc.doctype, doc.name),
recipients = frappe.get_doc('User', doc.owner, 'email') or doc.owner,
subject = _('New Comment on {0}: {1}').format(doc.doctype, doc.name),
message = content,
reference_doctype=doc.doctype,
reference_name=doc.name
)
# revert with template
template = frappe.get_template("templates/includes/comments/comment.html")
if comment.published:
# revert with template if all clear (no backlinks)
template = frappe.get_template("templates/includes/comments/comment.html")
return template.render({"comment": comment.as_dict()})
return template.render({"comment": comment.as_dict()})
else:
return ''

View file

@ -105,7 +105,7 @@ def execute_job(site, method, event, job_name, kwargs, user=None, is_async=True,
if (retry < 5 and
(isinstance(e, frappe.RetryBackgroundJobError) or
(frappe.db.is_deadlocked() or frappe.db.is_timedout()))):
(frappe.db.is_deadlocked(e) or frappe.db.is_timedout(e)))):
# retry the job if
# 1213 = deadlock
# 1205 = lock wait timeout

View file

@ -39,7 +39,7 @@ def get_comment_list(doctype, name):
filters = dict(
reference_doctype = doctype,
reference_name = name,
comment_type = comment,
comment_type = 'Comment',
published = 1
),
order_by = 'creation asc')