diff --git a/rhodecode/apps/admin/views/repo_groups.py b/rhodecode/apps/admin/views/repo_groups.py --- a/rhodecode/apps/admin/views/repo_groups.py +++ b/rhodecode/apps/admin/views/repo_groups.py @@ -69,6 +69,7 @@ class AdminRepoGroupsView(BaseAppView, D c.repo_groups = RepoGroup.groups_choices( groups=groups_with_admin_rights, show_empty_group=allow_empty_group) + c.personal_repo_group = self._rhodecode_user.personal_repo_group def _can_create_repo_group(self, parent_group_id=None): is_admin = HasPermissionAny('hg.admin')('group create controller') @@ -261,15 +262,28 @@ class AdminRepoGroupsView(BaseAppView, D # perm check for admin, create_group perm or admin of parent_group parent_group_id = safe_int(self.request.GET.get('parent_group')) + _gr = RepoGroup.get(parent_group_id) if not self._can_create_repo_group(parent_group_id): raise HTTPForbidden() self._load_form_data(c) defaults = {} # Future proof for default of repo group + + parent_group_choice = '-1' + if not self._rhodecode_user.is_admin and self._rhodecode_user.personal_repo_group: + parent_group_choice = self._rhodecode_user.personal_repo_group + + if parent_group_id and _gr: + if parent_group_id in [x[0] for x in c.repo_groups]: + parent_group_choice = safe_unicode(parent_group_id) + + defaults.update({'group_parent_id': parent_group_choice}) + data = render( 'rhodecode:templates/admin/repo_groups/repo_group_add.mako', self._get_template_context(c), self.request) + html = formencode.htmlfill.render( data, defaults=defaults, diff --git a/rhodecode/apps/admin/views/repositories.py b/rhodecode/apps/admin/views/repositories.py --- a/rhodecode/apps/admin/views/repositories.py +++ b/rhodecode/apps/admin/views/repositories.py @@ -169,8 +169,8 @@ class AdminReposView(BaseAppView, DataGr c = self.load_default_context() new_repo = self.request.GET.get('repo', '') - parent_group = safe_int(self.request.GET.get('parent_group')) - _gr = RepoGroup.get(parent_group) + parent_group_id = safe_int(self.request.GET.get('parent_group')) + _gr = RepoGroup.get(parent_group_id) if not HasPermissionAny('hg.admin', 'hg.create.repository')(): # you're not super admin nor have global create permissions, @@ -196,9 +196,9 @@ class AdminReposView(BaseAppView, DataGr if not self._rhodecode_user.is_admin and self._rhodecode_user.personal_repo_group: parent_group_choice = self._rhodecode_user.personal_repo_group - if parent_group and _gr: - if parent_group in [x[0] for x in c.repo_groups]: - parent_group_choice = safe_unicode(parent_group) + if parent_group_id and _gr: + if parent_group_id in [x[0] for x in c.repo_groups]: + parent_group_choice = safe_unicode(parent_group_id) defaults.update({'repo_group': parent_group_choice}) diff --git a/rhodecode/templates/admin/repo_groups/repo_group_add.mako b/rhodecode/templates/admin/repo_groups/repo_group_add.mako --- a/rhodecode/templates/admin/repo_groups/repo_group_add.mako +++ b/rhodecode/templates/admin/repo_groups/repo_group_add.mako @@ -44,7 +44,12 @@