# HG changeset patch # User Mads Kiilerich # Date 1420502076 -3600 # Node ID 1a2e7a8d144cd498a34559fabea678ed433ca3e3 # Parent 5f0e40fad7da9b05280fe01f09060ce2d8f037d9 user: prevent deletion of users that are owners of a user group TODO: make it possible to reassign group ownership diff -r 5f0e40fad7da -r 1a2e7a8d144c kallithea/model/db.py --- a/kallithea/model/db.py Tue Jan 06 00:54:36 2015 +0100 +++ b/kallithea/model/db.py Tue Jan 06 00:54:36 2015 +0100 @@ -422,6 +422,7 @@ 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 -r 5f0e40fad7da -r 1a2e7a8d144c kallithea/model/user.py --- a/kallithea/model/user.py Tue Jan 06 00:54:36 2015 +0100 +++ b/kallithea/model/user.py Tue Jan 06 00:54:36 2015 +0100 @@ -269,6 +269,13 @@ '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