0002-models-add-SessionIndex-model-41949.patch
mellon/migrations/0002_sessionindex.py | ||
---|---|---|
1 |
# Generated by Django 2.2.12 on 2020-04-24 05:14 |
|
2 | ||
3 |
from django.db import migrations, models |
|
4 |
import django.db.models.deletion |
|
5 | ||
6 | ||
7 |
class Migration(migrations.Migration): |
|
8 | ||
9 |
dependencies = [ |
|
10 |
('mellon', '0001_initial'), |
|
11 |
] |
|
12 | ||
13 |
operations = [ |
|
14 |
migrations.CreateModel( |
|
15 |
name='SessionIndex', |
|
16 |
fields=[ |
|
17 |
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|
18 |
('session_index', models.TextField(verbose_name='SAML SessionIndex')), |
|
19 |
('session_key', models.CharField(max_length=40, verbose_name='Django session key')), |
|
20 |
('saml_identifier', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mellon.UserSAMLIdentifier', verbose_name='SAML identifier')), |
|
21 |
], |
|
22 |
options={ |
|
23 |
'verbose_name': 'SAML SessionIndex', |
|
24 |
'verbose_name_plural': 'SAML SessionIndexes', |
|
25 |
'unique_together': {('saml_identifier', 'session_index', 'session_key')}, |
|
26 |
}, |
|
27 |
), |
|
28 |
] |
mellon/models.py | ||
---|---|---|
15 | 15 | |
16 | 16 |
from __future__ import unicode_literals |
17 | 17 | |
18 |
from importlib import import_module |
|
19 | ||
18 | 20 |
from django.db import models |
19 | 21 |
from django.utils.translation import ugettext_lazy as _ |
20 | 22 |
from django.conf import settings |
... | ... | |
38 | 40 |
verbose_name = _('user SAML identifier') |
39 | 41 |
verbose_name_plural = _('users SAML identifiers') |
40 | 42 |
unique_together = (('issuer', 'name_id'),) |
43 | ||
44 | ||
45 |
class SessionIndex(models.Model): |
|
46 |
session_index = models.TextField(_('SAML SessionIndex')) |
|
47 |
session_key = models.CharField(_('Django session key'), max_length=40) |
|
48 |
saml_identifier = models.ForeignKey( |
|
49 |
verbose_name=_('SAML identifier'), |
|
50 |
to=UserSAMLIdentifier, |
|
51 |
on_delete=models.CASCADE) |
|
52 | ||
53 |
@staticmethod |
|
54 |
def cleanup(cls): |
|
55 |
session_engine = import_module(settings.SESSION_ENGINE) |
|
56 |
store = session_engine.SessionStore() |
|
57 | ||
58 |
ids = [] |
|
59 |
for si in cls.objects.all(): |
|
60 |
if not store.exists(si.session_key): |
|
61 |
ids.append(si.id) |
|
62 |
cls.objects.filter(id__in=ids).delete() |
|
63 | ||
64 |
class Meta: |
|
65 |
verbose_name = _('SAML SessionIndex') |
|
66 |
verbose_name_plural = _('SAML SessionIndexes') |
|
67 |
unique_together = ( |
|
68 |
('saml_identifier', 'session_index', 'session_key'), |
|
69 |
) |
|
41 |
- |