From 1c25448fa4b1ac4ea6217e3554675c7d1ac39016 Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Thu, 27 Jul 2017 09:15:58 +0200 Subject: [PATCH] Assign perms to EIC for reply-comments --- .../templates/comments/_add_comment_form.html | 76 ++++++++++++------ .../comments/_single_comment_with_link.html | 6 +- comments/templates/comments/new_comment.html | 78 +------------------ comments/views.py | 12 ++- 4 files changed, 66 insertions(+), 106 deletions(-) diff --git a/comments/templates/comments/_add_comment_form.html b/comments/templates/comments/_add_comment_form.html index aa5a8bd0a..b3a51a16b 100644 --- a/comments/templates/comments/_add_comment_form.html +++ b/comments/templates/comments/_add_comment_form.html @@ -1,34 +1,62 @@ -<script> - $(document).ready(function(){ +{% load bootstrap %} - var comment_text_input = $("#id_comment_text"); +<script> + $(document).ready(function(){ + var comment_text_input = $("#id_comment_text"); - function set_comment_text(value) { - $("#preview-comment_text").text(value) - } - set_comment_text(comment_text_input.val()) + comment_text_input.on('keyup', function(){ + var new_text = $(this).val() + $("#preview-comment_text").text(new_text) + MathJax.Hub.Queue(["Typeset",MathJax.Hub]); + }).trigger('keyup') + }); +</script> - comment_text_input.keyup(function(){ - var new_text = $(this).val() - set_comment_text(new_text) - MathJax.Hub.Queue(["Typeset",MathJax.Hub]); - }) +<form enctype="multipart/form-data" action="{{url}}" method="post"> + {% csrf_token %} + <div class="row"> + <div class="col-md-9"> + {{form.comment_text|bootstrap:'12,12'}} + <p> + In your comment, you can use LaTeX \$...\$ for in-text equations or \ [ ... \ ] for on-line equations. + </p> + <p id="goodCommenter"><em> + Be professional. Only serious and meaningful comments will be vetted through. + </em></p> + </div> + <div class="col-md-3 radio-list"> + <label>Specify categorization(s):</label> + {{form.is_cor|bootstrap}} + {{form.is_rem|bootstrap}} + {{form.is_que|bootstrap}} + {{form.is_ans|bootstrap}} + {{form.is_obj|bootstrap}} + {{form.is_rep|bootstrap}} + {{form.is_val|bootstrap}} + {{form.is_lit|bootstrap}} + {{form.is_sug|bootstrap}} + </div> + </div> - }); -</script> + <div class="row"> + <div class="col-md-9"> + {{form.remarks_for_editors|bootstrap:'12,12'}} + </div> + <div class="col-md-3"> + {{form.file_attachment|bootstrap:'12,12'}} + </div> + </div> -<div class="row"> - <div class="col-12"> - <form enctype="multipart/form-data" action="{{url}}" method="post"> - {% csrf_token %} - {% load crispy_forms_tags %} - {% crispy form %} - </form> - </div> -</div> + <div class="row"> + <div class="col-12"> + <input type="submit" name="submit" value="Submit your Comment for vetting" class="btn btn-primary" id="submit-id-submit"> + <p class="mt-2" id="goodCommenter"><i>By clicking on Submit, you agree with the <a target="_blank" href="{% url 'scipost:terms_and_conditions' %}">Terms and Conditions</a>.</i></p> + </div> + </div> +</form> <div class="row"> - <div class="col-md-10"> + <div class="col-md-9"> <h3>Preview of your comment:</h3> <p id="preview-comment_text"></p> </div> diff --git a/comments/templates/comments/_single_comment_with_link.html b/comments/templates/comments/_single_comment_with_link.html index 06cf9a4b9..9952e67b1 100644 --- a/comments/templates/comments/_single_comment_with_link.html +++ b/comments/templates/comments/_single_comment_with_link.html @@ -3,10 +3,6 @@ {% block comment_footer %} {% if user.is_authenticated and perms.scipost.can_submit_comments %} <hr class="small"> - <div class="row"> - <div class="col-12"> - <h3><a href="{% url 'comments:reply_to_comment' comment_id=comment.id %}">Reply to this comment</a></h3> - </div> - </div> + <h3><a href="{% url 'comments:reply_to_comment' comment_id=comment.id %}">Reply to this comment</a></h3> {% endif %} {% endblock %} diff --git a/comments/templates/comments/new_comment.html b/comments/templates/comments/new_comment.html index 4aedb638e..55d670be8 100644 --- a/comments/templates/comments/new_comment.html +++ b/comments/templates/comments/new_comment.html @@ -2,83 +2,11 @@ {% if user.is_authenticated and open_for_commenting and perms.scipost.can_submit_comments %} -<script> - $(document).ready(function(){ - - var comment_text_input = $("#id_comment_text"); - - function set_comment_text(value) { - $("#preview-comment_text").text(value) - } - set_comment_text(comment_text_input.val()) - - comment_text_input.keyup(function(){ - var new_text = $(this).val() - set_comment_text(new_text) - MathJax.Hub.Queue(["Typeset",MathJax.Hub]); - }) - - }); -</script> - <hr> -<div class="row" id="contribute_comment"> - <div class="col-12"> - <h2 class="highlight">Contribute a Comment:</h2> - </div> -</div> -<div class="row"> - <div class="col-12"> - <form enctype="multipart/form-data" - action="{% url 'comments:new_comment' object_id=object_id type_of_object=type_of_object %}" - method="post"> - {% csrf_token %} - <div class="row"> - <div class="col-md-9"> - {{form.comment_text|bootstrap:'12,12'}} - <p> - In your comment, you can use LaTeX \$...\$ for in-text equations or \ [ ... \ ] for on-line equations. - </p> - <p id="goodCommenter"><em> - Be professional. Only serious and meaningful comments will be vetted through. - </em></p> - </div> - <div class="col-md-3 radio-list"> - <label>Specify categorization(s):</label> - {{form.is_cor|bootstrap}} - {{form.is_rem|bootstrap}} - {{form.is_que|bootstrap}} - {{form.is_ans|bootstrap}} - {{form.is_obj|bootstrap}} - {{form.is_rep|bootstrap}} - {{form.is_val|bootstrap}} - {{form.is_lit|bootstrap}} - {{form.is_sug|bootstrap}} - </div> - </div> - - <div class="row"> - <div class="col-md-9"> - {{form.remarks_for_editors|bootstrap:'12,12'}} - </div> - <div class="col-md-3"> - {{form.file_attachment|bootstrap:'12,12'}} - </div> - </div> +<h2 class="highlight" id="contribute_comment">Contribute a Comment:</h2> - <div class="row"> - <div class="col-12"> - <input type="submit" name="submit" value="Submit your Comment for vetting" class="btn btn-primary" id="submit-id-submit"> - <p class="mt-2" id="goodCommenter"><i>By clicking on Submit, you agree with the <a target="_blank" href="{% url 'scipost:terms_and_conditions' %}">Terms and Conditions</a>.</i></p> - </div> - </div> - </form> - </div> - <div class="col-12"> - <h3>Preview of your comment:</h3> - <p id="preview-comment_text"></p> - </div> -</div> +{% url 'comments:new_comment' object_id=object_id type_of_object=type_of_object as url %} +{% include 'comments/_add_comment_form.html' with form=form url=url %} {% endif %} diff --git a/comments/views.py b/comments/views.py index 662841c02..4ef6459ae 100644 --- a/comments/views.py +++ b/comments/views.py @@ -135,9 +135,9 @@ def reply_to_comment(request, comment_id): is_author = False if comment.submission and not is_author: is_author = comment.submission.authors.filter(id=request.user.contributor.id).exists() - elif comment.commentary and not is_author: + if comment.commentary and not is_author: is_author = comment.commentary.authors.filter(id=request.user.contributor.id).exists() - elif comment.thesislink and not is_author: + if comment.thesislink and not is_author: is_author = comment.thesislink.author == request.user.contributor form = CommentForm(request.POST or None, request.FILES or None) @@ -156,6 +156,10 @@ def reply_to_comment(request, comment_id): 'It will soon be vetted by an Editor.') if newcomment.submission: + # Add permissions for EIC only, the Vetting-group already has it! + assign_perm('comments.can_vet_comments', newcomment.submission.editor_in_charge.user, + newcomment) + return redirect(newcomment.submission.get_absolute_url()) elif newcomment.commentary: return redirect(newcomment.commentary.get_absolute_url()) @@ -183,6 +187,10 @@ def reply_to_report(request, report_id): newcomment.author = request.user.contributor newcomment.save() + # Add permissions for EIC only, the Vetting-group already has it! + assign_perm('comments.can_vet_comments', newcomment.submission.editor_in_charge.user, + newcomment) + messages.success(request, '<h3>Thank you for contributing a Reply</h3>' 'It will soon be vetted by an Editor.') return redirect(newcomment.submission.get_absolute_url()) -- GitLab