-
-
Notifications
You must be signed in to change notification settings - Fork 447
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
TWO_FACTOR_SKIP_WELCOME setting to skip welcome page. #150
base: master
Are you sure you want to change the base?
Conversation
two_factor/views/core.py
Outdated
('welcome', Form), | ||
('method', MethodForm), | ||
('generator', TOTPDeviceForm), | ||
('sms', PhoneNumberForm), | ||
('call', PhoneNumberForm), | ||
('validation', DeviceValidationForm), | ||
('yubikey', YubiKeyDeviceForm), | ||
) | ||
] | ||
if hasattr(settings, 'TWO_FACTOR_SKIP_WELCOME') and settings.TWO_FACTOR_SKIP_WELCOME: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use condition_dict
to skip certain wizard pages
@@ -213,7 +213,10 @@ class SetupView(IdempotentSessionWizardView): | |||
('validation', DeviceValidationForm), | |||
('yubikey', YubiKeyDeviceForm), | |||
) | |||
|
|||
show_welcome = not hasattr(settings, 'TWO_FACTOR_SKIP_WELCOME') or not settings.TWO_FACTOR_SKIP_WELCOME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be executed at import time, not when the lambda function in the condition_dict
is being called. Can you either define the lambda expression here or move this into the lambda function's body, please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just not getattr(settings, 'TWO_FACTOR_SKIP_WELCOME', False)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- because a definition of
None
in the settings is not the same asFalse
. - because it will still be executed at import time, not when it should be evaluated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Change
False
toNone
then. - What's the problem of being executed at import time? (don't know. actually curious)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- It's only evaluated once which makes testing harder. When you want to check for different values of
TWO_FACTOR_SKIP_WELCOME
you'd need to take care of that yourself. Using dynamic evaluation at runtime isn't much slower within this simple situation but makes testing easier.
Apart from that, can you please add the settings to the documentation and add a test for this. Thank you 😄 |
PR for issue #149
TWO_FACTOR_SKIP_WELCOME = True in settings will drop welcome page from wizard.
If setting is left out it will continue to work as normal.
Unit tests all passing.