Coverage for app/venv/lib/python3.14/site-packages/weblate/legal/pipeline.py: 0%

19 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 07:15 +0000

1# Copyright © Michal Čihař <michal@weblate.org> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4from __future__ import annotations 

5 

6from typing import TYPE_CHECKING 

7 

8from django.shortcuts import redirect 

9from django.urls import reverse 

10from django.utils.http import urlencode 

11from social_core.pipeline.partial import partial 

12 

13from weblate.legal.models import Agreement 

14 

15if TYPE_CHECKING: 

16 from weblate.auth.models import User 

17 

18 

19@partial 

20def tos_confirm(strategy, backend, user: User, current_partial, **kwargs): 

21 """Force authentication when adding new association.""" 

22 agreement = Agreement.objects.get_or_create(user=user)[0] 

23 if not agreement.is_current(): 

24 if user: 

25 strategy.request.session["tos_user"] = user.pk 

26 url = "{}?partial_token={}".format( 

27 reverse("social:complete", args=(backend.name,)), current_partial.token 

28 ) 

29 return redirect( 

30 "{}?{}".format(reverse("legal:confirm"), urlencode({"next": url})) 

31 ) 

32 strategy.request.session.pop("tos_user", None) 

33 return None