mirror of https://github.com/zulip/zulip.git
2fa: Rename zulip_otp_required for clarity.
The name does not really comply with the actual behavior of the decorator since it returns True for an unauthenticated user. This makes it clear that the 2fa check only applies to users that are already logged in. Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
parent
00bd7513f2
commit
74f59bd8d0
|
@ -528,7 +528,7 @@ def zulip_login_required(
|
|||
login_url=login_url,
|
||||
redirect_field_name=redirect_field_name,
|
||||
)(
|
||||
zulip_otp_required(
|
||||
zulip_otp_required_if_logged_in(
|
||||
redirect_field_name=redirect_field_name,
|
||||
login_url=login_url,
|
||||
)(add_logging_data(function))
|
||||
|
@ -548,7 +548,7 @@ def web_public_view(
|
|||
This wrapper adds client info for unauthenticated users but
|
||||
forces authenticated users to go through 2fa.
|
||||
"""
|
||||
actual_decorator = lambda view_func: zulip_otp_required(
|
||||
actual_decorator = lambda view_func: zulip_otp_required_if_logged_in(
|
||||
redirect_field_name=redirect_field_name, login_url=login_url
|
||||
)(add_logging_data(view_func))
|
||||
|
||||
|
@ -1021,7 +1021,7 @@ def return_success_on_head_request(view_func: ViewFuncT) -> ViewFuncT:
|
|||
return cast(ViewFuncT, _wrapped_view_func) # https://github.com/python/mypy/issues/1927
|
||||
|
||||
|
||||
def zulip_otp_required(
|
||||
def zulip_otp_required_if_logged_in(
|
||||
redirect_field_name: str = "next",
|
||||
login_url: str = settings.HOME_NOT_LOGGED_IN,
|
||||
) -> Callable[[ViewFuncT], ViewFuncT]:
|
||||
|
@ -1033,7 +1033,7 @@ def zulip_otp_required(
|
|||
|
||||
Similar to :func:`~django.contrib.auth.decorators.login_required`, but
|
||||
requires the user to be :term:`verified`. By default, this redirects users
|
||||
to :setting:`OTP_LOGIN_URL`.
|
||||
to :setting:`OTP_LOGIN_URL`. Returns True if the user is not authenticated.
|
||||
"""
|
||||
|
||||
def test(user: Union[UserProfile, AnonymousUser]) -> bool:
|
||||
|
|
|
@ -34,7 +34,7 @@ from zerver.decorator import (
|
|||
validate_api_key,
|
||||
webhook_view,
|
||||
zulip_login_required,
|
||||
zulip_otp_required,
|
||||
zulip_otp_required_if_logged_in,
|
||||
)
|
||||
from zerver.forms import OurAuthenticationForm
|
||||
from zerver.lib.cache import dict_to_items_tuple, ignore_unhashable_lru_cache, items_tuple_to_dict
|
||||
|
@ -1902,7 +1902,7 @@ class TestZulipLoginRequiredDecorator(ZulipTestCase):
|
|||
self.assertEqual(response.content.decode(), "Success")
|
||||
|
||||
def test_otp_not_authenticated(self) -> None:
|
||||
@zulip_otp_required()
|
||||
@zulip_otp_required_if_logged_in()
|
||||
def test_view(request: HttpRequest) -> HttpResponse:
|
||||
return HttpResponse("Success")
|
||||
|
||||
|
|
Loading…
Reference in New Issue