Mercurial > kallithea
changeset 4758:5f0e40fad7da
user: prevent deletion of users that are owners of a repo group
TODO: make it possible to reassign group ownership
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 06 Jan 2015 00:54:36 +0100 |
parents | 2982360d2547 |
children | 1a2e7a8d144c |
files | kallithea/model/db.py kallithea/model/user.py |
diffstat | 2 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/model/db.py Sun Jan 04 14:03:23 2015 +0200 +++ b/kallithea/model/db.py Tue Jan 06 00:54:36 2015 +0100 @@ -421,6 +421,7 @@ 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')
--- a/kallithea/model/user.py Sun Jan 04 14:03:23 2015 +0200 +++ b/kallithea/model/user.py Tue Jan 06 00:54:36 2015 +0100 @@ -258,10 +258,17 @@ 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