feat: Add SSO History for Support

This commit is contained in:
ansabgillani
2022-03-15 16:45:53 +05:00
committed by Ansab Gillani
parent 4119e60fa9
commit 4af3d58b39
8 changed files with 133 additions and 14 deletions

View File

@@ -0,0 +1,41 @@
# Generated by Django 3.2.12 on 2022-04-15 01:04
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import simple_history.models
import social_django.fields
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('third_party_auth', '0008_auto_20220324_1422'),
]
operations = [
migrations.CreateModel(
name='HistoricalUserSocialAuth',
fields=[
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('provider', models.CharField(max_length=32)),
('uid', models.CharField(db_index=True, max_length=255)),
('extra_data', social_django.fields.JSONField(default=dict)),
('created', models.DateTimeField(blank=True, editable=False)),
('modified', models.DateTimeField(blank=True, editable=False)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField()),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('user', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'historical user social auth',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': 'history_date',
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]

View File

@@ -9,6 +9,8 @@ import logging
import re
from config_models.models import ConfigurationModel, cache
from simple_history import register
from social_django.models import UserSocialAuth
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
@@ -37,6 +39,11 @@ REGISTRATION_FORM_FIELD_BLACKLIST = [
'username'
]
# Registers UserSocialAuth with simple-django-history.
# This registration makes third_party_auth a required app for Studio,
# even when it is supposed to be for LMS only.
register(UserSocialAuth, app=__package__)
# A dictionary of {name: class} entries for each python-social-auth backend available.
# Because this setting can specify arbitrary code to load and execute, it is set via