diff --git a/src/open_inwoner/accounts/migrations/0069_auto_20231204_1159.py b/src/open_inwoner/accounts/migrations/0069_auto_20231204_1159.py new file mode 100644 index 0000000000..1ec16cfd5a --- /dev/null +++ b/src/open_inwoner/accounts/migrations/0069_auto_20231204_1159.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.20 on 2023-12-04 10:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0068_relax_email_constraint_for_eherkenning"), + ] + + operations = [ + migrations.AlterField( + model_name="user", + name="company_name", + field=models.CharField( + blank=True, default="", max_length=250, verbose_name="Company name" + ), + ), + ] diff --git a/src/open_inwoner/accounts/models.py b/src/open_inwoner/accounts/models.py index 2ea5d54f28..f3ccc5184a 100644 --- a/src/open_inwoner/accounts/models.py +++ b/src/open_inwoner/accounts/models.py @@ -131,7 +131,10 @@ class User(AbstractBaseUser, PermissionsMixin): validators=[validate_kvk], ) company_name = models.CharField( - verbose_name=_("Company name"), max_length=250, null=True, blank=True + verbose_name=_("Company name"), + blank=True, + default="", + max_length=250, ) login_type = models.CharField( verbose_name=_("Login type"), @@ -269,12 +272,12 @@ def __init__(self, *args, **kwargs): self._old_bsn = self.bsn def __str__(self): - name = self.get_full_name() + identifier = self.company_name if self.kvk else self.get_full_name() email = self.get_contact_email() - if name and email: - return f"{name} ({email})" + if identifier and email: + return f"{identifier} ({email})" else: - return name or email or str(self.uuid)[:8] + return identifier or email or str(self.uuid)[:8] def clean(self, *args, **kwargs): """Reject non-unique emails, except for users with login_type DigiD""" @@ -350,7 +353,7 @@ def get_age(self): def get_address(self): if self.street: - return f"{self.street} {self.housenumber}, {self.city}" + return f"{self.street} {self.housenumber}, {self.postcode} {self.city}" return "" def get_new_messages_total(self) -> int: diff --git a/src/open_inwoner/accounts/tests/factories.py b/src/open_inwoner/accounts/tests/factories.py index 087d1fa946..e53f5e7332 100644 --- a/src/open_inwoner/accounts/tests/factories.py +++ b/src/open_inwoner/accounts/tests/factories.py @@ -40,6 +40,14 @@ class eHerkenningUserFactory(UserFactory): is_prepopulated = True +class KvKUserFactory(UserFactory): + first_name = "" + infix = "" + last_name = "" + login_type = LoginTypeChoices.eherkenning + kvk = "12345678" + + class TokenFactory(factory.django.DjangoModelFactory): class Meta: model = "authtoken.Token" diff --git a/src/open_inwoner/accounts/tests/test_profile_views.py b/src/open_inwoner/accounts/tests/test_profile_views.py index 5d6c4d09ae..a2e28f2e6a 100644 --- a/src/open_inwoner/accounts/tests/test_profile_views.py +++ b/src/open_inwoner/accounts/tests/test_profile_views.py @@ -9,6 +9,7 @@ import requests_mock from cms import api from django_webtest import WebTest +from pyquery import PyQuery as PQ from timeline_logger.models import TimelineLog from webtest import Upload @@ -28,7 +29,13 @@ from ..choices import ContactTypeChoices, LoginTypeChoices from ..forms import BrpUserForm, UserForm from ..models import User -from .factories import ActionFactory, DigidUserFactory, DocumentFactory, UserFactory +from .factories import ( + ActionFactory, + DigidUserFactory, + DocumentFactory, + KvKUserFactory, + UserFactory, +) @override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls") @@ -69,6 +76,9 @@ def test_user_information_profile_page(self): self.assertContains(response, self.user.housenumber) self.assertContains(response, self.user.city) + # check business profile section not displayed + self.assertNotContains(response, "Bedrijfsgegevens") + def test_get_empty_profile_page(self): response = self.app.get(self.url, user=self.user) @@ -109,6 +119,9 @@ def test_mydata_shown_with_digid_and_brp(self): response = self.app.get(self.url, user=user) self.assertContains(response, _("My details")) + # check business profile section not displayed + self.assertNotContains(response, "Bedrijfsgegevens") + def test_mydata_not_shown_with_digid_and_no_brp(self): user = UserFactory( bsn="999993847", @@ -124,6 +137,29 @@ def test_mydata_not_shown_without_digid(self): response = self.app.get(self.url, user=self.user) self.assertNotContains(response, _("My details")) + def test_info_kvk_user(self): + user = KvKUserFactory( + company_name="Makers and Shakers", + street="Fantasiestraat", + housenumber="42", + postcode="1234 XY", + city="The good place", + ) + response = self.app.get(self.url, user=user) + + self.assertContains(response, "Makers and Shakers") + self.assertContains(response, "Fantasiestraat 42") + self.assertContains(response, "1234 XY The good place") + + doc = PQ(response.content) + + business_section = doc.find("#business-overview")[0] + self.assertEqual(business_section.text, "Bedrijfsgegevens") + + # check personal overview section not displayed + personal_section = doc.find("#personal-overview") + self.assertEqual(personal_section, []) + def test_active_user_notifications_are_shown(self): user = UserFactory( bsn="999993847", diff --git a/src/open_inwoner/templates/pages/profile/me.html b/src/open_inwoner/templates/pages/profile/me.html index 71d791117d..0283a16e76 100644 --- a/src/open_inwoner/templates/pages/profile/me.html +++ b/src/open_inwoner/templates/pages/profile/me.html @@ -10,49 +10,70 @@ {% with user=request.user %}