Coverage for apps/comments_views/journal/mixins.py: 93%

21 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2024-02-28 09:09 +0000

1from django.contrib.auth import REDIRECT_FIELD_NAME 

2from django.contrib.auth import logout 

3from django.http import HttpRequest 

4from django.http import HttpResponseRedirect 

5from django.urls import reverse 

6 

7from ptf.url_utils import format_url_with_params 

8 

9from ..core.mixins import AbstractCommentRightsMixin 

10from .models import OIDCUser 

11from .rights import OIDCUserRights 

12 

13 

14class OIDCCommentRightsMixin(AbstractCommentRightsMixin): 

15 @property 

16 def rights_class(self) -> type[OIDCUserRights]: 

17 return OIDCUserRights 

18 

19 

20class SSOLoginRequiredMixin: 

21 """ 

22 Redirects to the `remote_login` URL if the current user is not a `OIDCUser`. 

23 """ 

24 

25 def dispatch(self, request: HttpRequest, *args, **kwargs): 

26 if not isinstance(request.user, OIDCUser): 

27 redirect_uri = format_url_with_params( 

28 reverse("remote_login"), {REDIRECT_FIELD_NAME: request.build_absolute_uri()} 

29 ) 

30 if request.user.is_authenticated: 30 ↛ 31line 30 didn't jump to line 31, because the condition on line 30 was never true

31 logout(request) 

32 return HttpResponseRedirect(redirect_uri) 

33 

34 return super().dispatch(request, *args, **kwargs) # type:ignore