Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Set up automatic patching/unpatching based on setting change #9

Merged
merged 1 commit into from
Aug 18, 2021

Conversation

sergei-maertens
Copy link
Member

This makes it possible to use @override_settings in tests to control 2FA behaviour.


@receiver(setting_changed, dispatch_uid="two_factor.handle_setting_changed")
def handle_setting_changed(sender, setting: str, value, **kwargs):
from .admin import patch_admin, unpatch_admin, __default_admin_site__

Choose a reason for hiding this comment

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

why did you put the import here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Circular dependencies, apps.py is imported before everything else, and if that pulls in admin.py before django is ready, then everything collapses.

Choose a reason for hiding this comment

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

ok :)

unpatch_admin()

elif setting == "TWO_FACTOR_FORCE_OTP_ADMIN":
if is_patched:

Choose a reason for hiding this comment

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

you can probably put this "if" in the "elif statement" in order to combine them no?
elif setting == "TWO_FACTOR_FORCE_OTP_ADMIN" and is_patched:

Copy link
Member Author

Choose a reason for hiding this comment

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

I decided to go with readability & symmetry with the above if-statement to make it clear we're only looking at two settings.

Copy link

@annashamray annashamray left a comment

Choose a reason for hiding this comment

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

Some nitpicking: I think this change could be moved into 'two_factor/signals.py` (which already exists in this lib)

This makes it possible to use @override_settings in tests to control 2FA behaviour.
@sergei-maertens sergei-maertens force-pushed the feature/patch-unpatch-on-settings-changed branch from c11a4b7 to 4129802 Compare August 18, 2021 13:11
@sergei-maertens sergei-maertens merged commit f50879c into master Aug 18, 2021
@joeribekker joeribekker deleted the feature/patch-unpatch-on-settings-changed branch September 2, 2021 09:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants