Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the models swappable #117

Closed
wants to merge 5 commits into from
Closed

Make the models swappable #117

wants to merge 5 commits into from

Conversation

lgarvey
Copy link
Contributor

@lgarvey lgarvey commented Mar 2, 2021

This PR follows the pattern used in django-oauth2-toolkit - and is suggested in #90

I have a need to extend the ServiceProvider model to add some additional features so I thought I'd raise a PR to add swappable functionality. I can also add some documentation if required.

I assume unit tests aren't required as it's leveraging the swappable api in django?

Following the pattern used in django-oauth2-toolkit
@lgarvey
Copy link
Contributor Author

lgarvey commented Mar 3, 2021

Hi @mhindery I've squashed the previous migrations and used the squashed version to apply the swappable logic. So that existing installations should still function without any issues.

Doing some manual testing the PR works with:

an existing installation of djangosaml2idp with previous migrations applied
a new installation of djangosaml2idp without overridden models
a new installation of djangosaml2idp with overridden models (will do some more testing as currently I have only overridden the ServiceProvider model)

I haven't looked at the admin system - but typically this involves unregistering and re-registering the admin models in the overriding app.

It'd be good to gauge whether you'd be interested in merging the PR as I'm currently building some functionality that depends on it. Essentially I need to add some extra fields to the ServiceProvider model

@@ -16,6 +16,7 @@
from saml2 import xmldsig

from .idp import IDP
from .settings import SERVICE_PROVIDER_MODEL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be from django.conf import settings? that way you're actually importing the settings proxy object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind. I looked back over the Oauth toolkit implementation and it looks like you're doing it the same way.

Copy link
Contributor

@Amertz08 Amertz08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any issues with this.

lgarvey added 2 commits March 4, 2021 17:18
Again following Django-oauth-toolkits configuration, this automatically uses the overridden model in the admin, and allow for overriding of the admin model.
@mhindery
Copy link
Contributor

mhindery commented Mar 6, 2021

Hi @lgarvey , this is a great addition, I'm definitely happy to merge this in.

@mhindery
Copy link
Contributor

mhindery commented Mar 6, 2021

Ideally this gets some documentation added as well, but that is something I can add later. Let me know if you are done and not plan any more changes in the PR, then I'll merge it.

@lgarvey
Copy link
Contributor Author

lgarvey commented Mar 6, 2021

It all seems good from this end - one very minor point:

If overriding a model, the migration for the overridden model has to run before the migrations for djangosaml2idp or else there'll be an error. The django-oauth-toolkit advises to put a run_before statement into your overriding migration to ensure they are executed in the correct order, e.g

class Migration(migrations.Migration):

    run_before = [
        ('djangosaml2idp', '0001_initial_squashed_0002_persistent_id_swappable_models'),
    ]

I think the name of the squashed (and swappable) migration should be something less verbose, e.g: 0001_initial_swappable.py

But aside from that everything seems good.

@lgarvey
Copy link
Contributor Author

lgarvey commented Mar 8, 2021

This seems all good to merge now.

@farzeni
Copy link

farzeni commented Feb 7, 2022

Hello,

Is there any reason why this PR has not been merged in upstream?

@uktrade uktrade closed this by deleting the head repository May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants