From 126889817645a1e5a25a5a564ac71e884e395f4a Mon Sep 17 00:00:00 2001 From: Veiko Aasa Date: Tue, 27 Feb 2024 09:15:54 +0200 Subject: [PATCH] gitweb: Fix modifying git repositories when gitweb app is disabled Fixes #2408. - When app is disabled, continue to update the app shortcut's login required property. Otherwise, the value is current after the app is re-enabled. - When public access is enabled, the gitweb-freedombox-auth.conf configuration must be disabled. This can be done even if the configuration is already disabled or does not exist. So, continue doing this. Signed-off-by: Veiko Aasa [sunil: Perform enable public access even if app is disabled] [sunil: Perform shortcut update in all cases even if app is disabled] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/modules/gitweb/__init__.py | 4 +- .../modules/gitweb/tests/test_functional.py | 41 ++++++++++++------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/plinth/modules/gitweb/__init__.py b/plinth/modules/gitweb/__init__.py index 26c9c968b..3d8599217 100644 --- a/plinth/modules/gitweb/__init__.py +++ b/plinth/modules/gitweb/__init__.py @@ -98,7 +98,7 @@ class GitwebApp(app_module.App): def post_init(self): """Perform post initialization operations.""" - if not self.needs_setup() and self.is_enabled(): + if not self.needs_setup(): self.update_service_access() def set_shortcut_login_required(self, login_required): @@ -122,7 +122,7 @@ class GitwebApp(app_module.App): def _disable_public_access(self): """Allow Gitweb app to be accessed by logged-in users only.""" - if not self.auth_webserver.is_conf_enabled(): + if self.is_enabled() and not self.auth_webserver.is_conf_enabled(): self.auth_webserver.enable() self.set_shortcut_login_required(True) diff --git a/plinth/modules/gitweb/tests/test_functional.py b/plinth/modules/gitweb/tests/test_functional.py index 5c833aaff..5f8a67ee7 100644 --- a/plinth/modules/gitweb/tests/test_functional.py +++ b/plinth/modules/gitweb/tests/test_functional.py @@ -63,23 +63,30 @@ class TestGitwebApp(functional.BaseAppTests): @pytest.mark.parametrize('access', ['public', 'private']) @pytest.mark.parametrize('repo_name', ['Test-repo', 'Test-repo.git']) - def test_create_delete_repo(self, session_browser, access, repo_name): + @pytest.mark.parametrize('app_status', ['enabled', 'disabled']) + def test_create_delete_repo(self, session_browser, access, repo_name, + app_status): """Test creating and deleting a repo and accessing with a git client.""" + if app_status == "disabled": + functional.app_disable(session_browser, 'gitweb') + _delete_repo(session_browser, repo_name, ignore_missing=True) _create_repo(session_browser, repo_name, access) assert _repo_exists(session_browser, repo_name, access) - assert _site_repo_exists(session_browser, repo_name) - if access == "public": - assert _repo_is_readable(repo_name) - else: - assert not _repo_is_readable(repo_name) + if app_status == "enabled": + assert _site_repo_exists(session_browser, repo_name) - assert not _repo_is_writable(repo_name) - assert _repo_is_readable(repo_name, with_auth=True) - assert _repo_is_writable(repo_name, with_auth=True) + if access == "public": + assert _repo_is_readable(repo_name) + else: + assert not _repo_is_readable(repo_name) + + assert not _repo_is_writable(repo_name) + assert _repo_is_readable(repo_name, with_auth=True) + assert _repo_is_writable(repo_name, with_auth=True) _delete_repo(session_browser, repo_name) assert not _repo_exists(session_browser, repo_name) @@ -93,8 +100,12 @@ class TestGitwebApp(functional.BaseAppTests): assert _site_repo_exists(session_browser, 'Test-repo') assert not _site_repo_exists(session_browser, 'Test-repo-private') - def test_edit_repo_metadata(self, session_browser): + @pytest.mark.parametrize('app_status', ['enabled', 'disabled']) + def test_edit_repo_metadata(self, session_browser, app_status): """Test edit repo metadata.""" + if app_status == "disabled": + functional.app_disable(session_browser, 'gitweb') + _create_repo(session_browser, 'Test-repo2', 'public', ok_if_exists=True) _delete_repo(session_browser, 'Test-repo', ignore_missing=True) @@ -108,10 +119,12 @@ class TestGitwebApp(functional.BaseAppTests): assert _get_repo_metadata(session_browser, "Test-repo") == repo_metadata - _create_branch('Test-repo', 'branch1') - _set_default_branch(session_browser, 'Test-repo', 'branch1') - assert _get_gitweb_site_default_repo_branch(session_browser, - 'Test-repo') == 'branch1' + if app_status == "enabled": + _create_branch('Test-repo', 'branch1') + _set_default_branch(session_browser, 'Test-repo', 'branch1') + + assert _get_gitweb_site_default_repo_branch( + session_browser, 'Test-repo') == 'branch1' def _create_local_repo(path):