diff --git a/rhodecode/apps/repository/__init__.py b/rhodecode/apps/repository/__init__.py --- a/rhodecode/apps/repository/__init__.py +++ b/rhodecode/apps/repository/__init__.py @@ -369,6 +369,10 @@ def includeme(config): name='edit_repo_perms', pattern='/{repo_name:.*?[^/]}/settings/permissions', repo_route=True) + config.add_route( + name='edit_repo_perms_set_private', + pattern='/{repo_name:.*?[^/]}/settings/permissions/set_private', repo_route=True) + # Permissions Branch (EE feature) config.add_route( name='edit_repo_perms_branch', diff --git a/rhodecode/apps/repository/views/repo_permissions.py b/rhodecode/apps/repository/views/repo_permissions.py --- a/rhodecode/apps/repository/views/repo_permissions.py +++ b/rhodecode/apps/repository/views/repo_permissions.py @@ -105,3 +105,30 @@ class RepoSettingsPermissionsView(RepoAp raise HTTPFound( h.route_path('edit_repo_perms', repo_name=self.db_repo_name)) + + @LoginRequired() + @HasRepoPermissionAnyDecorator('repository.admin') + @CSRFRequired() + @view_config( + route_name='edit_repo_perms_set_private', request_method='POST', + renderer='json_ext') + def edit_permissions_set_private_repo(self): + _ = self.request.translate + self.load_default_context() + + try: + RepoModel().update( + self.db_repo, **{'repo_private': True, 'repo_name': self.db_repo_name}) + Session().commit() + + h.flash(_('Repository `{}` private mode set successfully').format(self.db_repo_name), + category='success') + except Exception: + log.exception("Exception during update of repository") + h.flash(_('Error occurred during update of repository {}').format( + self.db_repo_name), category='error') + + return { + 'redirect_url': h.route_path('edit_repo_perms', repo_name=self.db_repo_name), + 'private': True + } diff --git a/rhodecode/model/repo.py b/rhodecode/model/repo.py --- a/rhodecode/model/repo.py +++ b/rhodecode/model/repo.py @@ -374,8 +374,7 @@ class RepoModel(BaseModel): ) # handle extra fields - for field in filter(lambda k: k.startswith(RepositoryField.PREFIX), - kwargs): + for field in filter(lambda k: k.startswith(RepositoryField.PREFIX), kwargs): k = RepositoryField.un_prefix_key(field) ex_field = RepositoryField.get_by_key_name( key=k, repo=cur_repo) diff --git a/rhodecode/public/js/rhodecode/routes.js b/rhodecode/public/js/rhodecode/routes.js --- a/rhodecode/public/js/rhodecode/routes.js +++ b/rhodecode/public/js/rhodecode/routes.js @@ -239,6 +239,7 @@ function registerRCRoutes() { pyroutes.register('edit_repo_advanced_hooks', '/%(repo_name)s/settings/advanced/hooks', ['repo_name']); pyroutes.register('edit_repo_caches', '/%(repo_name)s/settings/caches', ['repo_name']); pyroutes.register('edit_repo_perms', '/%(repo_name)s/settings/permissions', ['repo_name']); + pyroutes.register('edit_repo_perms_set_private', '/%(repo_name)s/settings/permissions/set_private', ['repo_name']); pyroutes.register('edit_repo_maintenance', '/%(repo_name)s/settings/maintenance', ['repo_name']); pyroutes.register('edit_repo_maintenance_execute', '/%(repo_name)s/settings/maintenance/execute', ['repo_name']); pyroutes.register('edit_repo_fields', '/%(repo_name)s/settings/fields', ['repo_name']); diff --git a/rhodecode/templates/admin/repos/repo_edit_permissions.mako b/rhodecode/templates/admin/repos/repo_edit_permissions.mako --- a/rhodecode/templates/admin/repos/repo_edit_permissions.mako +++ b/rhodecode/templates/admin/repos/repo_edit_permissions.mako @@ -105,6 +105,10 @@ member="${_user.user_id}" member_type="user"> ${_('Remove')} + %elif _user.username == h.DEFAULT_USER: + + ${_('set private mode')} + %endif