From e14f1e79d2f24e96468c9d7334d4087e10ba06a3 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 13 2017 14:10:29 +0000 Subject: [PATCH 1/4] Ensure people with ticket metadata can edit the custom fields. --- diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 5fccec2..892a985 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -379,7 +379,7 @@

- {% if authenticated and g.repo_admin %} + {% if authenticated and g.repo_user %}
{% if field.key_type == 'list' %} From 95877ad743d0ab26873ed57c81fe0d59d28ba676 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 13 2017 14:10:29 +0000 Subject: [PATCH 2/4] Add unit-tests ensuring people with ticket access to view and edit custom fields Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/test_pagure_flask_ui_issues.py b/tests/test_pagure_flask_ui_issues.py index fd42b0a..b328ea0 100644 --- a/tests/test_pagure_flask_ui_issues.py +++ b/tests/test_pagure_flask_ui_issues.py @@ -689,6 +689,126 @@ class PagureFlaskIssuestests(tests.Modeltests): @patch('pagure.lib.git.update_git') @patch('pagure.lib.notify.send_email') + def test_view_issue_custom_field_user_ticket(self, p_send_email, p_ugt): + """ Test the view_issue endpoint. """ + p_send_email.return_value = True + p_ugt.return_value = True + + output = self.app.get('/foo/issue/1') + self.assertEqual(output.status_code, 404) + + tests.create_projects(self.session) + tests.create_projects_git( + os.path.join(self.path), bare=True) + + output = self.app.get('/test/issue/1') + self.assertEqual(output.status_code, 404) + + # Create issues to play with + repo = pagure.lib.get_project(self.session, 'test') + msg = pagure.lib.new_issue( + session=self.session, + repo=repo, + title='Test issue', + content='We should work on this', + user='pingou', + ticketfolder=None + ) + self.session.commit() + self.assertEqual(msg.title, 'Test issue') + + # Add user 'foo' with ticket access on repo + repo = pagure.lib.get_project(self.session, 'test') + msg = pagure.lib.add_user_to_project( + self.session, + repo, + new_user='foo', + user='pingou', + access='ticket', + ) + self.assertEqual(msg, 'User added') + self.session.commit() + + # Set some custom fields + repo = pagure.lib.get_project(self.session, 'test') + msg = pagure.lib.set_custom_key_fields( + self.session, + repo, + ['bugzilla', 'upstream', 'reviewstatus'], + ['link', 'boolean', 'list'], + ['unused data for non-list type', '', 'ack, nack , needs review'], + [None, None, None]) + self.session.commit() + self.assertEqual(msg, 'List of custom fields updated') + + # User with no rights + user = tests.FakeUser() + with tests.user_set(pagure.APP, user): + output = self.app.get('/test/issue/1') + self.assertEqual(output.status_code, 200) + self.assertNotIn( + '', + output.data) + self.assertNotIn( + '