mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 20:40:17 +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
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
from __future__ import unicode_literals
|
|
|
|
import logging
|
|
|
|
from alliance_auth.celeryapp import app
|
|
from django.conf import settings
|
|
from django.contrib.auth.models import User
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
from notifications import notify
|
|
|
|
from .manager import SmfManager
|
|
from .models import SmfUser
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class SmfTasks:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def delete_user(cls, user, notify_user=False):
|
|
if cls.has_account(user):
|
|
logger.debug("User %s has a SMF account %s. Deleting." % (user, user.smf.username))
|
|
SmfManager.disable_user(user.smf.username)
|
|
user.smf.delete()
|
|
if notify_user:
|
|
notify(user, "SMF Account Disabled", level='danger')
|
|
return True
|
|
return False
|
|
|
|
@staticmethod
|
|
def has_account(user):
|
|
try:
|
|
return user.smf.username != ''
|
|
except ObjectDoesNotExist:
|
|
return False
|
|
|
|
@classmethod
|
|
def disable(cls):
|
|
SmfUser.objects.all().delete()
|
|
|
|
@staticmethod
|
|
@app.task(bind=True, name="smf.update_groups")
|
|
def update_groups(self, pk):
|
|
user = User.objects.get(pk=pk)
|
|
logger.debug("Updating smf groups for user %s" % user)
|
|
if SmfTasks.has_account(user):
|
|
groups = []
|
|
for group in user.groups.all():
|
|
groups.append(str(group.name))
|
|
if len(groups) == 0:
|
|
groups.append('empty')
|
|
logger.debug("Updating user %s smf groups to %s" % (user, groups))
|
|
try:
|
|
SmfManager.update_groups(user.smf.username, groups)
|
|
except:
|
|
logger.exception("smf group sync failed for %s, retrying in 10 mins" % user)
|
|
raise self.retry(countdown=60 * 10)
|
|
logger.debug("Updated user %s smf groups." % user)
|
|
else:
|
|
logger.debug("User does not have an smf account")
|
|
|
|
@staticmethod
|
|
@app.task(name="smf.update_all_groups")
|
|
def update_all_groups():
|
|
logger.debug("Updating ALL smf groups")
|
|
for user in SmfUser.objects.exclude(username__exact=''):
|
|
SmfTasks.update_groups.delay(user.user_id)
|