From: Magnus Hagander Date: Sun, 17 Jan 2021 15:17:57 +0000 (+0100) Subject: Send moderation notice to moderators even when no changes are made X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=171c6b5be185485cb1fb6c108ffc96e6755121d8;p=pgweb.git Send moderation notice to moderators even when no changes are made When a moderation notice was sent without making any actual state changse (so not approving, rejecting or returning), the notice would only be sent to the submitter, and not to the moderators. Which obviously can lead to some confusion. So make sure that it's always sent there as well, and the message clearly states that it was just a comment. --- diff --git a/pgweb/core/views.py b/pgweb/core/views.py index dd9be636..5edcadfa 100644 --- a/pgweb/core/views.py +++ b/pgweb/core/views.py @@ -364,7 +364,15 @@ def _send_moderation_message(request, obj, message, notice, what): ) # Send notification to admins + if obj.twomoderators and obj.firstmoderator: + # For two-moderator objects, only one is required to reject or send back for editing. In that case, + # just log the current user who is the one that did that. + modname = "{} and {}".format(obj.firstmoderator, request.user) + else: + modname = request.user + if what: + # If an actual change happened, notify of that admmsg = message if obj.is_approved: admmsg += "\n\nNOTE! This {} was previously approved!!".format(obj._meta.verbose_name) @@ -376,17 +384,22 @@ def _send_moderation_message(request, obj, message, notice, what): # No point in sending an edit link to a page that doesn't exist anymore admmsg += "\n\nEdit at: {}/admin/_moderate/{}/{}/\n".format(settings.SITE_ROOT, obj._meta.model_name, obj.id) - if obj.twomoderators and obj.firstmoderator: - # For two-moderator objects, only one is required to reject or send back for editing. In that case, - # just log the current user who is the one that did that. - modname = "{} and {}".format(obj.firstmoderator, request.user) - else: - modname = request.user - send_simple_mail(settings.NOTIFICATION_FROM, settings.NOTIFICATION_EMAIL, "{} '{}' {} by {}".format(obj._meta.verbose_name.capitalize(), obj.title, what, modname), admmsg) + elif notice: + # There was no change, but there was a moderation notice. We still want to inform the moderators that this happened + admmsg = "No changes were made, but the following notice was sent:\n{}\n\nEdit at: {}/admin/_moderate/{}/{}/\n".format( + notice, + settings.SITE_ROOT, + obj._meta.model_name, + obj.id, + ) + send_simple_mail(settings.NOTIFICATION_FROM, + settings.NOTIFICATION_EMAIL, + "Moderation notice on '{}' {} by {}".format(obj._meta.verbose_name.capitalize(), obj.title, modname), + admmsg) # Moderate a single item