From babe37834792cebea8dae105ba284ec29285c4c8 Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Nov 29 2016 14:31:20 +0000 Subject: Add a view for open pull requests and issues This adds a new view that shows a user all their issues. It adds both that view and the existing view for pull requests to the master template when a user is logged in. fixes #1077 Signed-off-by: Jeremy Cline --- diff --git a/pagure/templates/master.html b/pagure/templates/master.html index d20f9be..25b49c5 100644 --- a/pagure/templates/master.html +++ b/pagure/templates/master.html @@ -37,6 +37,16 @@ {% if not nologin %} {% if g.fas_user %} + + {% if admin %} diff --git a/pagure/templates/user_issues.html b/pagure/templates/user_issues.html new file mode 100644 index 0000000..04a0f8f --- /dev/null +++ b/pagure/templates/user_issues.html @@ -0,0 +1,110 @@ +{% extends "master.html" %} + +{% block title %}Issues opened by {{ username }}{% endblock %} + + +{% block content %} +
+
+

+ Issues opened by {{ username | avatar(20) | safe }} {{ username }} +

+
+ + Open + Closed + All + +
+ + + + + + + + + + + + + + + {% for issue in user.issues %} + + + + + + + + + {% else %} + + + + {% endfor %} + +
#StatusTitleOpenedProjectAssigned to
#{{ issue.id }}{{issue.status}} + + {% if issue.private %} + Private Issue + {% else %} + {{ issue.title | noJS("img") | safe }} + {% endif %} + + + {{ + issue.date_created | humanize}} + + + {{ issue.project.username + '/' if issue.project.is_fork }} + {{ issue.project.namespace + '/' if issue.project.namespace }} + {{ issue.project.name }} + + + {% if issue.assignee %} + {{ issue.assignee.default_email | avatar(16) | safe }} + {{ issue.assignee.user }} + {% else %} + unassigned + {% endif %} +
No issues found
+
+
+ +{% endblock %} + +{% block jscripts %} + {{ super() }} + +{% endblock %} diff --git a/pagure/templates/user_requests.html b/pagure/templates/user_requests.html index 2ae88fe..61922cf 100644 --- a/pagure/templates/user_requests.html +++ b/pagure/templates/user_requests.html @@ -1,17 +1,9 @@ {% extends "master.html" %} -{% from "_formhelper.html" import render_field_in_row %} -{% from "_browseheader.html" import browse_header %} {% block title %}Pull-requests of {{ username }}{% endblock %} -{% set tag = "users"%} {% block content %} -
-
- {{browse_header(select=tag)}} -
-

diff --git a/pagure/ui/app.py b/pagure/ui/app.py index 5d85c70..587e054 100644 --- a/pagure/ui/app.py +++ b/pagure/ui/app.py @@ -358,6 +358,26 @@ def view_user_requests(username): ) +@APP.route('/user//issues/') +@APP.route('/user//issues') +def view_user_issues(username): + """ + Shows the issues created by the specified user. + + :param username: The username to retrieve the issues for + :type username: str + """ + user = pagure.lib.search_user(SESSION, username=username) + if not user: + flask.abort(404, 'No user `%s` found' % username) + + return flask.render_template( + 'user_issues.html', + username=username, + user=user, + ) + + @APP.route('/new/', methods=('GET', 'POST')) @APP.route('/new', methods=('GET', 'POST')) @login_required @@ -467,6 +487,7 @@ def user_settings(): form=form, ) + @APP.route('/settings/usersettings', methods=['POST']) @login_required def update_user_settings(): diff --git a/tests/__init__.py b/tests/__init__.py index cacf7c0..395d2e3 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -188,6 +188,17 @@ class Modeltests(unittest.TestCase): # Prevent unit-tests to send email, globally pagure.APP.config['EMAIL_SEND'] = False + pagure.APP.config['TESTING'] = True + pagure.APP.config['GIT_FOLDER'] = self.path + pagure.APP.config['FORK_FOLDER'] = os.path.join( + self.path, 'forks') + pagure.APP.config['TICKETS_FOLDER'] = os.path.join( + self.path, 'tickets') + pagure.APP.config['DOCS_FOLDER'] = os.path.join( + self.path, 'docs') + pagure.APP.config['REQUESTS_FOLDER'] = os.path.join( + self.path, 'requests') + self.app = pagure.APP.test_client() def tearDown(self): # pylint: disable=invalid-name """ Remove the test.db database if there is one. """ diff --git a/tests/test_pagure_flask_ui_app.py b/tests/test_pagure_flask_ui_app.py index 744dc24..3e2d9c6 100644 --- a/tests/test_pagure_flask_ui_app.py +++ b/tests/test_pagure_flask_ui_app.py @@ -923,6 +923,55 @@ class PagureFlaskApptests(tests.Modeltests): self.assertEqual(output.status_code, 302) +class ViewMyRequestsTests(tests.Modeltests): + + def test_view_my_requests_no_user(self): + """Test the endpoint.""" + output = self.app.get('/user/somenonexistentuser/requests') + self.assertEqual(output.status_code, 404) + + def test_view_my_requests(self): + """Test the index endpoint. """ + user = tests.FakeUser(username='jcline') + with tests.user_set(pagure.APP, user): + output = self.app.get('/user/jcline/requests') + self.assertEqual(output.status_code, 200) + + +class ViewMyIssuesTests(tests.Modeltests): + + @classmethod + def setUpClass(cls): + """ Set up the environnment, ran before every tests. """ + super(ViewMyIssuesTests, cls).setUpClass() + tests.create_projects(cls.session) + tests.create_projects_git( + os.path.join(cls.path, 'tickets'), bare=True) + tests.create_tokens(cls.session) + tests.create_tokens_acl(cls.session) + + headers = {'Authorization': 'token aaabbbcccddd'} + data = { + 'title': 'test issue', + 'issue_content': 'This issue needs attention', + } + + # Valid request + cls.app.post('/api/0/test/new_issue', data=data, headers=headers) + + def test_view_my_issues_no_user(self): + """Test the endpoint.""" + output = self.app.get('/user/somenonexistentuser/issues') + self.assertEqual(output.status_code, 404) + + def test_view_my_issues(self): + """Test the index endpoint. """ + user = tests.FakeUser(username='jcline') + with tests.user_set(pagure.APP, user): + output = self.app.get('/user/jcline/issues') + self.assertEqual(output.status_code, 200) + + if __name__ == '__main__': SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskApptests) unittest.TextTestRunner(verbosity=2).run(SUITE)