From a136ce28809598e379d3d963d65842e097b71600 Mon Sep 17 00:00:00 2001 From: Duncan Brown Date: Tue, 16 Apr 2024 23:27:39 +0100 Subject: [PATCH] Feature flag user login --- .../consultations/views/sessions.py | 2 ++ consultation_analyser/context_processors.py | 24 ++++++++++--------- tests/integration/test_user_can_sign_in.py | 2 ++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/consultation_analyser/consultations/views/sessions.py b/consultation_analyser/consultations/views/sessions.py index ede77de9f..8f3876602 100644 --- a/consultation_analyser/consultations/views/sessions.py +++ b/consultation_analyser/consultations/views/sessions.py @@ -3,6 +3,7 @@ from django.contrib.auth import logout from django.shortcuts import redirect from django.contrib import messages +from waffle.decorators import waffle_switch from consultation_analyser.authentication.models import User from magic_link.models import MagicLink @@ -20,6 +21,7 @@ def get_magic_link_for_email(request: HttpRequest, email: str) -> str: return "" +@waffle_switch('FRONTEND_USER_LOGIN') def new(request: HttpRequest): if not request.POST: form = NewSessionForm() diff --git a/consultation_analyser/context_processors.py b/consultation_analyser/context_processors.py index 5186123d0..27c0ef648 100644 --- a/consultation_analyser/context_processors.py +++ b/consultation_analyser/context_processors.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +import waffle from django.http import HttpRequest @@ -31,17 +32,18 @@ def app_config(request: HttpRequest): } ] - if request.user.is_authenticated: - menu_items.append({ - "href": "/sign-out", - "text": "Sign out", - }) - else: - menu_items.append({ - "href": "/sign-in", - "text": "Sign in", - "active": request.path == "/sign-in", - }) + if waffle.switch_is_active('FRONTEND_USER_LOGIN'): + if request.user.is_authenticated: + menu_items.append({ + "href": "/sign-out", + "text": "Sign out", + }) + else: + menu_items.append({ + "href": "/sign-in", + "text": "Sign in", + "active": request.path == "/sign-in/", + }) app_config = AppConfig( name="Consultation analyser", diff --git a/tests/integration/test_user_can_sign_in.py b/tests/integration/test_user_can_sign_in.py index 5840db693..c38f18264 100644 --- a/tests/integration/test_user_can_sign_in.py +++ b/tests/integration/test_user_can_sign_in.py @@ -1,9 +1,11 @@ import pytest +from waffle.testutils import override_switch from consultation_analyser.factories import UserFactory @pytest.mark.django_db +@override_switch("FRONTEND_USER_LOGIN", True) def test_user_can_sign_in(django_app): UserFactory(email="email@example.com", password="admin") # pragma: allowlist secret