Coverage for distro_tracker/signon/models.py: 100%
13 statements
« prev ^ index » next coverage.py v6.5.0, created at 2025-01-12 09:15 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2025-01-12 09:15 +0000
1# Copyright 2019, 2021-2024 The Debusine Developers
2# See the COPYRIGHT file at the top-level directory of this distribution
3#
4# This file is part of Distro Tracker. It is subject to the license terms
5# in the LICENSE file found in the top-level directory of this
6# distribution and at https://deb.li/DTLicense. No part of Distro Tracker,
7# including this file, may be copied, modified, propagated, or distributed
8# except according to the terms contained in the LICENSE file.
10from django.db import models
11from django.db.models import UniqueConstraint
12from django.conf import settings
15class Identity(models.Model):
16 """
17 Identity for a user in a remote user database.
19 An Identity is bound if it's associated with a Django user, or unbound if
20 no Django user is known for it.
21 """
23 class Meta:
24 constraints = [
25 UniqueConstraint(
26 fields=["issuer", "subject"],
27 name="%(app_label)s_%(class)s_unique_issuer_subject",
28 ),
29 ]
31 user = models.ForeignKey(
32 settings.AUTH_USER_MODEL,
33 related_name="identities",
34 null=True,
35 on_delete=models.SET_NULL,
36 )
37 issuer = models.CharField(
38 max_length=512,
39 help_text="identifier of auhoritative system for this identity",
40 )
41 subject = models.CharField(
42 max_length=512,
43 help_text="identifier of the user in the issuer system",
44 )
45 last_used = models.DateTimeField(
46 auto_now=True, help_text="last time this identity has been used"
47 )
48 claims = models.JSONField(default=dict)
50 def __str__(self) -> str:
51 """Return str for the object."""
52 return f"{self.issuer}:{self.subject}"