diff --git a/allianceauth/__init__.py b/allianceauth/__init__.py index da2c8532..4fd57563 100644 --- a/allianceauth/__init__.py +++ b/allianceauth/__init__.py @@ -1,7 +1,7 @@ # This will make sure the app is always imported when # Django starts so that shared_task will use this app. -__version__ = '2.7.2' +__version__ = '2.7.3a2' __title__ = 'Alliance Auth' __url__ = 'https://gitlab.com/allianceauth/allianceauth' NAME = '%s v%s' % (__title__, __version__) diff --git a/allianceauth/authentication/backends.py b/allianceauth/authentication/backends.py index 2ef95401..f6fb2e0d 100644 --- a/allianceauth/authentication/backends.py +++ b/allianceauth/authentication/backends.py @@ -1,7 +1,8 @@ -from django.contrib.auth.backends import ModelBackend -from django.contrib.auth.models import Permission -from django.contrib.auth.models import User import logging + +from django.contrib.auth.backends import ModelBackend +from django.contrib.auth.models import User, Permission + from .models import UserProfile, CharacterOwnership, OwnershipRecord @@ -11,9 +12,11 @@ logger = logging.getLogger(__name__) class StateBackend(ModelBackend): @staticmethod def _get_state_permissions(user_obj): - profile_state_field = UserProfile._meta.get_field('state') - user_state_query = 'state__%s__user' % profile_state_field.related_query_name() - return Permission.objects.filter(**{user_state_query: user_obj}) + """returns permissions for state of given user object""" + if hasattr(user_obj, "profile") and user_obj.profile: + return Permission.objects.filter(state=user_obj.profile.state) + else: + return Permission.objects.none() def get_state_permissions(self, user_obj, obj=None): return self._get_permissions(user_obj, obj, 'state') diff --git a/allianceauth/authentication/models.py b/allianceauth/authentication/models.py index aa565219..c71721ef 100755 --- a/allianceauth/authentication/models.py +++ b/allianceauth/authentication/models.py @@ -73,11 +73,17 @@ class UserProfile(models.Model): if commit: logger.info('Updating {} state to {}'.format(self.user, self.state)) self.save(update_fields=['state']) - notify(self.user, _('State Changed'), - _('Your user state has been changed to %(state)s') % ({'state': state}), - 'info') + notify( + self.user, + _('State changed to: %s' % state), + _('Your user\'s state is now: %(state)s') + % ({'state': state}), + 'info' + ) from allianceauth.authentication.signals import state_changed - state_changed.send(sender=self.__class__, user=self.user, state=self.state) + state_changed.send( + sender=self.__class__, user=self.user, state=self.state + ) def __str__(self): return str(self.user) diff --git a/allianceauth/authentication/signals.py b/allianceauth/authentication/signals.py index 6f90cabc..2667ec8d 100644 --- a/allianceauth/authentication/signals.py +++ b/allianceauth/authentication/signals.py @@ -23,9 +23,7 @@ def trigger_state_check(state): check_states = State.objects.filter(priority__lt=state.priority) for profile in UserProfile.objects.filter(state__in=check_states): if state.available_to_user(profile.user): - profile.state = state - profile.save(update_fields=['state']) - state_changed.send(sender=state.__class__, user=profile.user, state=state) + profile.assign_state(state) @receiver(m2m_changed, sender=State.member_characters.through) diff --git a/allianceauth/authentication/templates/authentication/dashboard.html b/allianceauth/authentication/templates/authentication/dashboard.html index c7a0adbf..18f57d1f 100644 --- a/allianceauth/authentication/templates/authentication/dashboard.html +++ b/allianceauth/authentication/templates/authentication/dashboard.html @@ -14,7 +14,11 @@