Skip to content

Commit

Permalink
Feature flag user login
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanjbrown committed Apr 17, 2024
1 parent 041f688 commit a136ce2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 2 additions & 0 deletions consultation_analyser/consultations/views/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
24 changes: 13 additions & 11 deletions consultation_analyser/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
import waffle

from django.http import HttpRequest

Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/test_user_can_sign_in.py
Original file line number Diff line number Diff line change
@@ -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 protected]", password="admin") # pragma: allowlist secret

Expand Down

0 comments on commit a136ce2

Please sign in to comment.