• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iplweb / bpp / 18634744198

19 Oct 2025 07:00PM UTC coverage: 31.618% (-29.9%) from 61.514%
18634744198

push

github

mpasternak
Merge branch 'release/v202510.1270'

657 of 9430 branches covered (6.97%)

Branch coverage included in aggregate %.

229 of 523 new or added lines in 42 files covered. (43.79%)

11303 existing lines in 316 files now uncovered.

14765 of 39346 relevant lines covered (37.53%)

0.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/bpp_setup_wizard/middleware.py
UNCOV
1
from django.contrib.auth import get_user_model
×
UNCOV
2
from django.shortcuts import redirect
×
UNCOV
3
from django.urls import reverse
×
UNCOV
4
from django.utils.deprecation import MiddlewareMixin
×
5

UNCOV
6
from bpp.models import Uczelnia
×
7

UNCOV
8
BppUser = get_user_model()
×
9

10

UNCOV
11
class SetupWizardMiddleware(MiddlewareMixin):
×
12
    """
13
    Middleware to redirect to setup wizard when database is empty.
14
    Handles both user setup and uczelnia setup.
15
    """
16

UNCOV
17
    def process_request(self, request):
×
18
        # Skip middleware for static files and media files
UNCOV
19
        if request.path.startswith("/static/") or request.path.startswith("/media/"):
×
20
            return None
×
21

22
        # Skip if we're already on the setup wizard URLs
UNCOV
23
        if request.path.startswith("/setup/"):
×
UNCOV
24
            return None
×
25

26
        # Skip for admin URLs during setup (in case we need to access admin for debugging)
UNCOV
27
        if request.path.startswith("/admin/") and request.path != "/admin/":
×
28
            # Allow access to admin if users exist
29
            try:
×
30
                if BppUser.objects.exists():
×
31
                    return None
×
32
            except BaseException:
×
33
                # Database might not be migrated yet
34
                return None
×
35

36
        # Skip for migration-related URLs
UNCOV
37
        if any(path in request.path for path in ["migrate", "__debug__"]):
×
38
            return None
×
39

40
        # Skip for login/logout URLs
UNCOV
41
        if any(path in request.path for path in ["login", "logout", "accounts"]):
×
42
            return None
×
43

44
        # First check if any users exist
UNCOV
45
        try:
×
UNCOV
46
            needs_user_setup = not BppUser.objects.exists()
×
47
        except BaseException:
×
48
            # If there's an error (e.g., table doesn't exist), don't redirect
49
            # This allows migrations to run properly
50
            return None
×
51

UNCOV
52
        if needs_user_setup:
×
53
            # Redirect to user setup wizard
UNCOV
54
            setup_url = reverse("bpp_setup_wizard:setup")
×
UNCOV
55
            if request.path != setup_url:
×
UNCOV
56
                return redirect(setup_url)
×
57

58
        # If users exist, check if Uczelnia is configured
UNCOV
59
        try:
×
UNCOV
60
            needs_uczelnia_setup = not Uczelnia.objects.exists()
×
61
        except BaseException:
×
62
            # Table might not exist yet
63
            return None
×
64

UNCOV
65
        if needs_uczelnia_setup:
×
66
            # Only redirect authenticated superusers to Uczelnia setup
67
            # Check if request has user attribute (set by AuthenticationMiddleware)
UNCOV
68
            if (
×
69
                hasattr(request, "user")
70
                and request.user.is_authenticated
71
                and request.user.is_superuser
72
            ):
UNCOV
73
                uczelnia_url = reverse("bpp_setup_wizard:uczelnia_setup")
×
UNCOV
74
                if request.path != uczelnia_url:
×
UNCOV
75
                    return redirect(uczelnia_url)
×
76

77
        return None
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc