From 48b2c53ffb71cce1fe572cdbf84f2f949867e1e1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 19 2018 11:56:34 +0000 Subject: [PATCH 1/3] Add a link to the group when viewing a namespace When viewing projects of a namespace, it is nice to be able to access quickly the group which is underneath this namespace (assuming there is one, ie that the namespace isn't in the list of allowed_prefix). Fixes https://pagure.io/pagure/issue/3582 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/templates/index.html b/pagure/templates/index.html index 176b950..98bf911 100644 --- a/pagure/templates/index.html +++ b/pagure/templates/index.html @@ -18,6 +18,16 @@ {{ browse_header(select=select) }} + {% if namespace %} +
+

+ These projects are under the `{{ namespace }}` namespace making them + likely related to the {{ namespace }} + group. +

+
+ {% endif %}
{{ render_repos( repos, total_page, 'page', page, diff --git a/pagure/ui/app.py b/pagure/ui/app.py index 4639798..77001a8 100644 --- a/pagure/ui/app.py +++ b/pagure/ui/app.py @@ -633,8 +633,12 @@ def view_projects(pattern=None, namespace=None): total_page = int(ceil(projects_length / float(limit))) + if namespace in pagure_config["ALLOWED_PREFIX"]: + namespace = None + return flask.render_template( "index.html", + namespace=namespace, repos=projects, repos_length=projects_length, total_page=total_page, From 7b3c51e5584951900aecc1a652e3c6e8d776c099 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 19 2018 13:37:17 +0000 Subject: [PATCH 2/3] Fix tests Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/ui/app.py b/pagure/ui/app.py index 77001a8..a9755ad 100644 --- a/pagure/ui/app.py +++ b/pagure/ui/app.py @@ -58,8 +58,11 @@ def _filter_acls(repos, acl, user): def index(): """ Front page of the application. """ - if authenticated() and flask.request.path == "/" \ - and not flask.session.get("_requires_fpca", False): + if ( + authenticated() + and flask.request.path == "/" + and not flask.session.get("_requires_fpca", False) + ): flask.request.from_index = True return flask.redirect(flask.url_for("ui_ns.userdash_projects")) diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index 56376a6..e39d35e 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -19,7 +19,6 @@ from __future__ import unicode_literals import datetime import logging import os -import re from collections import defaultdict, OrderedDict from math import ceil @@ -33,7 +32,7 @@ import pagure.doc_utils import pagure.exceptions import pagure.lib import pagure.lib.mimetype -from pagure.decorators import has_issue_tracker, is_repo_admin, has_trackers +from pagure.decorators import has_issue_tracker, is_repo_admin import pagure.forms from pagure.config import config as pagure_config diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index f901c95..68e19db 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -23,6 +23,7 @@ import datetime import json import logging import os +import re from math import ceil import flask @@ -3222,7 +3223,7 @@ def update_tags(repo, username=None, namespace=None): @UI_NS.route("/fork////droptag/", methods=["POST"]) @login_required @is_repo_admin -@has_issue_tracker +@has_trackers def remove_tag(repo, username=None, namespace=None): """ Remove the specified tag, associated with the issues, from the project. """ @@ -3275,7 +3276,7 @@ def remove_tag(repo, username=None, namespace=None): ) @login_required @is_repo_admin -@has_issue_tracker +@has_trackers def edit_tag(repo, tag, username=None, namespace=None): """ Edit the specified tag associated with the issues of a project. """ From f2c200b6feedc94cd0f23a7451f0ba30a27c48e0 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 19 2018 14:59:01 +0000 Subject: [PATCH 3/3] Raise a 401 when trying to update a tag In projects that have disabled PRs and made tickets read-only. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/decorators.py b/pagure/decorators.py index b24f3d6..323a7a4 100644 --- a/pagure/decorators.py +++ b/pagure/decorators.py @@ -51,6 +51,10 @@ def has_trackers(function): "issue_tracker", True ) and not repo.settings.get("pull_requests", True): flask.abort(404, "No ticket trackers found for this project") + elif flask.request.method == "POST" \ + and repo.settings.get("issue_tracker_read_only", False) \ + and not repo.settings.get("pull_requests", True): + flask.abort(401, "The issue tracker for this project is read-only") return function(*args, **kwargs) return check_trackers diff --git a/tests/test_pagure_flask_ui_issues_read_only.py b/tests/test_pagure_flask_ui_issues_read_only.py index b8a8171..1acd03e 100644 --- a/tests/test_pagure_flask_ui_issues_read_only.py +++ b/tests/test_pagure_flask_ui_issues_read_only.py @@ -149,34 +149,6 @@ class PagureFlaskIssuesReadOnlytests(tests.Modeltests): '

The issue tracker for this project is read-only

', output_text) - def test_edit_tag(self): - """ Test editing a ticket tag. - """ - user = tests.FakeUser(username='pingou') - with tests.user_set(self.app.application, user): - output = self.app.post('/test/tag/tag1/edit', data={}) - self.assertEqual(output.status_code, 401) - output_text = output.get_data(as_text=True) - self.assertIn( - 'Unauthorized :\'( - Pagure', output_text) - self.assertIn( - '

The issue tracker for this project is read-only

', - output_text) - - def test_drop_tags(self): - """ Test dropping a ticket tag. - """ - user = tests.FakeUser(username='pingou') - with tests.user_set(self.app.application, user): - output = self.app.post('/test/droptag/', data={}) - self.assertEqual(output.status_code, 401) - output_text = output.get_data(as_text=True) - self.assertIn( - 'Unauthorized :\'( - Pagure', output_text) - self.assertIn( - '

The issue tracker for this project is read-only

', - output_text) - def test_new_issue(self): """ Test creating a new ticket. """ @@ -351,5 +323,80 @@ class PagureFlaskAPIIssuesReadOnlytests(PagureFlaskIssuesReadOnlytests): ) +class PagureFlaskIssuesAndPRDisabledtests(tests.Modeltests): + """ Tests for flask issues controller of pagure with tickets and PRs + disabled. + """ + + @patch('pagure.lib.notify.send_email', MagicMock(return_value=True)) + def setUp(self): + """ Set up the environnment, ran before every tests. """ + super(PagureFlaskIssuesAndPRDisabledtests, self).setUp() + + tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path, 'repos')) + + # Make the project's issue tracker read-only + repo = pagure.lib.get_authorized_project(self.session, 'test') + settings = repo.settings + settings['pull_requests'] = False + settings['issue_tracker_read_only'] = True + repo.settings = settings + self.session.add(repo) + self.session.commit() + + # Create a couple of issue + msg = pagure.lib.new_issue( + session=self.session, + repo=repo, + title='Test issue #1', + content='We should work on this for the second time', + user='foo', + status='Open', + private=True, + ) + self.session.commit() + self.assertEqual(msg.title, 'Test issue #1') + + msg = pagure.lib.new_issue( + session=self.session, + repo=repo, + title='Test issue #2', + content='We should work on this for the second time', + user='foo', + status='Open', + private=False, + ) + self.session.commit() + self.assertEqual(msg.title, 'Test issue #2') + + def test_edit_tag(self): + """ Test editing a ticket tag. + """ + user = tests.FakeUser(username='pingou') + with tests.user_set(self.app.application, user): + output = self.app.post('/test/tag/tag1/edit', data={}) + self.assertEqual(output.status_code, 401) + output_text = output.get_data(as_text=True) + self.assertIn( + 'Unauthorized :\'( - Pagure', output_text) + self.assertIn( + '

The issue tracker for this project is read-only

', + output_text) + + def test_drop_tags(self): + """ Test dropping a ticket tag. + """ + user = tests.FakeUser(username='pingou') + with tests.user_set(self.app.application, user): + output = self.app.post('/test/droptag/', data={}) + self.assertEqual(output.status_code, 401) + output_text = output.get_data(as_text=True) + self.assertIn( + 'Unauthorized :\'( - Pagure', output_text) + self.assertIn( + '

The issue tracker for this project is read-only

', + output_text) + if __name__ == '__main__': unittest.main(verbosity=2)