mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 03:17:38 -02:30
session limit invalidation events via socket.io
This commit is contained in:
@@ -64,6 +64,7 @@ from awx.api.permissions import * # noqa
|
||||
from awx.api.renderers import * # noqa
|
||||
from awx.api.serializers import * # noqa
|
||||
from awx.fact.models import * # noqa
|
||||
from awx.main.utils import emit_websocket_notification
|
||||
|
||||
def api_exception_handler(exc):
|
||||
'''
|
||||
@@ -528,16 +529,20 @@ class AuthTokenView(APIView):
|
||||
reason='')[0]
|
||||
token.refresh()
|
||||
except IndexError:
|
||||
token = AuthToken.objects.create(user=serializer.object['user'],
|
||||
request_hash=request_hash)
|
||||
# Get user un-expired tokens that are not invalidated that are
|
||||
# over the configured limit.
|
||||
# Mark them as invalid and inform the user
|
||||
invalid_tokens = AuthToken.get_tokens_over_limit(serializer.object['user'])
|
||||
for t in invalid_tokens:
|
||||
# TODO: send socket notification
|
||||
emit_websocket_notification('/socket.io/control',
|
||||
'limit_reached',
|
||||
dict(reason=unicode(AuthToken.reason_long('limit_reached'))),
|
||||
token_key=t.key)
|
||||
t.invalidate(reason='limit_reached')
|
||||
|
||||
token = AuthToken.objects.create(user=serializer.object['user'],
|
||||
request_hash=request_hash)
|
||||
return Response({'token': token.key, 'expires': token.expires})
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user