mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 12:30:15 +02:00
* Add service access permissions and migration `ENABLE_AUTH_<servicename> = True` will have the new permission applied to the settings configured `DEFAULT_AUTH_GROUP` group or `Member` if none is configured. `ENABLE_BLUE_<servicename> = True` will have the new permission applied to the settings configured `DEFAULT_BLUE_GROUP` group or `Blue` if none is configured. * Move views and hooks to permissions based access * Remove access restriction to services view Hypothetically non-member/blues could be granted permission to access services manually as desired now. A user that has no permissions to access any services will see a blank services list. * Remove obsolete service settings * Remove references to obsolete settings * Adjusted tests to support permissions based access * Fix incorrectly named permissions * Add simple get_services generator function * Added signals for user and groups perm changes * Update validate_services to support permissions deactivate_services removed as its surplus to requirements. * Removed state parameter from validate_services calls * Update tests to support signals changes * Fix incorrect call to validate_services task * Fix validate_services and test * Add validate_user to changed user groups signal * Added tests for new signals * Remove unnecessary post_add signals * Added documentation for service permissions * Added detection for members with service active If there are any service users in the Member or Blue groups active, then the permission will be added to the respective Member or Blue group. This means its no longer necessary to maintain the service enablesettings to migrate to permissions based service. Remove obsolete state based status checking
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
from __future__ import unicode_literals
|
|
from django.db.models.signals import pre_save, post_save
|
|
from django.dispatch import receiver
|
|
from django.contrib.auth.models import User
|
|
from authentication.models import AuthServicesInfo
|
|
from authentication.states import MEMBER_STATE, BLUE_STATE
|
|
from authentication.tasks import make_member, make_blue, disable_member
|
|
from services.tasks import validate_services
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@receiver(pre_save, sender=AuthServicesInfo)
|
|
def pre_save_auth_state(sender, instance, *args, **kwargs):
|
|
if instance.pk:
|
|
old_instance = AuthServicesInfo.objects.get(pk=instance.pk)
|
|
if old_instance.state != instance.state:
|
|
logger.debug('Detected state change for %s' % instance.user)
|
|
if instance.state == MEMBER_STATE:
|
|
make_member(instance)
|
|
elif instance.state == BLUE_STATE:
|
|
make_blue(instance)
|
|
else:
|
|
disable_member(instance.user)
|
|
validate_services.apply(args=(instance.user,))
|
|
|
|
|
|
@receiver(post_save, sender=User)
|
|
def post_save_user(sender, instance, created, *args, **kwargs):
|
|
# ensure all users have a model
|
|
if created:
|
|
AuthServicesInfo.objects.get_or_create(user=instance)
|
|
|