From 887974a74ba2059ee4ac7134e60a4ab05814cae8 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 01 2015 15:14:28 +0000 Subject: Add a new API endpoint returning a specific comment of a specific ticket This is used by the JS logic handling the EV messages as a way to update private tickets. Private changes are not broadcasted via the EV, redis just says, something changed and JS will call this endpoint and if you have the proper authorization it will refresh the page. --- diff --git a/pagure/api/issue.py b/pagure/api/issue.py index 2ac5ddd..4c82135 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -354,6 +354,73 @@ def api_view_issue(repo, issueid, username=None): return jsonout +@API.route('//issue//comment/') +@API.route('/fork///issue//comment/') +@api_login_optional() +@api_method +def api_view_issue_comment(repo, issue_uid, commentid, username=None): + """ + Comment of a ticket + ------------------- + Retrieve a specific comment of a ticket. + + :: + + GET /api/0//issue//comment/ + + :: + + GET /api/0/fork///issue//comment/ + + Sample response + ^^^^^^^^^^^^^^^ + + :: + + { + "avatar_url": "https://seccdn.libravatar.org/avatar/...?s=16&d=retro", + "comment": "9", + "comment_date": "2015-07-01 15:08", + "date_created": "1435756127", + "id": 464, + "parent": null, + "user": { + "fullname": "P.-Y.C.", + "name": "pingou" + } + } + + """ + + comment = pagure.lib.get_issue_comment(SESSION, issue_uid, commentid) + + if comment is None: + raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOPROJECT) + + if not comment.issue.project.settings.get('issue_tracker', True): + raise pagure.exceptions.APIError( + 404, error_code=APIERROR.ETRACKERDISABLED) + + if api_authenticated(): + if repo != flask.g.token.project: + raise pagure.exceptions.APIError( + 401, error_code=APIERROR.EINVALIDTOK) + + if comment.issue.private and not is_repo_admin(comment.issue.project) \ + and (not api_authenticated() or + not comment.issue.user.user == flask.g.fas_user.username): + raise pagure.exceptions.APIError( + 403, error_code=APIERROR.EISSUENOTALLOWED) + + + output = comment.to_json(public=True) + output['avatar_url'] = pagure.lib.avatar_url(comment.user.user, size=16) + output['comment_date'] = comment.date_created.strftime('%Y-%m-%d %H:%M') + jsonout = flask.jsonify(output) + return jsonout + + + @API.route('//issue//status', methods=['POST']) @API.route('/fork////status', methods=['POST']) @api_login_required(acls=['issue_change_status'])