# HG changeset patch # User Mads Kiilerich # Date 2022-12-11 23:25:22 # Node ID f2dc57c123cf448cca9dc6cfb9cc1054ff491035 # Parent d00371a768c91915cab2afd6b49f620e97f53e87 repo: introduce enable_downloads and enable_statistics when creating repos These booleans were not shown in the normal repo creation form, so the form validation applied the "default" values of False. These values were however not used by the model when creating repos - it just unconditionally used the real global defaults. The API already exposed some of this, but it wasn't implemented. The web form for creating repos lacked these fields, but it was present in the repo edit form. Just make these fields mandatory. There will thus not be any defaults to apply in the model for creating repos. diff --git a/kallithea/controllers/api/api.py b/kallithea/controllers/api/api.py --- a/kallithea/controllers/api/api.py +++ b/kallithea/controllers/api/api.py @@ -1230,8 +1230,8 @@ class ApiController(JSONRPCController): clone_uri=clone_uri, repo_group=group_name, repo_landing_rev=landing_rev, - enable_statistics=enable_statistics, - enable_downloads=enable_downloads, + repo_enable_statistics=enable_statistics, + repo_enable_downloads=enable_downloads, repo_copy_permissions=copy_permissions, ) diff --git a/kallithea/model/repo.py b/kallithea/model/repo.py --- a/kallithea/model/repo.py +++ b/kallithea/model/repo.py @@ -711,13 +711,10 @@ def create_repo(form_data, cur_user): copy_fork_permissions = form_data.get('copy_permissions') copy_group_permissions = form_data.get('repo_copy_permissions') fork_of = form_data.get('fork_parent_id') + enable_statistics = form_data['repo_enable_statistics'] + enable_downloads = form_data['repo_enable_downloads'] state = form_data.get('repo_state', db.Repository.STATE_PENDING) - # repo creation defaults, private and repo_type are filled in form - defs = db.Setting.get_default_repo_settings(strip_prefix=True) - enable_statistics = defs.get('repo_enable_statistics') - enable_downloads = defs.get('repo_enable_downloads') - try: db_repo = RepoModel()._create_repo( repo_name=repo_name_full, diff --git a/kallithea/templates/admin/repos/repo_add_base.html b/kallithea/templates/admin/repos/repo_add_base.html --- a/kallithea/templates/admin/repos/repo_add_base.html +++ b/kallithea/templates/admin/repos/repo_add_base.html @@ -58,6 +58,20 @@
+ +
+ ${h.checkbox('repo_enable_statistics',value="True")} + ${_('Enable statistics window on summary page.')} +
+
+
+ +
+ ${h.checkbox('repo_enable_downloads',value="True")} + ${_('Enable download menu on summary page.')} +
+
+
${h.submit('add',_('Add'),class_="btn btn-default")}
diff --git a/kallithea/tests/api/api_base.py b/kallithea/tests/api/api_base.py --- a/kallithea/tests/api/api_base.py +++ b/kallithea/tests/api/api_base.py @@ -792,8 +792,8 @@ class _BaseTestApi(object): ('clone_uri', {'clone_uri': None}), ('landing_rev', {'landing_rev': 'branch:master'}), ('private', {'private': True}), - #('enable_statistics', {'enable_statistics': True}), # currently broken - #('enable_downloads', {'enable_downloads': True}), # currently broken + ('enable_statistics', {'enable_statistics': True}), + ('enable_downloads', {'enable_downloads': True}), ('repo_group', {'group': 'test_group_for_update'}), ]) def test_api_create_repo(self, changing_attr, updates): diff --git a/kallithea/tests/fixture.py b/kallithea/tests/fixture.py --- a/kallithea/tests/fixture.py +++ b/kallithea/tests/fixture.py @@ -95,6 +95,8 @@ class Fixture(object): repo_group='-1', repo_description='DESC', repo_private=False, + repo_enable_statistics=False, + repo_enable_downloads=False, repo_landing_rev='rev:tip', repo_copy_permissions=False, repo_state=db.Repository.STATE_CREATED,