Improves error message on bad config; refactors common code

I'll muck around with the branches and get some tests in.

-Benjamin


On Wed, Jul 30, 2014 at 1:51 PM, Jaime Bermudez <notifications@github.com>
wrote:

> In django_auth_lti/verification.py:
>
> > @@ -0,0 +1,22 @@
> > +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)
> > +    if not isinstance(allowed_roles, (list, tuple)):
> > +        allowed = (allowed_roles, )
> > +    else:
> > +        allowed = allowed_roles
> > +
> > +    lti_params = request.session.get('LTI_LAUNCH', None)
> > +    if lti_params is None:
>
> Could you use hasattr(request.session, 'LTI_LAUNCH') here? If that's
> doable, then I think you could collapse the lines above into one if
> statement and have a one-liner below to get the roles like
> `request.session['LTI_LAUNCH']['roles']. Feel free to ignore the suggestion
> as it is just a style preference, but I thought I'd just offer up the
> possibility.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/Harvard-University-iCommons/django-auth-lti/pull/6/files#r15600295>
> .
>