mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-10 04:50:16 +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
67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from __future__ import unicode_literals
|
|
from django.template.loader import render_to_string
|
|
from django.conf import settings
|
|
from notifications import notify
|
|
|
|
from alliance_auth import hooks
|
|
from services.hooks import ServicesHook
|
|
from .tasks import MumbleTasks
|
|
from .manager import MumbleManager
|
|
from .urls import urlpatterns
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class MumbleService(ServicesHook):
|
|
def __init__(self):
|
|
ServicesHook.__init__(self)
|
|
self.name = 'mumble'
|
|
self.urlpatterns = urlpatterns
|
|
self.service_url = settings.MUMBLE_URL
|
|
self.access_perm = 'mumble.access_mumble'
|
|
|
|
def delete_user(self, user, notify_user=False):
|
|
logging.debug("Deleting user %s %s account" % (user, self.name))
|
|
if MumbleManager.delete_user(user):
|
|
if notify_user:
|
|
notify(user, 'Mumble Account Disabled', level='danger')
|
|
return True
|
|
return False
|
|
|
|
def update_groups(self, user):
|
|
logger.debug("Updating %s groups for %s" % (self.name, user))
|
|
if MumbleTasks.has_account(user):
|
|
MumbleTasks.update_groups.delay(user.pk)
|
|
|
|
def validate_user(self, user):
|
|
if MumbleTasks.has_account(user) and not self.service_active_for_user(user):
|
|
self.delete_user(user, notify_user=True)
|
|
|
|
def update_all_groups(self):
|
|
logger.debug("Updating all %s groups" % self.name)
|
|
MumbleTasks.update_all_groups.delay()
|
|
|
|
def service_active_for_user(self, user):
|
|
return user.has_perm(self.access_perm)
|
|
|
|
def render_services_ctrl(self, request):
|
|
urls = self.Urls()
|
|
urls.auth_activate = 'auth_activate_mumble'
|
|
urls.auth_deactivate = 'auth_deactivate_mumble'
|
|
urls.auth_reset_password = 'auth_reset_mumble_password'
|
|
urls.auth_set_password = 'auth_set_mumble_password'
|
|
|
|
return render_to_string(self.service_ctrl_template, {
|
|
'service_name': self.title,
|
|
'urls': urls,
|
|
'service_url': self.service_url,
|
|
'username': request.user.mumble.username if MumbleTasks.has_account(request.user) else '',
|
|
}, request=request)
|
|
|
|
|
|
@hooks.register('services_hook')
|
|
def register_mumble_service():
|
|
return MumbleService()
|