mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-12 05:50:16 +02:00
Correct discourse login for non-superusers.
Correct TS3 error handling. Closes #554
This commit is contained in:
parent
4ff21b25c3
commit
5ee65706cb
@ -40,10 +40,15 @@ class Teamspeak3Manager:
|
|||||||
def _get_userid(uid):
|
def _get_userid(uid):
|
||||||
logger.debug("Looking for uid %s on TS3 server." % uid)
|
logger.debug("Looking for uid %s on TS3 server." % uid)
|
||||||
server = Teamspeak3Manager.__get_created_server()
|
server = Teamspeak3Manager.__get_created_server()
|
||||||
|
try:
|
||||||
ret = server.send_command('customsearch', {'ident': 'sso_uid', 'pattern': uid})
|
ret = server.send_command('customsearch', {'ident': 'sso_uid', 'pattern': uid})
|
||||||
if ret and 'keys' in ret and 'cldbid' in ret['keys']:
|
if ret and 'keys' in ret and 'cldbid' in ret['keys']:
|
||||||
logger.debug("Got userid %s for uid %s" % (ret['keys']['cldbid'], uid))
|
logger.debug("Got userid %s for uid %s" % (ret['keys']['cldbid'], uid))
|
||||||
return ret['keys']['cldbid']
|
return ret['keys']['cldbid']
|
||||||
|
except TeamspeakError as e:
|
||||||
|
if not e.code == '1281':
|
||||||
|
raise e
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _group_id_by_name(groupname):
|
def _group_id_by_name(groupname):
|
||||||
@ -85,7 +90,13 @@ class Teamspeak3Manager:
|
|||||||
def _user_group_list(cldbid):
|
def _user_group_list(cldbid):
|
||||||
logger.debug("Retrieving group list for user with id %s" % cldbid)
|
logger.debug("Retrieving group list for user with id %s" % cldbid)
|
||||||
server = Teamspeak3Manager.__get_created_server()
|
server = Teamspeak3Manager.__get_created_server()
|
||||||
|
try:
|
||||||
groups = server.send_command('servergroupsbyclientid', {'cldbid': cldbid})
|
groups = server.send_command('servergroupsbyclientid', {'cldbid': cldbid})
|
||||||
|
except TeamspeakError as e:
|
||||||
|
if e.code == '1281': # no groups
|
||||||
|
groups = []
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
logger.debug("Retrieved group list: %s" % groups)
|
logger.debug("Retrieved group list: %s" % groups)
|
||||||
outlist = {}
|
outlist = {}
|
||||||
|
|
||||||
@ -231,7 +242,10 @@ class Teamspeak3Manager:
|
|||||||
user = Teamspeak3Manager._get_userid(uid)
|
user = Teamspeak3Manager._get_userid(uid)
|
||||||
logger.debug("Deleting user %s with id %s from TS3 server." % (user, uid))
|
logger.debug("Deleting user %s with id %s from TS3 server." % (user, uid))
|
||||||
if user:
|
if user:
|
||||||
for client in server.send_command('clientlist'):
|
clients = server.send_command('clientlist')
|
||||||
|
logger.debug(clients['keys'])
|
||||||
|
if clients['keys']:
|
||||||
|
for client in clients:
|
||||||
try:
|
try:
|
||||||
if client['keys']['client_database_id'] == user:
|
if client['keys']['client_database_id'] == user:
|
||||||
logger.debug("Found user %s on TS3 server - issuing deletion command." % user)
|
logger.debug("Found user %s on TS3 server - issuing deletion command." % user)
|
||||||
@ -253,6 +267,9 @@ class Teamspeak3Manager:
|
|||||||
else:
|
else:
|
||||||
logger.exception("Failed to delete user id %s from TS3 - received response %s" % (uid, ret))
|
logger.exception("Failed to delete user id %s from TS3 - received response %s" % (uid, ret))
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
logger.warning('Received no clients from TS3 server. Assuming user %s already deleted.' % uid)
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
logger.warn("User with id %s not found on TS3 server. Assuming succesful deletion." % uid)
|
logger.warn("User with id %s not found on TS3 server. Assuming succesful deletion." % uid)
|
||||||
return True
|
return True
|
||||||
|
@ -36,7 +36,7 @@ from services.forms import FleetFormatterForm
|
|||||||
from services.forms import ServicePasswordForm
|
from services.forms import ServicePasswordForm
|
||||||
from services.forms import TeamspeakJoinForm
|
from services.forms import TeamspeakJoinForm
|
||||||
from authentication.decorators import members_and_blues
|
from authentication.decorators import members_and_blues
|
||||||
from authentication.states import MEMBER_STATE, BLUE_STATE
|
from authentication.states import MEMBER_STATE, BLUE_STATE, NONE_STATE
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import hmac
|
import hmac
|
||||||
@ -1132,13 +1132,13 @@ def discourse_sso(request):
|
|||||||
|
|
||||||
auth, c = AuthServicesInfo.objects.get_or_create(user=request.user)
|
auth, c = AuthServicesInfo.objects.get_or_create(user=request.user)
|
||||||
if not request.user.is_superuser:
|
if not request.user.is_superuser:
|
||||||
if auth.state == MEMBER_STATE and not settings.ENABLE_AUTH_DISCOURSE:
|
if not settings.ENABLE_AUTH_DISCOURSE and auth.state == MEMBER_STATE:
|
||||||
messages.error(request, 'You are not authorized to access Discourse.')
|
messages.error(request, 'Members are not authorized to access Discourse.')
|
||||||
return redirect('auth_dashboard')
|
return redirect('auth_dashboard')
|
||||||
elif auth.state == BLUE_STATE and not settings.ENABLE_BLUE_DISCOURSE:
|
elif not settings.ENABLE_BLUE_DISCOURSE and auth.state == BLUE_STATE:
|
||||||
messages.error(request, 'You are not authorized to access Discourse.')
|
messages.error(request, 'Blues are not authorized to access Discourse.')
|
||||||
return redirect('auth_dashboard')
|
return redirect('auth_dashboard')
|
||||||
else:
|
elif auth.state == NONE_STATE:
|
||||||
messages.error(request, 'You are not authorized to access Discourse.')
|
messages.error(request, 'You are not authorized to access Discourse.')
|
||||||
return redirect('auth_dashboard')
|
return redirect('auth_dashboard')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user