示例#1
0
    def dispatch(self, request, *args, **kwargs):
        if self.allowed_roles is None:
            raise ImproperlyConfigured(
                _("'LTIRoleRestrictionMixin' requires "
                  "'allowed_roles' attribute to be set."))

        if is_allowed(request, self.allowed_roles, self.raise_exception):
            return super().dispatch(request, *args, **kwargs)

        return redirect(self.redirect_url)
示例#2
0
        def _wrapped_view(request, *args, **kwargs):
            if is_allowed(request, allowed_roles, raise_exception):
                return view_func(request, *args, **kwargs)

            return redirect(redirect_url)
示例#3
0
 def test_is_allowed_failure_one_role(self):
     request = MagicMock(LTI={"roles": []})
     allowed_roles = "admin"
     user_is_allowed = is_allowed(request, allowed_roles, False)
     self.assertFalse(user_is_allowed)
示例#4
0
 def test_is_allowed_failure(self):
     request = MagicMock(LTI={"roles": []})
     allowed_roles = ["admin", "student"]
     user_is_allowed = is_allowed(request, allowed_roles, False)
     self.assertFalse(user_is_allowed)
示例#5
0
 def test_is_allowed_success_one_role(self):
     request = MagicMock(LTI={"roles": ["admin"]})
     allowed_roles = "admin"
     user_is_allowed = is_allowed(request, allowed_roles, False)
     self.assertTrue(user_is_allowed)
示例#6
0
 def test_is_allowed_success(self):
     request = MagicMock(LTI={"roles": ["admin"]})
     allowed_roles = ["admin", "student"]
     user_is_allowed = is_allowed(request, allowed_roles, False)
     self.assertTrue(user_is_allowed)