diff --git a/scim_app/core/migrations/0002_auto_20220118_1452.py b/scim_app/core/migrations/0002_auto_20220118_1452.py new file mode 100644 index 0000000..3e0842a --- /dev/null +++ b/scim_app/core/migrations/0002_auto_20220118_1452.py @@ -0,0 +1,37 @@ +# Generated by Django 3.2 on 2022-01-18 14:52 + +import django.contrib.auth.models +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ('core', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Group', + fields=[ + ('group_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='auth.group')), + ('scim_id', models.CharField(blank=True, default=None, help_text='A unique identifier for a SCIM resource as defined by the service provider.', max_length=254, null=True, unique=True, verbose_name='SCIM ID')), + ('scim_external_id', models.CharField(blank=True, db_index=True, default=None, help_text='A string that is an identifier for the resource as defined by the provisioning client.', max_length=254, null=True, verbose_name='SCIM External ID')), + ('scim_display_name', models.CharField(blank=True, db_index=True, default=None, help_text='A human-readable name for the Group.', max_length=254, null=True, verbose_name='SCIM Display Name')), + ], + options={ + 'abstract': False, + }, + bases=('auth.group', models.Model), + managers=[ + ('objects', django.contrib.auth.models.GroupManager()), + ], + ), + migrations.AlterField( + model_name='user', + name='groups', + field=models.ManyToManyField(to='core.Group'), + ), + ] diff --git a/scim_app/core/models.py b/scim_app/core/models.py index e471679..84e6f13 100644 --- a/scim_app/core/models.py +++ b/scim_app/core/models.py @@ -1,7 +1,19 @@ -from django.contrib.auth.models import AbstractUser +from django.contrib.auth.models import AbstractUser, Group from django.db import models -from django_scim.models import AbstractSCIMUserMixin +from django_scim.models import AbstractSCIMUserMixin, AbstractSCIMGroupMixin + +class Group(AbstractSCIMGroupMixin, Group): + def __str__(self) -> str: + return self.scim_display_name + class User(AbstractSCIMUserMixin, AbstractUser): - pass + groups = models.ManyToManyField(Group) + + @property + def scim_groups(self): + return self.groups + + def __str__(self) -> str: + return self.email