diff --git a/comments/utils.py b/comments/utils.py index 8737a8e0d20b60b23fc0f2d9e5efe4bb5a4f313c..e245f7dd4c29597fabe7eaaaee40d4018d450d2e 100644 --- a/comments/utils.py +++ b/comments/utils.py @@ -11,43 +11,3 @@ def validate_file_extention(value, allowed_extentions): """Check if a filefield (value) has allowed extentions.""" ext = os.path.splitext(value.name)[1] # [0] returns path+filename return ext.lower() in allowed_extentions - - -class CommentUtils(BaseMailUtil): - mail_sender = 'comments@scipost.org' - mail_sender_title = 'The SciPost Team' - - @classmethod - def email_comment_vet_accepted_to_author(cls): - """Send mail after Comment is vetted: `Accept`. - - Requires loading: - comment -- Comment - """ - from submissions.models import Submission, Report - - comment = cls._context['comment'] - send_mail = True - if isinstance(comment.content_object, Submission): - send_mail = comment.author not in comment.content_object.authors.all() - elif isinstance(comment.content_object, Report): - send_mail = comment.author not in comment.content_object.submission.authors.all() - - if not send_mail: - return - - cls._send_mail(cls, 'comment_vet_accepted', - [comment.author.user.email], - 'SciPost Comment published') - - @classmethod - def email_comment_vet_rejected_to_author(cls, email_response=''): - """Send mail after Comment is vetted: `Reject`. - - Requires loading: - comment -- Comment - """ - cls._send_mail(cls, 'comment_vet_rejected', - [cls._context['comment'].author.user.email], - 'SciPost Comment rejected', - extra_context={'email_response': email_response}) diff --git a/comments/views.py b/comments/views.py index 9b37556ff53d51b17a905b84157e669f1e62130f..c47f8dc7d8cbf700294c86d65c7d5a65e568e2c9 100644 --- a/comments/views.py +++ b/comments/views.py @@ -16,7 +16,7 @@ import strings from .constants import EXTENTIONS_IMAGES, EXTENTIONS_PDF from .models import Comment from .forms import CommentForm, VetCommentForm -from .utils import CommentUtils, validate_file_extention +from .utils import validate_file_extention from commentaries.models import Commentary from mails.utils import DirectMailUtil @@ -87,8 +87,10 @@ def vet_submitted_comment(request, comment_id): content_object.add_event_for_eic('A Comment has been accepted.') content_object.add_event_for_author('A new Comment has been added.') if not comment.is_author_reply: - SubmissionUtils.load({'submission': content_object}) - SubmissionUtils.send_author_comment_received_email() + mail_sender = DirectMailUtil( + mail_code='authors/inform_authors_comment_received', + instance=content_object) + mail_sender.send() elif isinstance(content_object, Report): # Add events to related Submission and send mail to author of the Submission content_object.submission.add_event_for_eic('A Comment has been accepted.') @@ -99,13 +101,23 @@ def vet_submitted_comment(request, comment_id): mail_code='referees/inform_referee_authors_replied_to_report', instance=content_object) mail_sender.send() - else: - SubmissionUtils.load({'submission': content_object.submission}) - SubmissionUtils.send_author_comment_received_email() + else: # this is a Comment on the Report from another Contributor + # Email Report author: Contributor has commented the Report + mail_sender = DirectMailUtil( + mail_code='referees/inform_referee_contributor_commented_report', + instance=content_object) + mail_sender.send() + # Email submission authors: Contributor has commented the Report + mail_sender = DirectMailUtil( + mail_code='authors/inform_authors_contributor_commented_report', + instance=content_object) + mail_sender.send() - # Send emails - CommentUtils.load({'comment': comment}) - CommentUtils.email_comment_vet_accepted_to_author() + # In all cases, email the comment author + mail_sender = DirectMailUtil( + mail_code='commenters/inform_commenter_comment_vetted', + instance=comment) + mail_sender.send() elif form.cleaned_data['action_option'] == '2': # The comment request is simply rejected @@ -115,9 +127,12 @@ def vet_submitted_comment(request, comment_id): comment.save() # Send emails - CommentUtils.load({'comment': comment}) - CommentUtils.email_comment_vet_rejected_to_author( - email_response=form.cleaned_data['email_response_field']) + mail_sender = DirectMailUtil( + mail_code='commenters/inform_commenter_comment_rejected', + instance=comment, + email_response=form.cleaned_data['email_response_field']) # TODO: needs kwargs to mail template + mail_sender.send() + if isinstance(comment.content_object, Submission): # Add event if commented to Submission diff --git a/submissions/utils.py b/submissions/utils.py index 39d3ee95c163389f3d38983d0f7ae4463c6dca2b..03da8f41840a432a494b18c32fc7fd5297ebae3b 100644 --- a/submissions/utils.py +++ b/submissions/utils.py @@ -988,48 +988,6 @@ class SubmissionUtils(BaseMailUtil): emailmessage.attach_alternative(html_version, 'text/html') emailmessage.send(fail_silently=False) - @classmethod - def send_author_comment_received_email(cls): - """ Requires loading 'submission' attribute. """ - email_text = ('Dear ' + cls.submission.submitted_by.get_title_display() + ' ' + - cls.submission.submitted_by.user.last_name + - ', \n\nA Comment has been posted on your recent Submission to SciPost,\n\n' + - cls.submission.title + ' by ' + cls.submission.author_list + '.' - '\n\nYou can view it at the Submission Page ' - 'https://scipost.org/submission/' - + cls.submission.arxiv_identifier_w_vn_nr + '.' - '\n\nWe thank you very much for your contribution.' - '\n\nSincerely,' + - '\n\nThe SciPost Team.') - email_text_html = ( - '<p>Dear {{ auth_title }} {{ auth_last_name }},</p>' - '<p>A Comment has been posted on your recent Submission to SciPost,</p>' - '<p>{{ sub_title }}</p>\n<p>by {{ author_list }}.</p>' - '\n<p>You can view it at the ' - '<a href="https://scipost.org/submission/{{ arxiv_identifier_w_vn_nr }}">' - 'Submission\'s Page</a>.</p>' - '\n<p>We thank you very much for your contribution.</p>' - '<p>Sincerely,</p>' - '<p>The SciPost Team.</p>') - email_context = { - 'auth_title': cls.submission.submitted_by.get_title_display(), - 'auth_last_name': cls.submission.submitted_by.user.last_name, - 'sub_title': cls.submission.title, - 'author_list': cls.submission.author_list, - 'arxiv_identifier_w_vn_nr': cls.submission.arxiv_identifier_w_vn_nr, - } - email_text_html += '<br/>' + EMAIL_FOOTER - html_template = Template(email_text_html) - html_version = html_template.render(Context(email_context)) - emailmessage = EmailMultiAlternatives( - 'SciPost: Comment received on your Submission', email_text, - 'SciPost Editorial Admin <submissions@scipost.org>', - [cls.submission.submitted_by.user.email], - bcc=[cls.submission.editor_in_charge.user.email, - 'submissions@scipost.org'], - reply_to=['submissions@scipost.org']) - emailmessage.attach_alternative(html_version, 'text/html') - emailmessage.send(fail_silently=False) @classmethod def send_communication_email(cls): diff --git a/templates/email/authors/inform_authors_comment_received.html b/templates/email/authors/inform_authors_comment_received.html new file mode 100644 index 0000000000000000000000000000000000000000..927232ccb4bda2a4d99be25c0dc6d848c2650591 --- /dev/null +++ b/templates/email/authors/inform_authors_comment_received.html @@ -0,0 +1,16 @@ +<p> + Dear {{ submission.submitted_by.get_title_display }} {{ submission.submitted_by.user.last_name }}, +</p> +<p> + We would like to inform you that a Comment has been posted on your recent Submission + <br><br> + {{ submission.title }} + <br>by {{ submission.author_list }}<br> + (see https://scipost.org{{ submission.get_absolute_url }} - first submitted {{ submission.original_submission_date|date:"d M Y" }}). +</p> +<p> + You can view it at the <a href="https://scipost.org/submission/{{ submission.arxiv_identifier_w_vn_nr }}">Submission\'s Page</a>. +</p> +<p>Sincerely,</p> +<p>The SciPost Team</p> +{% include 'email/_footer.html' %} diff --git a/templates/email/authors/inform_authors_comment_received.json b/templates/email/authors/inform_authors_comment_received.json new file mode 100644 index 0000000000000000000000000000000000000000..ff00de57d44c1e4b923ef199afb9067b9b9a8486 --- /dev/null +++ b/templates/email/authors/inform_authors_comment_received.json @@ -0,0 +1,8 @@ +{ + "subject": "SciPost: Comment on your Submission", + "to_address": "submitted_by.user.email", + "bcc_to": "editor_in_charge.user.email,edadmin@scipost.org", + "from_address_name": "SciPost Refereeing", + "from_address": "refereeing@scipost.org", + "context_object": "submission" +} diff --git a/templates/email/authors/inform_authors_contributor_commented_report.html b/templates/email/authors/inform_authors_contributor_commented_report.html new file mode 100644 index 0000000000000000000000000000000000000000..860bb67e60c8646418c68efde576a93be5566557 --- /dev/null +++ b/templates/email/authors/inform_authors_contributor_commented_report.html @@ -0,0 +1,18 @@ +<p> + Dear {{ report.submission.submitted_by.get_title_display }} {{ report.submission.submitted_by.user.last_name }}, +</p> +<p> + For your information, a Contributor Comment has been posted on a recent Report on your Submission + <br><br> + {{ report.submission.title }} + <br>by {{ report.submission.author_list }}<br> + (see https://scipost.org{{ report.submission.get_absolute_url }} - first submitted {{ report.submission.original_submission_date|date:"d M Y" }}). +</p> +<p> + You can view this Report and the associated Comment directly at + <a href="https://scipost.org{{ report.get_absolute_url }}">this link</a>. +</p> +<p> + We thank you very much for your contribution.<br/><br/>The SciPost Team. +</p> +{% include 'email/_footer.html' %} diff --git a/templates/email/authors/inform_authors_contributor_commented_report.json b/templates/email/authors/inform_authors_contributor_commented_report.json new file mode 100644 index 0000000000000000000000000000000000000000..a29b3d72df79d829e36b0cb56b13004b89392ef5 --- /dev/null +++ b/templates/email/authors/inform_authors_contributor_commented_report.json @@ -0,0 +1,8 @@ +{ + "subject": "SciPost: Contributor Comment on Report", + "to_address": "submission.submitted_by.user.email", + "bcc_to": "submission.editor_in_charge.user.email,edadmin@scipost.org", + "from_address_name": "SciPost Refereeing", + "from_address": "refereeing@scipost.org", + "context_object": "report" +} diff --git a/templates/email/comment_vet_accepted.txt b/templates/email/comment_vet_accepted.txt deleted file mode 100644 index c717f5fe32e03c5c4c1724f5590c7bc6b2a02a0e..0000000000000000000000000000000000000000 --- a/templates/email/comment_vet_accepted.txt +++ /dev/null @@ -1,16 +0,0 @@ -Dear {{comment.author.get_title_display}} {{comment.author.user.last_name}} -\n\n - -The Comment you have submitted, concerning publication with title - -{{comment.core_content_object.title}} by {% if comment.core_content_object.author_list %}{{comment.core_content_object.author_list}}{% elif comment.core_content_object.author %}{{comment.core_content_object.author}}{% endif %} at https://scipost.org{{comment.get_absolute_url}} - -has been accepted and published online. -\n\nWe copy it below for your convenience. - -\n\nThank you for your contribution, -\nThe SciPost Team. - -'\n\n' -Comment:\n -{{comment.comment_text}} diff --git a/templates/email/comment_vet_rejected.txt b/templates/email/comment_vet_rejected.txt deleted file mode 100644 index c489d65acf3725c63f1542cfa0e2288a80f0ac22..0000000000000000000000000000000000000000 --- a/templates/email/comment_vet_rejected.txt +++ /dev/null @@ -1,22 +0,0 @@ -Dear {{comment.author.get_title_display}} {{comment.author.user.last_name}} -\n\n - -The Comment you have submitted, concerning publication with title - -{{comment.core_content_object.title}} by {% if comment.core_content_object.author_list %}{{comment.core_content_object.author_list}}{% elif comment.core_content_object.author %}{{comment.core_content_object.author}}{% endif %} at https://scipost.org{{comment.get_absolute_url}} - -has been rejected for the following reason: {{comment.get_status_display}}. - -\n\nWe copy it below for your convenience. - -\n\nThank you for your contribution, - -\n\nThe SciPost Team. - -{% if email_response %} - \n\nFurther explanations: {{email_response}} -{% endif %} - -\n\n -Comment:\n -{{comment.comment_text}} diff --git a/templates/email/comment_vet_rejected.html b/templates/email/commenters/inform_commenter_comment_rejected.html similarity index 91% rename from templates/email/comment_vet_rejected.html rename to templates/email/commenters/inform_commenter_comment_rejected.html index 678771fb32954fdfb86ebf20402bad97f421ef3c..99cb52af3f8193a7075779ab1e028f4b16292476 100644 --- a/templates/email/comment_vet_rejected.html +++ b/templates/email/commenters/inform_commenter_comment_rejected.html @@ -1,9 +1,9 @@ <p>Dear {{comment.author.get_title_display}} {{comment.author.user.last_name}},</p> - <p> - The Comment you have submitted, concerning publication with title - + The Comment you have submitted, concerning + <br/> {{comment.core_content_object.title}} by {% if comment.core_content_object.author_list %}{{comment.core_content_object.author_list}}{% elif comment.core_content_object.author %}{{comment.core_content_object.author}}{% endif %} (<a href="https://scipost.org{{comment.get_absolute_url}}">see on SciPost.org</a>) + <br/> has been rejected for the following reason: {{comment.get_status_display}}. </p> <p> diff --git a/templates/email/commenters/inform_commenter_comment_rejected.json b/templates/email/commenters/inform_commenter_comment_rejected.json new file mode 100644 index 0000000000000000000000000000000000000000..2503233b77beb7da8d28b96238a7e2b303bce295 --- /dev/null +++ b/templates/email/commenters/inform_commenter_comment_rejected.json @@ -0,0 +1,8 @@ +{ + "subject": "SciPost: Comment not vetted", + "to_address": "author.user.email", + "bcc_to": "edadmin@scipost.org", + "from_address_name": "SciPost Comments", + "from_address": "edadmin@scipost.org", + "context_object": "comment" +} diff --git a/templates/email/comment_vet_accepted.html b/templates/email/commenters/inform_commenter_comment_vetted.html similarity index 87% rename from templates/email/comment_vet_accepted.html rename to templates/email/commenters/inform_commenter_comment_vetted.html index 60908ef568720835558a91280c070fc2a48b7a0f..b9f218e61d6e3b910d7b4e964ab845b0137500f3 100644 --- a/templates/email/comment_vet_accepted.html +++ b/templates/email/commenters/inform_commenter_comment_vetted.html @@ -1,9 +1,10 @@ <p>Dear {{comment.author.get_title_display}} {{comment.author.user.last_name}},</p> <p> - The Comment you have submitted, concerning publication with title - + The Comment you have submitted, concerning + <br/> {{comment.core_content_object.title}} by {% if comment.core_content_object.author_list %}{{comment.core_content_object.author_list}}{% elif comment.core_content_object.author %}{{comment.core_content_object.author}}{% endif %} (<a href="https://scipost.org{{comment.get_absolute_url}}">see on SciPost.org</a>) + <br/> has been accepted and published online. </p> <p> @@ -11,7 +12,7 @@ </p> <p> Thank you for your contribution,<br><br> - The SciPost Team. + The SciPost Team </p> <p> <br> @@ -19,5 +20,4 @@ <br> {{comment.comment_text|linebreaksbr}} </p> - {% include 'email/_footer.html' %} diff --git a/templates/email/commenters/inform_commenter_comment_vetted.json b/templates/email/commenters/inform_commenter_comment_vetted.json new file mode 100644 index 0000000000000000000000000000000000000000..22bb3c4311aef452f2c6d40f0f8d181596336add --- /dev/null +++ b/templates/email/commenters/inform_commenter_comment_vetted.json @@ -0,0 +1,8 @@ +{ + "subject": "SciPost: Comment vetted and posted", + "to_address": "author.user.email", + "bcc_to": "edadmin@scipost.org", + "from_address_name": "SciPost Comments", + "from_address": "edadmin@scipost.org", + "context_object": "comment" +} diff --git a/templates/email/referees/inform_referee_contributor_commented_report.html b/templates/email/referees/inform_referee_contributor_commented_report.html new file mode 100644 index 0000000000000000000000000000000000000000..3c540b8bb99cfd162b85cf0f9c4fbc47383ce620 --- /dev/null +++ b/templates/email/referees/inform_referee_contributor_commented_report.html @@ -0,0 +1,18 @@ +<p> + Dear {{ report.author.get_title_display }} {{ report.author.user.last_name }}, +</p> +<p> + For your information, a Contributor Comment has been posted on your recent Report on + <br><br> + {{ report.submission.title }} + <br>by {{ report.submission.author_list }}<br> + (see https://scipost.org{{ report.submission.get_absolute_url }} - first submitted {{ report.submission.original_submission_date|date:"d M Y" }}). +</p> +<p> + You can view your Report and the associated Comment directly at + <a href="https://scipost.org{{ report.get_absolute_url }}">this link</a>. +</p> +<p> + We thank you very much for your contribution.<br/><br/>The SciPost Team. +</p> +{% include 'email/_footer.html' %} diff --git a/templates/email/referees/inform_referee_contributor_commented_report.json b/templates/email/referees/inform_referee_contributor_commented_report.json new file mode 100644 index 0000000000000000000000000000000000000000..2d3a45c6da8bcc8c647892bc78f16310b9a5c3fd --- /dev/null +++ b/templates/email/referees/inform_referee_contributor_commented_report.json @@ -0,0 +1,8 @@ +{ + "subject": "SciPost: Comment posted on your Report", + "to_address": "author.user.email", + "bcc_to": "submission.editor_in_charge.user.email,edadmin@scipost.org", + "from_address_name": "SciPost Refereeing", + "from_address": "refereeing@scipost.org", + "context_object": "report" +}