From ad1fd633b11e7a1ae36f331d3ec41cb6f416d953 Mon Sep 17 00:00:00 2001 From: Adarnof Date: Sat, 7 Apr 2018 20:59:00 -0400 Subject: [PATCH] Ensure autogroups are removed if new state has config --- allianceauth/eveonline/autogroups/models.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/allianceauth/eveonline/autogroups/models.py b/allianceauth/eveonline/autogroups/models.py index 7e7746c6..8f5bbe9e 100644 --- a/allianceauth/eveonline/autogroups/models.py +++ b/allianceauth/eveonline/autogroups/models.py @@ -38,14 +38,13 @@ class AutogroupsConfigManager(models.Manager): """ if state is None: state = user.profile.state - configs = self.filter(states=state) - if configs: - [config.update_group_membership_for_user(user) for config in configs] - else: - # No config for this user's state. Remove all managed groups. - for config in self.all(): - config.remove_user_from_alliance_groups(user) - config.remove_user_from_corp_groups(user) + for config in self.filter(states=state): + # grant user new groups for their state + config.update_group_membership_for_user(user) + for config in self.exclude(states=state): + # ensure user does not have groups from previous state + config.remove_user_from_alliance_groups(user) + config.remove_user_from_corp_groups(user) class AutogroupsConfig(models.Model):