Skip to content

Commit

Permalink
[#1898] Design profile page for businesses
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Dec 4, 2023
1 parent bbc1a2a commit 8cb7d5f
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 46 deletions.
20 changes: 20 additions & 0 deletions src/open_inwoner/accounts/migrations/0069_auto_20231204_1159.py
Original file line number Diff line number Diff line change
@@ -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"
),
),
]
15 changes: 9 additions & 6 deletions src/open_inwoner/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions src/open_inwoner/accounts/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
38 changes: 37 additions & 1 deletion src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
99 changes: 60 additions & 39 deletions src/open_inwoner/templates/pages/profile/me.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,70 @@
{% with user=request.user %}

<div class="tabled tabled--flexible">
<h1 class="h1 tabled__title">{% trans "Welkom" %}, {{ user.first_name }}</h1>
<span class="tabled__key">{%trans "voor het laatst ingelogd op" %}: <span class="tabled__value">{{ user.last_login|date:"d-m-Y" }} om {{ user.last_login|date:"H:i" }} uur</span></span>
<h1 class="h1" id="title">{% trans "Welkom" %}{% if not user.is_digid_user %}, {{ user.first_name }}{% endif %}</h1>
<span class="tabled__key">{%trans "voor het laatst ingelogd op" %}: <span class="tabled__value">{{ user.last_login|date:"d F Y" }} om {{ user.last_login|date:"H:i" }} uur</span></span>
</div>

{# Personal information #}
<div class="tabled tabled--flexible profile-section" id="personal-info">
<div class="tabled__section">
<h2 class="h2 title" id="personal-overview">{% trans "Persoonlijke gegevens" %}
<div class="tabled__item--force-right tabled__item--mobile-big">
{% button href="profile:edit" text=_("Bewerken") icon="edit" transparent=True %}
{% if user.is_digid_user_with_brp and view.config.my_data %}
{% button href="profile:data" text=_("My details") icon="info" transparent=True icon_outlined=True %}
{% elif not user.is_digid_user %}
{% button href="password_change" text=_("Password") icon="key" transparent=True %}
{% endif %}
</div>
</h2>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Voornaam" %}</div>
<div class="tabled__item tabled__value">{{ user.infix}} {{ user.first_name }}</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Achternaam" %}</div>
<div class="tabled__item tabled__value">{{ user.last_name }}</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Geboortedatum" %}</div>
<div class="tabled__item tabled__value">{{ user.birthday|date:"d.m.Y" }}</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Adres" %}</div>
<div class="tabled__item tabled__value">{{ user.street }} {{ user.housenumber }}<br>{{user.postcode}} {{ user.city }}</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "E-mail adres" %}</div>
<div class="tabled__item tabled__value">{{ user.get_contact_email }}</div>
{% if user.kvk %}
{# Business information #}
<div class="tabled tabled--flexible profile-section">
<div>
<h2 class="h2 tabled__section" id="business-overview">{% trans "Bedrijfsgegevens" %}</h2>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__item--lighter">{% trans "Handelsnaam" %}</div>
<div class="tabled__item">{{ user.company_name }}</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__item--lighter">{% trans "KvK nummer" %}</div>
<div class="tabled__item">{{ user.kvk }}</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__item--lighter">{% trans "Zakelijk adres" %}</div>
<div class="tabled__item">{{ user.street }} {{ user.housenumber }}<br>{{user.postcode}} {{ user.city }}</div>
</div>
</div>
<div class="tabled__row">
<div class="tabled__item tabled__key">{% trans "Telefoonnummer" %}</div>
<div class="tabled__item tabled__value">{{ user.phonenumber }}</div>
{% else %}
{# Personal information #}
<div class="tabled tabled--flexible profile-section" id="personal-info">
<div class="tabled__section">
<h2 class="h2 title" id="personal-overview">{% trans "Persoonlijke gegevens" %}
<div class="tabled__item--force-right tabled__item--mobile-big">
{% button href="profile:edit" text=_("Bewerken") icon="edit" transparent=True %}
{% if user.is_digid_user_with_brp and view.config.my_data %}
{% button href="profile:data" text=_("My details") icon="info" transparent=True icon_outlined=True %}
{% elif not user.is_digid_user %}
{% button href="password_change" text=_("Password") icon="key" transparent=True %}
{% endif %}
</div>
</h2>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Voornaam" %}</div>
<div class="tabled__item tabled__value">{{ user.infix}} {{ user.first_name }}</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Achternaam" %}</div>
<div class="tabled__item tabled__value">{{ user.last_name }}</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Geboortedatum" %}</div>
<div class="tabled__item tabled__value">{{ user.birthday|date:"d F Y" }}</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Adres" %}</div>
<div class="tabled__item tabled__value">{{ user.street }} {{ user.housenumber }}<br>{{user.postcode}} {{ user.city }}</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "E-mail adres" %}</div>
<div class="tabled__item tabled__value">{{ user.get_contact_email }}</div>
</div>
<div class="tabled__row">
<div class="tabled__item tabled__key">{% trans "Telefoonnummer" %}</div>
<div class="tabled__item tabled__value">{{ user.phonenumber }}</div>
</div>
</div>
</div>
{% endif %}

{# Notifications #}
<div class="tabled tabled--flexible profile-section" id="notifications">
Expand Down

0 comments on commit 8cb7d5f

Please sign in to comment.