Skip to content
Snippets Groups Projects
Commit 0146d8ef authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

TMSS-2601: bugfix, reduce log level

parent 31774a72
Branches
Tags
1 merge request!1122Resolve TMSS-2601
......@@ -66,13 +66,11 @@ class TMSSWebSocket(WebSocket):
self.user = token_obj.user
self.authenticated = True
logger.info('Client authenticated. User: %s from IP: %s' % (self.user, self.address[0]))
self.sendMessage(JSONdumps([u'Your websocket connection was successfully authenticated.']))
else:
logger.info('Client not authenticated. IP: %s' % (self.address[0]))
self.close(1011, u'Please login, so you have a token, and please submit the token in the 1st message after the connection was made.')
else:
logger.info('Client already authenticated, ignoring incoming message. User: %s from IP: %s' % (self.user, self.address[0]))
self.sendMessage(JSONdumps([u'Your websocket connection is already authenticated.']))
logger.debug('Client already authenticated, ignoring incoming message. User: %s from IP: %s' % (self.user, self.address[0]))
# NOTE: We just ignore incoming messages as we treat the communication as one-way only, except for the auth msg.
except Exception as e:
logger.exception('Error when handling websocket message of User: %s from IP: %s' % (self.user, self.address[0]))
......@@ -140,18 +138,18 @@ class TMSSEventMessageHandlerForWebsocket(TMSSEventMessageHandler):
from lofar.sas.tmss.tmss.tmssapp.models import ProjectRole
auth_clients = []
logger.info('Checking which of these users should receive websocket update for obj=%s: %s' % (obj, [ws.user for ws in list(self._ws_server.connections.values())]))
logger.debug('Checking which of these users should receive websocket update for obj=%s: %s' % (obj, [ws.user for ws in list(self._ws_server.connections.values())]))
for ws in list(self._ws_server.connections.values()):
if ws.authenticated: # Check user permissions for the object
user = User.objects.get(username=ws.user)
if user.is_superuser:
logger.info('User=%s is superuser and will receive websocket update for obj=%s' % (user, obj))
logger.debug('User=%s is superuser and will receive websocket update for obj=%s' % (user, obj))
auth_clients.append(ws)
elif user.has_perm("tmssapp.view_%s" % type(obj).__name__.lower()):
logger.info('User=%s has permission=%s and will receive websocket update for obj=%s' % (user, "tmssapp.view_%s" % type(obj).__name__.lower(), obj))
logger.debug('User=%s has permission=%s and will receive websocket update for obj=%s' % (user, "tmssapp.view_%s" % type(obj).__name__.lower(), obj))
auth_clients.append(ws)
else:
logger.info('User=%s has no permission=%s, checking for project-based permission to receive websocket update for obj=%s' % (user, "tmssapp.view_%s" % type(obj).__name__.lower(), obj))
logger.debug('User=%s has no permission=%s, checking for project-based permission to receive websocket update for obj=%s' % (user, "tmssapp.view_%s" % type(obj).__name__.lower(), obj))
# project-based permission
permitted_project_roles = get_project_roles_with_permission(type(obj).__name__.lower(), 'GET')
user_project_roles = get_project_roles_for_user(user)
......@@ -161,10 +159,10 @@ class TMSSEventMessageHandlerForWebsocket(TMSSEventMessageHandler):
if project_role['project'].lower() == related_project.name.lower() and \
ProjectRole.objects.get(value=project_role['role']) in permitted_project_roles:
auth_clients.append(ws)
logger.info("User=%s has project-based permission for project=%s and will receive websocket update for obj=%s" % (user, project_role['project'].lower(), obj))
logger.debug("User=%s has project-based permission for project=%s and will receive websocket update for obj=%s" % (user, project_role['project'].lower(), obj))
break
else:
logger.info("%s websocket is not authenticated and will not receive websocket update for obj=%s" % (ws.user, obj))
logger.debug("%s websocket is not authenticated and will not receive websocket update for obj=%s" % (ws.user, obj))
return auth_clients
def _broadcast_notify_to_clients_websocket(self, msg, clients):
......
......@@ -115,7 +115,6 @@ class TestSubtaskSchedulingService(unittest.TestCase):
cls.tmss_test_env.stop()
cls.tmp_exchange.close()
@unittest.skip('Skipped until TMSS-2601 is resolved and we do not send unexpected debug messages to the clients any more')
def test_01(self):
'''
This test starts a websocket service and tmss. Creates, updates and deletes objects to check if json_blobs from the ws service are properly received.
......
......@@ -70,11 +70,14 @@ def authentication_state(request):
if not request.user.is_authenticated:
return JsonResponse({'is_authenticated': False})
token_obj = Token.objects.filter(user=request.user).first()
token = token_obj.key if token_obj else None
return JsonResponse({'is_authenticated': True,
'username': request.user.username,
'email': request.user.email,
'id': request.user.id,
'websocket_token': Token.objects.filter(user=request.user).first()})
'websocket_token': token})
# Allow everybody to GET our publicly available template-json-schema's
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment