changeset 8942:f2dc57c123cf stable

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.
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 12 Dec 2022 00:25:22 +0100
parents d00371a768c9
children 5f8f52a2f4b4
files kallithea/controllers/api/api.py kallithea/model/repo.py kallithea/templates/admin/repos/repo_add_base.html kallithea/tests/api/api_base.py kallithea/tests/fixture.py
diffstat 5 files changed, 22 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/api/api.py	Sun Dec 11 02:05:08 2022 +0100
+++ b/kallithea/controllers/api/api.py	Mon Dec 12 00:25:22 2022 +0100
@@ -1230,8 +1230,8 @@
                 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,
             )
 
--- a/kallithea/model/repo.py	Sun Dec 11 02:05:08 2022 +0100
+++ b/kallithea/model/repo.py	Mon Dec 12 00:25:22 2022 +0100
@@ -711,13 +711,10 @@
     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,
--- a/kallithea/templates/admin/repos/repo_add_base.html	Sun Dec 11 02:05:08 2022 +0100
+++ b/kallithea/templates/admin/repos/repo_add_base.html	Mon Dec 12 00:25:22 2022 +0100
@@ -58,6 +58,20 @@
             </div>
         </div>
         <div class="form-group">
+            <label class="control-label" for="repo_enable_statistics">${_('Enable statistics')}:</label>
+            <div>
+                ${h.checkbox('repo_enable_statistics',value="True")}
+                <span class="help-block">${_('Enable statistics window on summary page.')}</span>
+            </div>
+        </div>
+        <div class="form-group">
+            <label class="control-label" for="repo_enable_downloads">${_('Enable downloads')}:</label>
+            <div>
+                ${h.checkbox('repo_enable_downloads',value="True")}
+                <span class="help-block">${_('Enable download menu on summary page.')}</span>
+            </div>
+        </div>
+        <div class="form-group">
             <div class="buttons">
                 ${h.submit('add',_('Add'),class_="btn btn-default")}
             </div>
--- a/kallithea/tests/api/api_base.py	Sun Dec 11 02:05:08 2022 +0100
+++ b/kallithea/tests/api/api_base.py	Mon Dec 12 00:25:22 2022 +0100
@@ -792,8 +792,8 @@
         ('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):
--- a/kallithea/tests/fixture.py	Sun Dec 11 02:05:08 2022 +0100
+++ b/kallithea/tests/fixture.py	Mon Dec 12 00:25:22 2022 +0100
@@ -95,6 +95,8 @@
             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,