Files
allianceauth/allianceauth/services/modules/smf/migrations/0002_service_permissions.py
Peter Pfeufer a6b340c179 update code to reflect the new minimum python version 3.7
- update string format method
- remove redundant default arguments from function  calls
- remove unused imports
- remove unicode identifier from strings, it's default in py3 (see: https://stackoverflow.com/a/4182635/12201331)
2021-10-18 11:59:05 +02:00

60 lines
2.0 KiB
Python

# Generated by Django 1.10.5 on 2017-02-02 05:59
from django.db import migrations
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth.management import create_permissions
import logging
logger = logging.getLogger(__name__)
def migrate_service_enabled(apps, schema_editor):
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, apps=apps, verbosity=0)
app_config.models_module = None
Group = apps.get_model("auth", "Group")
Permission = apps.get_model("auth", "Permission")
SmfUser = apps.get_model("smf", "SmfUser")
perm = Permission.objects.get(codename='access_smf')
member_group_name = getattr(settings, 'DEFAULT_AUTH_GROUP', 'Member')
blue_group_name = getattr(settings, 'DEFAULT_BLUE_GROUP', 'Blue')
# Migrate members
if SmfUser.objects.filter(user__groups__name=member_group_name).exists() or \
getattr(settings, 'ENABLE_AUTH_SMF', False):
try:
group = Group.objects.get(name=member_group_name)
group.permissions.add(perm)
except ObjectDoesNotExist:
logger.warning('Failed to migrate ENABLE_AUTH_SMF setting')
# Migrate blues
if SmfUser.objects.filter(user__groups__name=blue_group_name).exists() or \
getattr(settings, 'ENABLE_BLUE_SMF', False):
try:
group = Group.objects.get(name=blue_group_name)
group.permissions.add(perm)
except ObjectDoesNotExist:
logger.warning('Failed to migrate ENABLE_BLUE_SMF setting')
class Migration(migrations.Migration):
dependencies = [
('smf', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='smfuser',
options={'permissions': (('access_smf', 'Can access the SMF service'),)},
),
migrations.RunPython(migrate_service_enabled, migrations.RunPython.noop),
]