diff --git a/pagure/api/__init__.py b/pagure/api/__init__.py index bef5054..7712c16 100644 --- a/pagure/api/__init__.py +++ b/pagure/api/__init__.py @@ -31,7 +31,9 @@ API_ERROR_CODE = { 'reaching completion', 4: 'Invalid or incomplete input submited', 5: 'Invalid or expired token. Please visit %s get or renew your ' - 'API token.' % APP.config['APP_URL'] + 'API token.' % APP.config['APP_URL'], + 6: 'Issue not found', + 7: 'You are not allowed to view this issue', } diff --git a/pagure/api/issue.py b/pagure/api/issue.py index fee7425..09bf206 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -36,7 +36,6 @@ def api_new_issue(repo, username=None): if not repo.settings.get('issue_tracker', True): raise pagure.exceptions.APIError(404, error_code=2) - if repo != flask.g.token.project: raise pagure.exceptions.APIError(401, error_code=5) @@ -98,3 +97,36 @@ def api_new_issue(repo, username=None): jsonout = flask.jsonify(output) jsonout.status_code = httpcode return jsonout + + +@API.route('//issue/') +@API.route('/fork///issue/') +@api_method +def api_view_issue(repo, issueid, username=None): + """ List all issues associated to a repo + """ + + repo = pagure.lib.get_project(SESSION, repo, user=username) + httpcode = 200 + output = {} + + if repo is None: + raise pagure.exceptions.APIError(404, error_code=1) + + if not repo.settings.get('issue_tracker', True): + raise pagure.exceptions.APIError(404, error_code=2) + + issue = pagure.lib.search_issues(SESSION, repo, issueid=issueid) + + if issue is None or issue.project != repo: + raise pagure.exceptions.APIError(404, error_code=6) + + if issue.private and not is_repo_admin(repo) \ + and (not authenticated() or + not issue.user.user == flask.g.fas_user.username): + raise pagure.exceptions.APIError(403, error_code=7) + + + jsonout = flask.jsonify(issue.to_json()) + jsonout.status_code = httpcode + return jsonout