Coverage for src/comments_views/journal/mixins.py: 91%

19 statements  

« prev     ^ index     » next       coverage.py v7.7.0, created at 2025-04-09 14:49 +0000

1from django.contrib.auth import REDIRECT_FIELD_NAME, logout 

2from django.http import HttpRequest, HttpResponseRedirect 

3from django.urls import reverse 

4from ptf.url_utils import format_url_with_params 

5 

6from ..core.mixins import AbstractCommentRightsMixin 

7from .models import OIDCUser 

8from .rights import OIDCUserRights 

9 

10 

11class OIDCCommentRightsMixin(AbstractCommentRightsMixin): 

12 @property 

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

14 return OIDCUserRights 

15 

16 

17class SSOLoginRequiredMixin: 

18 """ 

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

20 """ 

21 

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

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

24 redirect_uri = format_url_with_params( 

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

26 ) 

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

28 logout(request) 

29 return HttpResponseRedirect(redirect_uri) 

30 

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