Changeset - f2dc57c123cf
[Not reviewed]
stable
0 5 0
Mads Kiilerich (mads) - 3 years ago 2022-12-12 00:25:22
mads@kiilerich.com
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.
5 files changed with 22 insertions and 9 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/api/api.py
Show inline comments
 
@@ -1221,26 +1221,26 @@ class ApiController(JSONRPCController):
 
            enable_downloads = defs.get('repo_enable_downloads')
 

	
 
        try:
 
            data = dict(
 
                repo_name=repo_name_parts[-1],
 
                repo_name_full=repo_name,
 
                repo_type=repo_type,
 
                repo_description=description,
 
                repo_private=private,
 
                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,
 
            )
 

	
 
            RepoModel().create(form_data=data, cur_user=owner.username)
 
            # no commit, it's done in RepoModel, or async via celery
 
            return dict(
 
                msg="Created new repository `%s`" % (repo_name,),
 
                success=True,  # cannot return the repo data here since fork
 
                               # can be done async
 
            )
 
        except Exception:
 
            log.error(traceback.format_exc())
kallithea/model/repo.py
Show inline comments
 
@@ -702,31 +702,28 @@ def create_repo(form_data, cur_user):
 
    owner = cur_user
 
    repo_name = form_data['repo_name']
 
    repo_name_full = form_data['repo_name_full']
 
    repo_type = form_data['repo_type']
 
    description = form_data['repo_description']
 
    private = form_data['repo_private']
 
    clone_uri = form_data.get('clone_uri')
 
    repo_group = form_data['repo_group']
 
    landing_rev = form_data['repo_landing_rev']
 
    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,
 
            repo_type=repo_type,
 
            description=description,
 
            owner=owner,
 
            private=private,
 
            clone_uri=clone_uri,
 
            repo_group=repo_group,
 
            landing_rev=landing_rev,
 
            fork_of=fork_of,
 
            copy_fork_permissions=copy_fork_permissions,
kallithea/templates/admin/repos/repo_add_base.html
Show inline comments
 
@@ -49,24 +49,38 @@ ${h.form(url('repos'))}
 
                ${h.select('repo_landing_rev',None,c.landing_revs,class_='form-control')}
 
                <span class="help-block">${_('Default revision for files page, downloads, full text search index and readme generation')}</span>
 
            </div>
 
        </div>
 
        <div class="form-group">
 
            <label class="control-label" for="repo_private">${_('Private repository')}:</label>
 
            <div>
 
                ${h.checkbox('repo_private',value="True")}
 
                <span class="help-block">${_('Private repositories are only visible to people explicitly added as collaborators.')}</span>
 
            </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>
 
        </div>
 
    </div>
 
${h.end_form()}
 

	
 
<script>
 
    'use strict';
 
    $(document).ready(function(){
 
        $('#repo_type').select2({
 
            'minimumResultsForSearch': -1
kallithea/tests/api/api_base.py
Show inline comments
 
@@ -783,26 +783,26 @@ class _BaseTestApi(object):
 
            self._compare_ok(id_, expected, given=response.body)
 
        finally:
 
            RepoModel().revoke_user_permission(self.REPO, self.TEST_USER_LOGIN)
 

	
 
    @base.parametrize('changing_attr,updates', [
 
        ('owner', {'owner': base.TEST_USER_REGULAR_LOGIN}),
 
        ('description', {'description': 'new description'}),
 
        ('clone_uri', {'clone_uri': 'http://example.com/repo'}), # will fail - pulling from non-existing repo should fail
 
        ('clone_uri', {'clone_uri': '/repo'}), # will fail - pulling from local repo was a misfeature - it would bypass access control
 
        ('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):
 
        repo_name = repo_name_full = 'new_repo'
 

	
 
        if changing_attr == 'repo_group':
 
            group_name = updates['group']
 
            fixture.create_repo_group(group_name)
 
            repo_name_full = '/'.join([group_name, repo_name])
 
            updates = {}
 

	
 
        id_, params = _build_data(self.apikey, 'create_repo',
kallithea/tests/fixture.py
Show inline comments
 
@@ -86,24 +86,26 @@ class Fixture(object):
 

	
 
        return context()
 

	
 
    def _get_repo_create_params(self, **custom):
 
        """Return form values to be validated through RepoForm"""
 
        defs = dict(
 
            repo_name=None,
 
            repo_type='hg',
 
            clone_uri='',
 
            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,
 
        )
 
        defs.update(custom)
 
        if 'repo_name_full' not in custom:
 
            defs.update({'repo_name_full': defs['repo_name']})
 

	
 
        # fix the repo name if passed as repo_name_full
 
        if defs['repo_name']:
 
            defs['repo_name'] = defs['repo_name'].split('/')[-1]
 

	
0 comments (0 inline, 0 general)