From aa23a9b058b24903c11b88517d7dd4820adae082 Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Jun 14 2016 13:24:56 +0000 Subject: [PATCH 1/4] add a take button to the issue assign field adds a take button so an authroized user can easily reassign a ticket to themselves fixes: #962 --- diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index dfa9b04..0505dea 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -147,6 +147,9 @@ {% else %} unassigned {% endif %} + {% if authenticated and repo_admin %} + + {% endif %} From 2833fb742e10133522f95d13cd07229e7ee415c9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 14 2016 13:24:56 +0000 Subject: [PATCH 2/4] If the user is authenticated, skip using an API token --- diff --git a/pagure/api/__init__.py b/pagure/api/__init__.py index 8dbd83a..64029a6 100644 --- a/pagure/api/__init__.py +++ b/pagure/api/__init__.py @@ -24,7 +24,7 @@ API = flask.Blueprint('api_ns', __name__, url_prefix='/api/0') import pagure import pagure.lib -from pagure import __api_version__, APP, SESSION +from pagure import __api_version__, APP, SESSION, authenticated from pagure.doc_utils import load_doc, modify_rst, modify_html from pagure.exceptions import APIError @@ -80,11 +80,14 @@ def check_api_acls(acls, optional=False): ''' Checks if the user provided an API token with its request and if this token allows the user to access the endpoint desired. ''' - flask.g.token = None flask.g.user = None token = None token_str = None + + if authenticated(): + return + if 'Authorization' in flask.request.headers: authorization = flask.request.headers['Authorization'] if 'token' in authorization: From 0031a9dfb71ae3efe2c50249762cf046b5abcc64 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 14 2016 13:24:56 +0000 Subject: [PATCH 3/4] If the user is authenticated, let them use the assign API And fix it in multiple places so that we are consistent on how we check if the user is authenticated and the token is valid --- diff --git a/pagure/api/issue.py b/pagure/api/issue.py index 68e1674..ff4d26a 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -501,8 +501,10 @@ def api_change_status_issue(repo, issueid, username=None): raise pagure.exceptions.APIError( 404, error_code=APIERROR.ETRACKERDISABLED) - if repo != flask.g.token.project: - raise pagure.exceptions.APIError(401, error_code=APIERROR.EINVALIDTOK) + if api_authenticated(): + if repo != flask.g.token.project: + raise pagure.exceptions.APIError( + 401, error_code=APIERROR.EINVALIDTOK) issue = pagure.lib.search_issues(SESSION, repo, issueid=issueid) @@ -595,8 +597,10 @@ def api_comment_issue(repo, issueid, username=None): raise pagure.exceptions.APIError( 404, error_code=APIERROR.ETRACKERDISABLED) - if repo.fullname != flask.g.token.project.fullname: - raise pagure.exceptions.APIError(401, error_code=APIERROR.EINVALIDTOK) + if api_authenticated(): + if repo != flask.g.token.project: + raise pagure.exceptions.APIError( + 401, error_code=APIERROR.EINVALIDTOK) issue = pagure.lib.search_issues(SESSION, repo, issueid=issueid) @@ -683,8 +687,10 @@ def api_assign_issue(repo, issueid, username=None): raise pagure.exceptions.APIError( 404, error_code=APIERROR.ETRACKERDISABLED) - if repo.fullname != flask.g.token.project.fullname: - raise pagure.exceptions.APIError(401, error_code=APIERROR.EINVALIDTOK) + if api_authenticated(): + if repo != flask.g.token.project: + raise pagure.exceptions.APIError( + 401, error_code=APIERROR.EINVALIDTOK) issue = pagure.lib.search_issues(SESSION, repo, issueid=issueid) From b790661cfee5d3a4aa216ca4222bc11d4498a640 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 14 2016 13:24:56 +0000 Subject: [PATCH 4/4] Make the `Take` button work on the issue page --- diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 0505dea..f6d2f90 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -147,8 +147,12 @@ {% else %} unassigned {% endif %} - {% if authenticated and repo_admin %} - + {% if authenticated and repo_admin + and (not issue.assignee or issue.assignee.username != g.fas_user.username) %} + {% endif %} @@ -615,6 +619,25 @@ $( document ).ready(function() { } ); + {% if authenticated and repo_admin %} + $("#take-btn").click(function(){ + var _url = "{{ url_for( + 'api_ns.api_assign_issue', repo=repo.name, username=username, issueid=issueid + ) }}"; + var _data = {assignee: "{{ g.fas_user.username }}"}; + $.post( _url, _data ).done( + function(data) { + var _user_url = '\n' + + '{{ g.fas_user.username }}'; + $('#assignee_plain').html(_user_url); + $('#assignee').val("{{ g.fas_user.username }}"); + } + ) + return false; + }); + {% endif %} + }); {% endblock %}