Coverage for src/comments_views/journal/models.py: 100%
17 statements
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-09 14:49 +0000
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-09 14:49 +0000
1from django.contrib.auth.models import User
4class OIDCUser(User):
5 """
6 Custom User class for OIDC authenticated users.
7 This Model is not to be stored in DB.
8 The class is used to: \\
9 1. Distinguish OIDC users from "normal" users. \\
10 2. Store the OIDC metadata properly in an user object so that \
11 it's accessible just like a regular authenticated User.
12 """
14 name: str = ""
15 provider: str = ""
16 provider_uid: str = ""
17 claims = {}
19 class Meta:
20 # Prevent the database table creation
21 managed = False
23 def save(self, *args, **kwargs):
24 """Override default save to do nothing"""
26 def populate_fields(self, claims: dict) -> None:
27 """Fill the user object with the claims coming from the OP."""
28 for key, value in claims.items():
29 if hasattr(self, key):
30 setattr(self, key, value)
31 self.username = claims["email"]
32 self.claims = {**claims}
34 def get_user_id(self) -> int:
35 return int(self.claims["sub"])