Skip to content

Commit

Permalink
Merge pull request #94 from Harvard-ATG/bugfix/launch-invalidation
Browse files Browse the repository at this point in the history
Fixes issue with launch invalidation
  • Loading branch information
arthurian authored Jul 7, 2017
2 parents 948d543 + 2e8dbba commit b167ae7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion annotationsx/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def _update_session(self, request):
max_launches = getattr(settings, 'LTI_MAX_LAUNCHES', 10)
self.logger.info("LTI launches in session: %s [max=%s]" % (lti_launches.keys(), max_launches))
if len(lti_launches.keys()) >= max_launches:
self.logger.info("Invalidating oldest LTI launch (FIFO)")
invalidated_launch = lti_launches.popitem(last=False)
self.logger.info("LTI launch invalidated: %s", json.dumps(invalidated_launch, indent=4))

Expand Down Expand Up @@ -355,4 +356,4 @@ def __contains__(self, item):

def __repr__(self):
self.assert_valid()
return repr(self.session['LTI_LAUNCH'][self.resource_link_id])
return repr(self.session['LTI_LAUNCH'][self.resource_link_id])
12 changes: 12 additions & 0 deletions annotationsx/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from collections import OrderedDict
import json

class JsonOrderedDictSerializer(object):
"""
Simple wrapper around JSON serializer that decodes dicts as ordered dicts.
"""
def dumps(self, obj):
return json.dumps(obj, separators=(',', ':')).encode('latin-1')

def loads(self, data):
return json.loads(data.decode('latin-1'), object_pairs_hook=OrderedDict)
5 changes: 5 additions & 0 deletions annotationsx/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@
SESSION_COOKIE_SECURE = True
SESSION_EXPIRE_AT_BROWSER_CLOSE = True

# Instead of using the default JSON serializer, we need to modify it slightly so that
# session dicts stored in JSON are de-serialized with their order preserved. This functionality
# is used in particular by the MultiLTILaunchMiddleware.
SESSION_SERIALIZER = 'annotationsx.serializers.JsonOrderedDictSerializer'

# Organization-specific configuration
# Try to minimize this as much as possible in favor of configuration
if ORGANIZATION == "ATG":
Expand Down

0 comments on commit b167ae7

Please sign in to comment.