1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 09:51:09 +03:00

Use process_response to attach user information later in the middleware request processing

This commit is contained in:
Matthew Jones 2013-11-11 14:05:51 -05:00
parent f1de300fd7
commit e1e70b37a5

View File

@ -3,11 +3,13 @@ from django.contrib.auth.models import User
from django.db.models.signals import pre_save
from django.utils.functional import curry
from awx.main.models.activity_stream import ActivityStream
import json
import urllib2
class ActivityStreamMiddleware(object):
def process_request(self, request):
self.isActivityStreamEvent = False
if hasattr(request, 'user') and hasattr(request.user, 'is_authenticated') and request.user.is_authenticated():
user = request.user
else:
@ -18,8 +20,20 @@ class ActivityStreamMiddleware(object):
def process_response(self, request, response):
pre_save.disconnect(dispatch_uid=(self.__class__, request))
if self.isActivityStreamEvent:
if "current_user" in request.COOKIES and "id" in request.COOKIES["current_user"]:
userInfo = json.loads(urllib2.unquote(request.COOKIES['current_user']).decode('utf8'))
userActual = User.objects.get(id=int(userInfo['id']))
self.instance.user = userActual
self.instance.save()
return response
def set_actor(self, user, sender, instance, **kwargs):
if sender == ActivityStream and isinstance(user, User) and instance.user is None:
instance.user = user
if sender == ActivityStream:
if isinstance(user, User) and instance.user is None:
instance.user = user
else:
self.isActivityStreamEvent = True
self.instance = instance
else:
self.isActivityStreamEvent = False