From 74baff89f6e20ba23ef2327911bb1c64b8453a0a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 16 2016 08:30:54 +0000 Subject: [PATCH 1/3] There is no reason to always block project with 40 chars project name Instances that are recent enough do not need this restriction, we only use it on old instances to keep backward compatibility on URLs of commits --- diff --git a/pagure/api/project.py b/pagure/api/project.py index 5bd1ae4..5300d07 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -248,6 +248,8 @@ def api_new_project(): requestfolder=APP.config['REQUESTS_FOLDER'], add_readme=create_readme, userobj=user, + prevent_40_chars=APP.config.get( + 'OLD_VIEW_COMMIT_ENABLED', False), ) SESSION.commit() pagure.lib.git.generate_gitolite_acls() diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 76ee859..74398cf 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -979,7 +979,8 @@ def add_pull_request_flag(session, request, username, percent, comment, url, def new_project(session, user, name, blacklist, allowed_prefix, gitfolder, docfolder, ticketfolder, requestfolder, description=None, url=None, avatar_email=None, - parent_id=None, add_readme=False, userobj=None): + parent_id=None, add_readme=False, userobj=None, + prevent_40_chars=False): ''' Create a new project based on the information provided. ''' if name in blacklist: @@ -998,7 +999,8 @@ def new_project(session, user, name, blacklist, allowed_prefix, 'prefix set by the admins of this pagure instance, or the name ' 'of a group that you are part of.' ) - if len(second_part) == 40: + + if len(second_part) == 40 and not prevent_40_chars: # We must block project with a name / where the length # of is exactly 40 characters long as this would otherwise # conflict with the old URL schema used for commit that was diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 636ea0c..cc6ab17 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -392,6 +392,8 @@ def get_project_from_json( docfolder=docfolder, ticketfolder=ticketfolder, requestfolder=requestfolder, + prevent_40_chars=pagure.APP.config.get( + 'OLD_VIEW_COMMIT_ENABLED', False), ) session.commit() diff --git a/pagure/ui/app.py b/pagure/ui/app.py index b688dd6..a395e4a 100644 --- a/pagure/ui/app.py +++ b/pagure/ui/app.py @@ -391,6 +391,8 @@ def new_project(): requestfolder=APP.config['REQUESTS_FOLDER'], add_readme=create_readme, userobj=user, + prevent_40_chars=APP.config.get( + 'OLD_VIEW_COMMIT_ENABLED', False), ) SESSION.commit() pagure.lib.git.generate_gitolite_acls() From 8043ded6a927a9ac371072e81ab5c5cb56ea485e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 16 2016 08:30:54 +0000 Subject: [PATCH 2/3] Add unit-tests checking pagure.lib.new_project's behavior These tests check the behavior of pagure.lib.new_project for creating project with names of 40 chars length. --- diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index 739c421..c0037df 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -749,6 +749,23 @@ class PagureLibtests(tests.Modeltests): parent_id=None, ) + # Try creating a 40 chars project + self.assertRaises( + pagure.exceptions.PagureException, + pagure.lib.new_project, + session=self.session, + user='pingou', + name='pingou/' + 's' * 40, + blacklist=['static'], + allowed_prefix=['pingou'], + gitfolder=gitfolder, + docfolder=docfolder, + ticketfolder=ticketfolder, + requestfolder=requestfolder, + description='description for 40 chars length project', + parent_id=None, + ) + # Create a new project msg = pagure.lib.new_project( session=self.session, @@ -872,6 +889,27 @@ class PagureLibtests(tests.Modeltests): self.assertFalse(os.path.exists(ticketrepo)) self.assertTrue(os.path.exists(requestrepo)) + # Re-Try creating a 40 chars project this time allowing it + msg = pagure.lib.new_project( + session=self.session, + user='pingou', + name='pingou/' + 's' * 40, + blacklist=['static'], + allowed_prefix=['pingou'], + gitfolder=gitfolder, + docfolder=docfolder, + ticketfolder=ticketfolder, + requestfolder=requestfolder, + description='description for 40 chars length project', + parent_id=None, + prevent_40_chars=True, + ) + self.session.commit() + self.assertEqual( + msg, + 'Project "pingou/ssssssssssssssssssssssssssssssssssssssss" ' + 'created') + def test_update_project_settings(self): """ Test the update_project_settings of pagure.lib. """ From 29bb9ec801ebebd7fa454a6fffa0ac0722a38965 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 16 2016 08:30:54 +0000 Subject: [PATCH 3/3] Invert the logic around prevent_40_chars to actually do what we want --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 74398cf..c84d04b 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1000,7 +1000,7 @@ def new_project(session, user, name, blacklist, allowed_prefix, 'of a group that you are part of.' ) - if len(second_part) == 40 and not prevent_40_chars: + if len(second_part) == 40 and prevent_40_chars: # We must block project with a name / where the length # of is exactly 40 characters long as this would otherwise # conflict with the old URL schema used for commit that was diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index c0037df..f233651 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ - (c) 2015 - Copyright Red Hat Inc + (c) 2015-2016 - Copyright Red Hat Inc Authors: Pierre-Yves Chibon @@ -764,6 +764,7 @@ class PagureLibtests(tests.Modeltests): requestfolder=requestfolder, description='description for 40 chars length project', parent_id=None, + prevent_40_chars=True, ) # Create a new project @@ -902,7 +903,6 @@ class PagureLibtests(tests.Modeltests): requestfolder=requestfolder, description='description for 40 chars length project', parent_id=None, - prevent_40_chars=True, ) self.session.commit() self.assertEqual(