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
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Generated by Django 1.10.5 on 2017-02-02 05:59
|
|
from __future__ import unicode_literals
|
|
|
|
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")
|
|
Phpbb3User = apps.get_model("phpbb3", "Phpbb3User")
|
|
|
|
perm = Permission.objects.get(codename='access_phpbb3')
|
|
|
|
member_group_name = getattr(settings, str('DEFAULT_AUTH_GROUP'), 'Member')
|
|
blue_group_name = getattr(settings, str('DEFAULT_BLUE_GROUP'), 'Blue')
|
|
|
|
# Migrate members
|
|
if Phpbb3User.objects.filter(user__groups__name=member_group_name).exists() or \
|
|
getattr(settings, str('ENABLE_AUTH_FORUM'), False):
|
|
try:
|
|
group = Group.objects.get(name=member_group_name)
|
|
group.permissions.add(perm)
|
|
except ObjectDoesNotExist:
|
|
logger.warning('Failed to migrate ENABLE_AUTH_FORUM setting')
|
|
|
|
# Migrate blues
|
|
if Phpbb3User.objects.filter(user__groups__name=blue_group_name).exists() or \
|
|
getattr(settings, str('ENABLE_BLUE_FORUM'), False):
|
|
try:
|
|
group = Group.objects.get(name=blue_group_name)
|
|
group.permissions.add(perm)
|
|
except ObjectDoesNotExist:
|
|
logger.warning('Failed to migrate ENABLE_BLUE_FORUM setting')
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('phpbb3', '0001_initial'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AlterModelOptions(
|
|
name='phpbb3user',
|
|
options={'permissions': (('access_phpbb3', 'Can access the phpBB3 service'),)},
|
|
),
|
|
migrations.RunPython(migrate_service_enabled),
|
|
]
|