diff --git a/passbook/admin/views/providers.py b/passbook/admin/views/providers.py index fd4de6ac6..fc85cd098 100644 --- a/passbook/admin/views/providers.py +++ b/passbook/admin/views/providers.py @@ -33,7 +33,7 @@ class ProviderListView( permission_required = "passbook_core.add_provider" template_name = "administration/provider/list.html" ordering = "id" - search_fields = ["id"] + search_fields = ["id", "name"] class ProviderCreateView( diff --git a/passbook/core/api/providers.py b/passbook/core/api/providers.py index c2830c06e..4b493dcac 100644 --- a/passbook/core/api/providers.py +++ b/passbook/core/api/providers.py @@ -17,7 +17,7 @@ class ProviderSerializer(ModelSerializer): class Meta: model = Provider - fields = ["pk", "authorization_flow", "property_mappings", "__type__"] + fields = ["pk", "name", "authorization_flow", "property_mappings", "__type__"] class ProviderViewSet(ReadOnlyModelViewSet): diff --git a/passbook/core/migrations/0011_provider_name_temp.py b/passbook/core/migrations/0011_provider_name_temp.py new file mode 100644 index 000000000..932029f79 --- /dev/null +++ b/passbook/core/migrations/0011_provider_name_temp.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.2 on 2020-10-03 17:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_core", "0010_auto_20200917_1021"), + ] + + operations = [ + migrations.AddField( + model_name="provider", + name="name_temp", + field=models.TextField(default=""), + preserve_default=False, + ), + ] diff --git a/passbook/core/migrations/0012_auto_20201003_1737.py b/passbook/core/migrations/0012_auto_20201003_1737.py new file mode 100644 index 000000000..180dae627 --- /dev/null +++ b/passbook/core/migrations/0012_auto_20201003_1737.py @@ -0,0 +1,20 @@ +# Generated by Django 3.1.2 on 2020-10-03 17:37 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_core", "0011_provider_name_temp"), + ("passbook_providers_oauth2", "0006_remove_oauth2provider_name"), + ("passbook_providers_saml", "0006_remove_samlprovider_name"), + ] + + operations = [ + migrations.RenameField( + model_name="provider", + old_name="name_temp", + new_name="name", + ), + ] diff --git a/passbook/core/models.py b/passbook/core/models.py index 866c80539..02f5323c4 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -124,6 +124,8 @@ class User(GuardianUserMixin, AbstractUser): class Provider(models.Model): """Application-independent Provider instance. For example SAML2 Remote, OAuth2 Application""" + name = models.TextField() + authorization_flow = models.ForeignKey( Flow, on_delete=models.CASCADE, @@ -148,11 +150,8 @@ class Provider(models.Model): """Return Form class used to edit this object""" raise NotImplementedError - # This class defines no field for easier inheritance def __str__(self): - if hasattr(self, "name"): - return getattr(self, "name") - return super().__str__() + return self.name class Application(PolicyBindingModel): diff --git a/passbook/providers/oauth2/migrations/0006_remove_oauth2provider_name.py b/passbook/providers/oauth2/migrations/0006_remove_oauth2provider_name.py new file mode 100644 index 000000000..3c67a491d --- /dev/null +++ b/passbook/providers/oauth2/migrations/0006_remove_oauth2provider_name.py @@ -0,0 +1,30 @@ +# Generated by Django 3.1.2 on 2020-10-03 17:37 + +from django.apps.registry import Apps +from django.db import migrations +from django.db.backends.base.schema import BaseDatabaseSchemaEditor + + +def update_name_temp(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): + OAuth2Provider = apps.get_model("passbook_providers_oauth2", "OAuth2Provider") + db_alias = schema_editor.connection.alias + + for provider in OAuth2Provider.objects.using(db_alias).all(): + provider.name_temp = provider.name + provider.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_core", "0011_provider_name_temp"), + ("passbook_providers_oauth2", "0005_auto_20200920_1240"), + ] + + operations = [ + migrations.RunPython(update_name_temp), + migrations.RemoveField( + model_name="oauth2provider", + name="name", + ), + ] diff --git a/passbook/providers/oauth2/models.py b/passbook/providers/oauth2/models.py index 3078dcf0e..96004dac8 100644 --- a/passbook/providers/oauth2/models.py +++ b/passbook/providers/oauth2/models.py @@ -120,8 +120,6 @@ class ScopeMapping(PropertyMapping): class OAuth2Provider(Provider): """OAuth2 Provider for generic OAuth and OpenID Connect Applications.""" - name = models.TextField() - client_type = models.CharField( max_length=30, choices=ClientTypes.choices, diff --git a/passbook/providers/saml/migrations/0006_remove_samlprovider_name.py b/passbook/providers/saml/migrations/0006_remove_samlprovider_name.py new file mode 100644 index 000000000..71c7b7c54 --- /dev/null +++ b/passbook/providers/saml/migrations/0006_remove_samlprovider_name.py @@ -0,0 +1,30 @@ +# Generated by Django 3.1.2 on 2020-10-03 17:37 + +from django.apps.registry import Apps +from django.db import migrations +from django.db.backends.base.schema import BaseDatabaseSchemaEditor + + +def update_name_temp(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): + SAMLProvider = apps.get_model("passbook_providers_saml", "SAMLProvider") + db_alias = schema_editor.connection.alias + + for provider in SAMLProvider.objects.using(db_alias).all(): + provider.name_temp = provider.name + provider.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_core", "0011_provider_name_temp"), + ("passbook_providers_saml", "0005_remove_samlprovider_processor_path"), + ] + + operations = [ + migrations.RunPython(update_name_temp), + migrations.RemoveField( + model_name="samlprovider", + name="name", + ), + ] diff --git a/passbook/providers/saml/models.py b/passbook/providers/saml/models.py index 4ab9e204f..5e5ad8b6a 100644 --- a/passbook/providers/saml/models.py +++ b/passbook/providers/saml/models.py @@ -27,8 +27,6 @@ class SAMLBindings(models.TextChoices): class SAMLProvider(Provider): """SAML 2.0 Endpoint for applications which support SAML.""" - name = models.TextField() - acs_url = models.URLField(verbose_name=_("ACS URL")) audience = models.TextField(default="") issuer = models.TextField(help_text=_("Also known as EntityID")) diff --git a/passbook/stages/identification/migrations/0005_auto_20201003_1734.py b/passbook/stages/identification/migrations/0005_auto_20201003_1734.py new file mode 100644 index 000000000..30ead927c --- /dev/null +++ b/passbook/stages/identification/migrations/0005_auto_20201003_1734.py @@ -0,0 +1,29 @@ +# Generated by Django 3.1.2 on 2020-10-03 17:34 + +import django.contrib.postgres.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ( + "passbook_stages_identification", + "0004_identificationstage_case_insensitive_matching", + ), + ] + + operations = [ + migrations.AlterField( + model_name="identificationstage", + name="user_fields", + field=django.contrib.postgres.fields.ArrayField( + base_field=models.CharField( + choices=[("email", "E Mail"), ("username", "Username")], + max_length=100, + ), + help_text="Fields of the user object to match against. (Hold shift to select multiple options)", + size=None, + ), + ), + ] diff --git a/swagger.yaml b/swagger.yaml index 7b322edb6..ee748eabd 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -6589,6 +6589,7 @@ definitions: minLength: 1 Provider: required: + - name - authorization_flow type: object properties: @@ -6596,6 +6597,10 @@ definitions: title: ID type: integer readOnly: true + name: + title: Name + type: string + minLength: 1 authorization_flow: title: Authorization flow description: Flow used when authorizing this provider.