Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1052-4]Feature/ haalcentraal contact data #430

Merged
merged 5 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/open_inwoner/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Meta:
fields = (
"first_name",
"last_name",
"display_name",
"email",
"phonenumber",
"birthday",
Expand All @@ -66,6 +67,16 @@ class Meta:
)


class BrpUserForm(forms.ModelForm):
class Meta:
model = User
fields = (
"display_name",
"email",
"phonenumber",
)


class NecessaryUserForm(forms.ModelForm):
invite = forms.ModelChoiceField(
queryset=Invite.objects.all(),
Expand Down
25 changes: 25 additions & 0 deletions src/open_inwoner/accounts/migrations/0053_user_display_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.2.15 on 2023-01-17 14:21

from django.db import migrations, models
import open_inwoner.utils.validators


class Migration(migrations.Migration):

dependencies = [
("accounts", "0052_auto_20221213_0758"),
]

operations = [
migrations.AddField(
model_name="user",
name="display_name",
field=models.CharField(
blank=True,
default="",
max_length=255,
validators=[open_inwoner.utils.validators.validate_charfield_entry],
verbose_name="Display name",
),
),
]
7 changes: 7 additions & 0 deletions src/open_inwoner/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class User(AbstractBaseUser, PermissionsMixin):
default="",
validators=[validate_charfield_entry],
)
display_name = models.CharField(
verbose_name=_("Display name"),
max_length=255,
blank=True,
default="",
validators=[validate_charfield_entry],
)
email = models.EmailField(verbose_name=_("Email address"), unique=True)
phonenumber = models.CharField(
verbose_name=_("Phonenumber"),
Expand Down
71 changes: 68 additions & 3 deletions src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ...questionnaire.tests.factories import QuestionnaireStepFactory
from ..choices import LoginTypeChoices
from ..forms import BrpUserForm, UserForm
from .factories import ActionFactory, DocumentFactory, UserFactory


Expand Down Expand Up @@ -127,13 +128,28 @@ def test_get_documents_sorted(self):
self.assertTrue(doc_new.name in file_tags[0].prettify())
self.assertTrue(doc_old.name in file_tags[1].prettify())

def test_mydata_shown_with_digid(self):
user = UserFactory.create(
login_type=LoginTypeChoices.digid, email="[email protected]"
def test_mydata_shown_with_digid_and_brp(self):
user = UserFactory(
bsn="999993847",
first_name="name",
last_name="surname",
is_prepopulated=True,
login_type=LoginTypeChoices.digid,
)
response = self.app.get(self.url, user=user)
self.assertContains(response, _("Mijn gegevens"))

def test_mydata_not_shown_with_digid_and_no_brp(self):
user = UserFactory(
bsn="999993847",
first_name="name",
last_name="surname",
is_prepopulated=False,
login_type=LoginTypeChoices.digid,
)
response = self.app.get(self.url, user=user)
self.assertNotContains(response, _("Mijn gegevens"))

def test_mydata_not_shown_without_digid(self):
response = self.app.get(self.url, user=self.user)
self.assertNotContains(response, _("Mijn gegevens"))
Expand Down Expand Up @@ -164,6 +180,7 @@ def test_save_empty_form_fails(self):
form = response.forms["profile-edit"]
form["first_name"] = ""
form["last_name"] = ""
form["display_name"] = ""
form["email"] = ""
form["phonenumber"] = ""
form["birthday"] = ""
Expand All @@ -180,6 +197,7 @@ def test_save_filled_form(self):
form = response.forms["profile-edit"]
form["first_name"] = "First name"
form["last_name"] = "Last name"
form["display_name"] = "a nickname"
form["email"] = "[email protected]"
form["phonenumber"] = "06987878787"
form["birthday"] = "21-01-1992"
Expand All @@ -194,6 +212,7 @@ def test_save_filled_form(self):
self.user.refresh_from_db()
self.assertEquals(self.user.first_name, "First name")
self.assertEquals(self.user.last_name, "Last name")
self.assertEquals(self.user.display_name, "a nickname")
self.assertEquals(self.user.email, "[email protected]")
self.assertEquals(self.user.birthday.strftime("%d-%m-%Y"), "21-01-1992")
self.assertEquals(self.user.street, "Keizersgracht")
Expand All @@ -210,6 +229,7 @@ def test_save_with_invalid_first_name_chars_fails(self):
form = response.forms["profile-edit"]
form["first_name"] = char
form["last_name"] = "Last name"
form["display_name"] = "a nickname"
form["phonenumber"] = "06987878787"
form["birthday"] = "21-01-1992"
form["street"] = "Keizersgracht"
Expand All @@ -235,6 +255,7 @@ def test_save_with_invalid_last_name_chars_fails(self):
form = response.forms["profile-edit"]
form["first_name"] = "John"
form["last_name"] = char
form["display_name"] = "a nickname"
form["phonenumber"] = "06987878787"
form["birthday"] = "21-01-1992"
form["street"] = "Keizersgracht"
Expand Down Expand Up @@ -273,6 +294,50 @@ 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_brp_user_saves_data(self):
user = UserFactory(
bsn="999993847",
first_name="name",
last_name="surname",
is_prepopulated=True,
login_type=LoginTypeChoices.digid,
)
response = self.app.get(self.url, user=user)
form = response.forms["profile-edit"]

form["display_name"] = "a nickname"
form["email"] = "[email protected]"
form["phonenumber"] = "06987878787"
response = form.submit()

self.assertEqual(response.url, self.return_url)

user.refresh_from_db()

self.assertEqual(user.display_name, "a nickname")
self.assertEqual(user.email, "[email protected]")
self.assertEqual(user.phonenumber, "06987878787")

def test_expected_form_is_rendered(self):
# regular user
response = self.app.get(self.url, user=self.user)
form = response.context["form"]

self.assertEqual(type(form), UserForm)

# digid-brp user
user = UserFactory(
bsn="999993847",
first_name="name",
last_name="surname",
is_prepopulated=True,
login_type=LoginTypeChoices.digid,
)
response = self.app.get(self.url, user=user)
form = response.context["form"]

self.assertEqual(type(form), BrpUserForm)


@requests_mock.Mocker()
class MyDataTests(HaalCentraalMixin, WebTest):
Expand Down
11 changes: 8 additions & 3 deletions src/open_inwoner/accounts/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.utils.translation import gettext as _
from django.views.generic import DetailView, FormView, TemplateView, UpdateView

from glom import PathAccessError, glom
from glom import glom
from view_breadcrumbs import BaseBreadcrumbMixin

from open_inwoner.accounts.choices import (
Expand All @@ -21,11 +21,10 @@
)
from open_inwoner.haalcentraal.utils import fetch_brp_data
from open_inwoner.questionnaire.models import QuestionnaireStep
from open_inwoner.utils.logentry import user_action
from open_inwoner.utils.mixins import ExportMixin
from open_inwoner.utils.views import CommonPageMixin, LogMixin

from ..forms import ThemesForm, UserForm
from ..forms import BrpUserForm, ThemesForm, UserForm
from ..models import Action, User


Expand Down Expand Up @@ -127,6 +126,12 @@ def form_valid(self, form):
self.log_change(self.get_object(), _("profile was modified"))
return HttpResponseRedirect(self.get_success_url())

def get_form_class(self):
user = self.request.user
if user.login_type == LoginTypeChoices.digid and user.is_prepopulated:
return BrpUserForm
return super().get_form_class()


class MyCategoriesView(
LogMixin, LoginRequiredMixin, CommonPageMixin, BaseBreadcrumbMixin, UpdateView
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/templates/pages/profile/me.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h1 class="h1" id="title">
<h1 class="h1" id="overview">{% trans "Persoonlijk overzicht" %}</h1>

<div class="tabled tabled--flexible personal-overview">
{% if request.user.login_type == "digid" %}
{% if request.user.login_type == "digid" and request.user.is_prepopulated %}
<div class="tabled__row">
<div class="tabled__item tabled__item--bold">{% trans "Mijn gegevens" %}</div>
<div class="tabled__item">{{request.user.get_full_name}}{% if request.user.get_address %}, {{ request.user.get_address }}{% endif %}</div>
Expand Down
Loading