diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -421,6 +421,7 @@ class User(Base, BaseModel): user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all') repositories = relationship('Repository') + repo_groups = relationship('RepoGroup') user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all') followings = relationship('UserFollowing', primaryjoin='UserFollowing.user_id==User.user_id', cascade='all') diff --git a/kallithea/model/user.py b/kallithea/model/user.py --- a/kallithea/model/user.py +++ b/kallithea/model/user.py @@ -258,10 +258,17 @@ class UserModel(BaseModel): if user.repositories: repos = [x.repo_name for x in user.repositories] raise UserOwnsReposException( - _(u'user "%s" still owns %s repositories and cannot be ' - 'removed. Switch owners or remove those repositories. %s') + _(u'User "%s" still owns %s repositories and cannot be ' + 'removed. Switch owners or remove those repositories: %s') % (user.username, len(repos), ', '.join(repos)) ) + if user.repo_groups: + repogroups = [x.group_name for x in user.repo_groups] + raise UserOwnsReposException( + _(u'User "%s" still owns %s repository groups and cannot be ' + 'removed. Switch owners or remove those repository groups: %s') + % (user.username, len(repogroups), ', '.join(repogroups)) + ) self.sa.delete(user) from kallithea.lib.hooks import log_delete_user