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

Fix issue AC=731, make sure we initialize some of the Activity Stream information in the middleware __init__ since process_request may not be called during the request phase

This commit is contained in:
Matthew Jones 2013-11-25 09:36:38 -05:00
parent 54ec61f2b7
commit 9038784bb6

View File

@ -13,8 +13,12 @@ logger = logging.getLogger('awx.main.middleware')
class ActivityStreamMiddleware(object): class ActivityStreamMiddleware(object):
def process_request(self, request): def __init__(self):
self.disp_uid = None
self.isActivityStreamEvent = False self.isActivityStreamEvent = False
self.finished = False
def process_request(self, request):
if hasattr(request, 'user') and hasattr(request.user, 'is_authenticated') and request.user.is_authenticated(): if hasattr(request, 'user') and hasattr(request.user, 'is_authenticated') and request.user.is_authenticated():
user = request.user user = request.user
else: else:
@ -23,12 +27,12 @@ class ActivityStreamMiddleware(object):
self.instances = [] self.instances = []
set_actor = curry(self.set_actor, user) set_actor = curry(self.set_actor, user)
self.disp_uid = str(uuid.uuid1()) self.disp_uid = str(uuid.uuid1())
self.finished = False
post_save.connect(set_actor, sender=ActivityStream, dispatch_uid=self.disp_uid, weak=False) post_save.connect(set_actor, sender=ActivityStream, dispatch_uid=self.disp_uid, weak=False)
def process_response(self, request, response): def process_response(self, request, response):
drf_request = getattr(request, 'drf_request', None) drf_request = getattr(request, 'drf_request', None)
drf_user = getattr(drf_request, 'user', None) drf_user = getattr(drf_request, 'user', None)
if self.disp_uid is not None:
post_save.disconnect(dispatch_uid=self.disp_uid) post_save.disconnect(dispatch_uid=self.disp_uid)
self.finished = True self.finished = True
if self.isActivityStreamEvent: if self.isActivityStreamEvent:
@ -61,5 +65,3 @@ class ActivityStreamMiddleware(object):
if instance.id not in self.instances: if instance.id not in self.instances:
self.isActivityStreamEvent = True self.isActivityStreamEvent = True
self.instances.append(instance.id) self.instances.append(instance.id)
else:
self.isActivityStreamEvent = False