Skip to content

Commit

Permalink
[#2720] Fix email field prefill in NecessaryFieldsUserView
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Sep 9, 2024
1 parent 9de71dd commit 7fa270c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/open_inwoner/accounts/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,14 +1507,16 @@ def test_submit_without_invite(self):
user = UserFactory(
first_name="",
last_name="",
email="test@example.org",
login_type=LoginTypeChoices.digid,
)
self.assertTrue(user.require_necessary_fields())

response = self.app.get(self.url, user=user)
form = response.forms["necessary-form"]

from open_inwoner.accounts.choices import NotificationChannelChoice
# check email is not prefilled
self.assertEqual(form["email"].value, "")

form["email"] = "john@smith.com"
form["first_name"] = "John"
Expand All @@ -1535,7 +1537,7 @@ def test_submit_without_invite(self):

def test_submit_with_invite(self):
user = UserFactory()
contact = UserFactory.build()
contact = UserFactory.build(email="test@example.org")
invite = InviteFactory.create(
inviter=user,
invitee_email=contact.email,
Expand Down
7 changes: 1 addition & 6 deletions src/open_inwoner/accounts/views/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from open_inwoner.accounts.choices import NotificationChannelChoice
from open_inwoner.accounts.views.mixins import KlantenAPIMixin
from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.utils.hash import generate_email_from_string
from open_inwoner.utils.views import CommonPageMixin, LogMixin

from ...mail.verification import send_user_email_verification_mail
Expand Down Expand Up @@ -184,11 +183,7 @@ def get_initial(self):
user = self.get_object()
invite = self.get_invite()

if not invite and (
(user.bsn and user.email == generate_email_from_string(user.bsn))
or (user.oidc_id and user.email == generate_email_from_string(user.oidc_id))
or (user.kvk and user.email == f"user-{user.kvk}@localhost")
):
if not invite and not user.has_usable_email():
initial["email"] = ""

return initial
Expand Down

0 comments on commit 7fa270c

Please sign in to comment.