mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-12 14:00:17 +02:00
23 lines
736 B
Python
23 lines
736 B
Python
import logging
|
|
from django.dispatch import receiver
|
|
from allianceauth.authentication.signals import state_changed
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@receiver(state_changed)
|
|
def check_groups_on_state_change(sender, user, state, **kwargs):
|
|
logger.debug(
|
|
"Checking group memberships for %s based on new state %s" % (user, state)
|
|
)
|
|
state_groups = (
|
|
user.groups.select_related("authgroup").exclude(authgroup__states=None)
|
|
)
|
|
for group in state_groups:
|
|
if not group.authgroup.states.filter(id=state.id).exists():
|
|
logger.info(
|
|
"Removing user %s from group %s due to missing state" % (user, group)
|
|
)
|
|
user.groups.remove(group)
|