diff --git a/src/open_inwoner/accounts/forms.py b/src/open_inwoner/accounts/forms.py index 32aeeed1dc..d67dae3df1 100644 --- a/src/open_inwoner/accounts/forms.py +++ b/src/open_inwoner/accounts/forms.py @@ -70,13 +70,17 @@ def __init__(self, user, *args, **kwargs): super().__init__(*args, **kwargs) if user.login_type == LoginTypeChoices.digid: - self.fields["first_name"].disabled = True - self.fields["last_name"].disabled = True - self.fields["birthday"].disabled = True - self.fields["street"].disabled = True - self.fields["housenumber"].disabled = True - self.fields["postcode"].disabled = True - self.fields["city"].disabled = True + disabled_fields = ( + "first_name", + "last_name", + "birthday", + "street", + "housenumber", + "postcode", + "city", + ) + for field in disabled_fields: + self.fields[field].disabled = True class NecessaryUserForm(forms.ModelForm): diff --git a/src/open_inwoner/accounts/tests/test_profile_views.py b/src/open_inwoner/accounts/tests/test_profile_views.py index 48d812cd34..e09f8cd92e 100644 --- a/src/open_inwoner/accounts/tests/test_profile_views.py +++ b/src/open_inwoner/accounts/tests/test_profile_views.py @@ -273,6 +273,40 @@ def test_updating_a_field_without_modifying_email_succeeds(self): self.assertEqual(self.user.email, initial_email) self.assertEqual(self.user.first_name, "Testing") + def test_form_for_digid__user_saves_only_non_disabled_fields(self): + user = UserFactory( + bsn="999993847", + first_name="name", + last_name="surname", + login_type=LoginTypeChoices.digid, + ) + response = self.app.get(self.url, user=user) + form = response.forms["profile-edit"] + + form["first_name"] = "First name" + form["last_name"] = "Last name" + form["email"] = "user@example.com" + form["phonenumber"] = "06987878787" + form["birthday"] = "21-01-1992" + form["street"] = "Keizersgracht" + form["housenumber"] = "17 d" + form["postcode"] = "1013 RM" + form["city"] = "Amsterdam" + response = form.submit() + + self.assertEqual(response.url, self.return_url) + + user.refresh_from_db() + + self.assertEqual(user.first_name, "name") + self.assertEqual(user.last_name, "surname") + self.assertEqual(user.email, "user@example.com") + self.assertIsNone(user.birthday) + self.assertEqual(user.street, "") + self.assertEqual(user.housenumber, "") + self.assertIsNone(user.postcode, "") + self.assertEqual(user.city, "") + @requests_mock.Mocker() class MyDataTests(HaalCentraalMixin, WebTest):