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

iplweb / bpp / 851809f0-9849-4611-a43d-17c345104d20

18 Feb 2025 12:47AM UTC coverage: 47.247% (-0.01%) from 47.257%
851809f0-9849-4611-a43d-17c345104d20

push

circleci

mpasternak
Merge tag 'v202502.1157' into dev

Nowa wersja: v202502.1157 v202502.1157

1 of 1 new or added line in 1 file covered. (100.0%)

279 existing lines in 11 files now uncovered.

16739 of 35429 relevant lines covered (47.25%)

1.21 hits per line

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

64.58
src/bpp/models/profile.py
1
"""
2
Profile użytkowników serwisu BPP
3
"""
4

5
from datetime import timedelta
3✔
6

7
from django.conf import settings
3✔
8
from django.db import models
3✔
9
from django.dispatch import receiver
3✔
10

11
from django.contrib.auth.models import AbstractUser, UserManager
3✔
12

13
from django.utils import timezone
3✔
14
from django.utils.functional import cached_property
3✔
15
from django.utils.itercompat import is_iterable
3✔
16

17
from bpp.const import PUSTY_ADRES_EMAIL
3✔
18
from bpp.models import ModelZAdnotacjami
3✔
19

20

21
class BppUserManager(UserManager):
3✔
22
    model = "bpp.BppUser"
3✔
23

24

25
class BppUser(AbstractUser, ModelZAdnotacjami):
3✔
26
    active_charmap_tab = models.IntegerField(default=0)
3✔
27

28
    per_page = models.IntegerField(
3✔
29
        "Ilość wyświetlanych rekordów na stronie", default=20
30
    )
31

32
    multiseek_format = models.CharField(
3✔
33
        "Ostatnio wybrany format wyświetlania w Multiseeku",
34
        max_length=200,
35
        null=True,
36
        blank=True,
37
    )
38

39
    multiseek_order_1 = models.CharField(
3✔
40
        "Ostatnio wybrane pole sortowania w Multiseeku",
41
        max_length=200,
42
        null=True,
43
        blank=True,
44
    )
45

46
    pbn_token = models.CharField(max_length=128, null=True, blank=True)
3✔
47
    pbn_token_updated = models.DateTimeField(null=True, blank=True)
3✔
48

49
    def pbn_token_possibly_valid(self):
3✔
UNCOV
50
        if (
2✔
51
            self.pbn_token is None
52
            or not self.pbn_token
53
            or self.pbn_token_updated is None
54
        ):
UNCOV
55
            return False
2✔
56

UNCOV
57
        delta = timezone.now() - self.pbn_token_updated
×
UNCOV
58
        if delta > timedelta(hours=6):
×
UNCOV
59
            return False
×
60

UNCOV
61
        return True
×
62

63
    class Meta:
3✔
64
        app_label = "bpp"
3✔
65
        verbose_name = "użytkownik"
3✔
66
        verbose_name_plural = "użytkownicy"
3✔
67

68
    objects = BppUserManager()
3✔
69

70
    @cached_property
3✔
71
    def cached_groups(self):
3✔
72
        return self.groups.all()
2✔
73

74

75
# Uzupełnianie pól użytkownika na bazie LDAP:
76

77
if getattr(settings, "AUTH_LDAP_SERVER_URI", None):
3✔
78
    from django_auth_ldap.backend import populate_user
×
79

80
    @receiver(populate_user)
×
UNCOV
81
    def populate_bppuser(user, ldap_user, **kwargs):
×
82
        # Populate the Django user from the LDAP directory.
83

84
        AUTH_LDAP_USER_ATTR_MAP = {
×
85
            "first_name": ("givenName", "BrakImieniaWActiveDirectory"),
86
            "last_name": ("sn", "BrakNazwiskaWActiveDirectory"),
87
            "email": ("mail", PUSTY_ADRES_EMAIL),
88
        }
89

UNCOV
90
        for attr, value in AUTH_LDAP_USER_ATTR_MAP.items():
×
UNCOV
91
            ldap_attr, default = value
×
UNCOV
92
            ldap_value = ldap_user.attrs.get(ldap_attr, value)
×
93

UNCOV
94
            if is_iterable(ldap_value):
×
UNCOV
95
                ldap_value = " ".join([str(x) for x in ldap_value])
×
UNCOV
96
            setattr(user, attr, ldap_value)
×
97

UNCOV
98
        user.is_active = True
×
99

100
        # Zresetuj uprawnienia superużytkownika i 'w zespole' dla użytkowników
101
        # autoryzujących się po LDAP:
UNCOV
102
        user.is_superuser = False
×
UNCOV
103
        user.is_staff = False
×
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