diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -422,6 +422,7 @@ class User(Base, BaseModel): repositories = relationship('Repository') repo_groups = relationship('RepoGroup') + user_groups = relationship('UserGroup') 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 @@ -269,6 +269,13 @@ class UserModel(BaseModel): 'removed. Switch owners or remove those repository groups: %s') % (user.username, len(repogroups), ', '.join(repogroups)) ) + if user.user_groups: + usergroups = [x.users_group_name for x in user.user_groups] + raise UserOwnsReposException( + _(u'User "%s" still owns %s user groups and cannot be ' + 'removed. Switch owners or remove those user groups: %s') + % (user.username, len(usergroups), ', '.join(usergroups)) + ) self.sa.delete(user) from kallithea.lib.hooks import log_delete_user