Skip to content
Snippets Groups Projects
Commit 41d9bfa0 authored by Douglas Hall's avatar Douglas Hall
Browse files

Merge pull request #17 from Harvard-University-iCommons/develop

Merging develop to master for 1.1.0 release
parents ea2125a4 b1092311
No related branches found
No related tags found
No related merge requests found
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
def is_allowed(request, allowed_roles, raise_exception):
# allowed_roles can either be a string (for just one)
# or a tuple or list (for several)
......@@ -14,9 +15,20 @@ def is_allowed(request, allowed_roles, raise_exception):
# the correct settings or is being run outside of an lti context
raise ImproperlyConfigured("No LTI_LAUNCH found in session")
user_roles = lti_launch.get('roles', [])
is_user_allowed = set(allowed) & set(user_roles)
is_user_allowed = set(allowed) & set(user_roles)
if not is_user_allowed and raise_exception:
raise PermissionDenied
return is_user_allowed
def has_lti_roles(request, roles):
# TODO: Refactor this common code here and above to keep it DRY
lti_launch = request.session.get('LTI_LAUNCH', None)
if not isinstance(lti_launch, dict):
# If this is raised, then likely the project doesn't have
# the correct settings or is being run outside of an lti context
raise ImproperlyConfigured("No LTI_LAUNCH found in session")
user_roles = lti_launch.get('roles', [])
return bool(set(user_roles) & set(roles))
......@@ -8,7 +8,7 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup(
name='django-auth-lti',
version='1.0',
version='1.1.0',
packages=['django_auth_lti'],
include_package_data=True,
license='TBD License', # example license
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment