From ae92283730f6f242cb0e71dedd7a44b58ccaf566 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 09 2018 09:38:58 +0000 Subject: [PATCH 1/2] Fix editing and deleting comments added by the EV server to PRs Basically, we had the project url hard-coded in the html instead of have it automatically generated from the content passed on by the EV server so editing a comment added by the EV server was only ever going to work on a one project. In addition, the form and csrf token were missing to allow the delete button to work. Both form and csrf token are now present on the html page, thus allowing to right away delete a generic comment that was added by the EV server. Fixes https://pagure.io/pagure/issue/2958 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 29d1841..1bfda0a 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1238,6 +1238,7 @@ def add_pull_request_comment(session, request, commit, tree_id, filename, 'comment_added': comment_text, 'comment_user': pr_comment.user.user, 'comment_id': pr_comment.id, + 'project': request.project.fullname, 'avatar_url': avatar_url_from_email( pr_comment.user.default_email, size=16), 'comment_date': pr_comment.date_created.strftime( diff --git a/pagure/static/request_ev.js b/pagure/static/request_ev.js index 66d36ba..58219c5 100644 --- a/pagure/static/request_ev.js +++ b/pagure/static/request_ev.js @@ -2,7 +2,7 @@ add_comment = function(data, username) { console.log('Adding comment ' + data.comment_added); var field = $('#comments'); var edit_btn = ' \ \ @@ -61,41 +61,46 @@ add_comment = function(data, username) { \ '; } else { - var _data = '
\ - \ -
\ -
\ -
\ - \ - ' - + emojione.toImage(data.comment_added) + '\ -
\ -
\ -
\ -
\ -
\ - \ - \ - '; - if ( data.comment_user == username) { - _data += edit_btn + - ''; - } - _data += '
\ -
\ -
'; + var _csrf = $('#csrf_token').clone(); + var _data = '
\ +
\ + \ +
\ +
\ +
\ + \ + ' + + emojione.toImage(data.comment_added) + '\ +
\ +
\ +
\ +
\ +
\ + \ + \ + '; + if ( data.comment_user == username) { + _data += edit_btn + + ''; + } + _data += '
\ +
\ +
\ + \ + '; } if (inline){ From a76b0fc98716b5085694a597d48238c95fa95e2d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 09 2018 09:38:58 +0000 Subject: [PATCH 2/2] Move back to use then authenticated method Instead of relying on the present of flask.g.authenticated. The perf gain isn't that important but this change is having consequences in a number of places in the code to the point that it is as simple to revert this change. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/utils.py b/pagure/utils.py index 1485452..f58057a 100644 --- a/pagure/utils.py +++ b/pagure/utils.py @@ -49,7 +49,7 @@ def is_safe_url(target): # pragma: no cover def is_admin(): """ Return whether the user is admin for this application or not. """ - if not flask.g.authenticated: + if not authenticated(): return False user = flask.g.fas_user