A minimal Clipper model for clipper metadata
This commit is contained in:
commit
1b1049a73f
6 changed files with 107 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
__pycache__
|
||||
/venv
|
0
authens/__init__.py
Normal file
0
authens/__init__.py
Normal file
5
authens/apps.py
Normal file
5
authens/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AuthEnsConfig(AppConfig):
|
||||
name = "authens"
|
56
authens/migrations/0001_initial.py
Normal file
56
authens/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
# Generated by Django 3.0.6 on 2020-05-10 19:14
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Clipper",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"uid",
|
||||
models.CharField(
|
||||
max_length=1023, unique=True, verbose_name="login clipper"
|
||||
),
|
||||
),
|
||||
(
|
||||
"entrance_year",
|
||||
models.SmallIntegerField(
|
||||
verbose_name="année de création du compte clipper"
|
||||
),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.OneToOneField(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="clipper",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
verbose_name="utilisateurice",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "Compte clipper",
|
||||
"verbose_name_plural": "Comptes clipper",
|
||||
},
|
||||
),
|
||||
]
|
0
authens/migrations/__init__.py
Normal file
0
authens/migrations/__init__.py
Normal file
44
authens/models.py
Normal file
44
authens/models.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class Clipper(models.Model):
|
||||
"""Information about clipper accounts.
|
||||
|
||||
A user is given an instance of this model iff it has a clipper account. The `uid`
|
||||
field is the clipper login and is used for CAS authentication.
|
||||
|
||||
At each connection, we check that the `entrance_year` we have is consistent with the
|
||||
meta-data returned by the SPI's CAS.
|
||||
- if both entrance years match, we connect `self.user`
|
||||
- if not, we consider that this account is old and assume a new clipper account with
|
||||
the same id has been created. We remove this instance and create a new user
|
||||
associated with a new Clipper account.
|
||||
"""
|
||||
|
||||
user = models.OneToOneField(
|
||||
User,
|
||||
verbose_name=_("utilisateurice"),
|
||||
on_delete=models.CASCADE,
|
||||
related_name="clipper",
|
||||
)
|
||||
uid = models.CharField(
|
||||
verbose_name=_("login clipper"), max_length=1023, blank=False, unique=True,
|
||||
)
|
||||
entrance_year = models.SmallIntegerField(
|
||||
verbose_name=_("année de création du compte clipper"), blank=False, null=False
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Compte clipper")
|
||||
verbose_name_plural = _("Comptes clipper")
|
||||
|
||||
def __str__(self):
|
||||
return _("compte clipper %(uid)s@%(entrance_year)s lié à %(user)s") % {
|
||||
"uid": self.uid,
|
||||
"entrance_year": self.entrance_year,
|
||||
"user": self.user.username,
|
||||
}
|
Loading…
Reference in a new issue