From 32945250b6e3d207a000150adc9dc15f31c596fd Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 24 Nov 2018 22:26:28 +0100 Subject: [PATCH] Move skip_authorization to base Provider --- .../0002_application_skip_authorization.py | 18 ++++++++++++++++++ .../core/migrations/0003_auto_20181124_1031.py | 18 ++++++++++++++++++ passbook/core/models.py | 7 ++++++- passbook/saml_idp/migrations/0001_initial.py | 5 ++--- passbook/saml_idp/models.py | 1 - 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 passbook/core/migrations/0002_application_skip_authorization.py create mode 100644 passbook/core/migrations/0003_auto_20181124_1031.py diff --git a/passbook/core/migrations/0002_application_skip_authorization.py b/passbook/core/migrations/0002_application_skip_authorization.py new file mode 100644 index 000000000..d8b333a93 --- /dev/null +++ b/passbook/core/migrations/0002_application_skip_authorization.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.3 on 2018-11-24 09:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_core', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='application', + name='skip_authorization', + field=models.BooleanField(default=False), + ), + ] diff --git a/passbook/core/migrations/0003_auto_20181124_1031.py b/passbook/core/migrations/0003_auto_20181124_1031.py new file mode 100644 index 000000000..e88c740af --- /dev/null +++ b/passbook/core/migrations/0003_auto_20181124_1031.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.3 on 2018-11-24 10:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_core', '0002_application_skip_authorization'), + ] + + operations = [ + migrations.AlterField( + model_name='rulemodel', + name='rules', + field=models.ManyToManyField(blank=True, to='passbook_core.Rule'), + ), + ] diff --git a/passbook/core/models.py b/passbook/core/models.py index 26c21b33d..a5ea7697b 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -23,11 +23,15 @@ class Provider(models.Model): """Application-independent Provider instance. For example SAML2 Remote, OAuth2 Application""" # This class defines no field for easier inheritance + def __str__(self): + if hasattr(self, 'name'): + return getattr(self, 'name') + return super().__str__() class RuleModel(UUIDModel, CreatedUpdatedModel): """Base model which can have rules applied to it""" - rules = models.ManyToManyField('Rule') + rules = models.ManyToManyField('Rule', blank=True) def passes(self, user: User) -> bool: """Return true if user passes, otherwise False or raise Exception""" @@ -46,6 +50,7 @@ class Application(RuleModel): launch_url = models.URLField(null=True, blank=True) icon_url = models.TextField(null=True, blank=True) provider = models.ForeignKey('Provider', null=True, default=None, on_delete=models.SET_DEFAULT) + skip_authorization = models.BooleanField(default=False) objects = InheritanceManager() diff --git a/passbook/saml_idp/migrations/0001_initial.py b/passbook/saml_idp/migrations/0001_initial.py index e1ac8a9d8..a200e7593 100644 --- a/passbook/saml_idp/migrations/0001_initial.py +++ b/passbook/saml_idp/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.3 on 2018-11-22 10:03 +# Generated by Django 2.1.3 on 2018-11-24 09:48 import django.db.models.deletion from django.db import migrations, models @@ -9,7 +9,7 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('passbook_core', '0001_initial'), + ('passbook_core', '0002_application_skip_authorization'), ] operations = [ @@ -19,7 +19,6 @@ class Migration(migrations.Migration): ('application_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='passbook_core.Application')), ('acs_url', models.URLField()), ('processor_path', models.CharField(max_length=255)), - ('skip_authorization', models.BooleanField(default=False)), ], options={ 'abstract': False, diff --git a/passbook/saml_idp/models.py b/passbook/saml_idp/models.py index c13e4a55d..15b46d889 100644 --- a/passbook/saml_idp/models.py +++ b/passbook/saml_idp/models.py @@ -12,7 +12,6 @@ class SAMLApplication(Application): acs_url = models.URLField() processor_path = models.CharField(max_length=255, choices=[]) - skip_authorization = models.BooleanField(default=False) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)