Skip to content

Commit

Permalink
Merge branch 'develop' into feature/2149-show-new-answer-to-question
Browse files Browse the repository at this point in the history
  • Loading branch information
alextreme authored Mar 15, 2024
2 parents 2a54eda + 9397863 commit 6ef5bc7
Show file tree
Hide file tree
Showing 49 changed files with 1,509 additions and 76 deletions.
2 changes: 2 additions & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ furl # processing urls
weasyprint # export to pdf
tinycss2
css_inline
pydantic[email]
typing-extensions

# Framework libraries
Django>=4.2<5.0
Expand Down
14 changes: 12 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ djangorestframework-camel-case==1.4.2
# via
# -r requirements/base.in
# notifications-api-common
dnspython==2.6.1
# via email-validator
drf-spectacular==0.20.1
# via -r requirements/base.in
easy-thumbnails[svg]==2.8.5
Expand All @@ -302,6 +304,8 @@ elasticsearch==7.15.1
# via elasticsearch-dsl
elasticsearch-dsl==7.4.0
# via django-elasticsearch-dsl
email-validator==2.1.1
# via pydantic
et-xmlfile==1.1.0
# via openpyxl
face==20.1.1
Expand Down Expand Up @@ -338,7 +342,9 @@ html5lib==1.1
humanfriendly==10.0
# via -r requirements/base.in
idna==3.2
# via requests
# via
# email-validator
# requests
inflection==0.5.1
# via drf-spectacular
isodate==0.6.1
Expand Down Expand Up @@ -407,6 +413,8 @@ psycopg2==2.9.9
# via -r requirements/base.in
pycparser==2.20
# via cffi
pydantic[email]==1.10.14
# via -r requirements/base.in
pydyf==0.1.2
# via weasyprint
pyee==11.0.1
Expand Down Expand Up @@ -494,8 +502,10 @@ tinycss2==1.1.1
# cssselect2
# svglib
# weasyprint
typing-extensions==4.4.0
typing-extensions==4.10.0
# via
# -r requirements/base.in
# pydantic
# pyee
# xsdata
uritemplate==4.1.1
Expand Down
26 changes: 24 additions & 2 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@ djangorestframework-camel-case==1.4.2
# -c requirements/base.txt
# -r requirements/base.txt
# notifications-api-common
dnspython==2.6.1
# via
# -c requirements/base.txt
# -r requirements/base.txt
# email-validator
drf-spectacular==0.20.1
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -511,6 +516,11 @@ elasticsearch-dsl==7.4.0
# -c requirements/base.txt
# -r requirements/base.txt
# django-elasticsearch-dsl
email-validator==2.1.1
# via
# -c requirements/base.txt
# -r requirements/base.txt
# pydantic
et-xmlfile==1.1.0
# via
# -c requirements/base.txt
Expand All @@ -524,7 +534,9 @@ face==20.1.1
factory-boy==3.2.0
# via -r requirements/test-tools.in
faker==9.9.0
# via factory-boy
# via
# factory-boy
# polyfactory
flake8==7.0.0
# via -r requirements/test-tools.in
fontawesomefree==6.4.2
Expand Down Expand Up @@ -584,6 +596,7 @@ idna==3.2
# via
# -c requirements/base.txt
# -r requirements/base.txt
# email-validator
# requests
inflection==0.5.1
# via
Expand Down Expand Up @@ -729,6 +742,8 @@ playwright==1.41.0
# via
# -c requirements/base.txt
# -r requirements/base.txt
polyfactory==2.13.0
# via -r requirements/test-tools.in
prompt-toolkit==3.0.36
# via
# -c requirements/base.txt
Expand All @@ -745,6 +760,11 @@ pycparser==2.20
# -c requirements/base.txt
# -r requirements/base.txt
# cffi
pydantic[email]==1.10.14
# via
# -c requirements/base.txt
# -r requirements/base.txt
# pydantic
pydyf==0.1.2
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -905,10 +925,12 @@ tinycss2==1.1.1
# weasyprint
tomlkit==0.12.3
# via pylint
typing-extensions==4.4.0
typing-extensions==4.10.0
# via
# -c requirements/base.txt
# -r requirements/base.txt
# polyfactory
# pydantic
# pyee
# xsdata
uritemplate==4.1.1
Expand Down
25 changes: 24 additions & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ djangorestframework-camel-case==1.4.2
# -c requirements/ci.txt
# -r requirements/ci.txt
# notifications-api-common
dnspython==2.6.1
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# email-validator
docutils==0.17.1
# via
# sphinx
Expand Down Expand Up @@ -562,6 +567,11 @@ elasticsearch-dsl==7.4.0
# -c requirements/ci.txt
# -r requirements/ci.txt
# django-elasticsearch-dsl
email-validator==2.1.1
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# pydantic
et-xmlfile==1.1.0
# via
# -c requirements/ci.txt
Expand All @@ -581,6 +591,7 @@ faker==9.9.0
# -c requirements/ci.txt
# -r requirements/ci.txt
# factory-boy
# polyfactory
flake8==7.0.0
# via
# -c requirements/ci.txt
Expand Down Expand Up @@ -666,6 +677,7 @@ idna==3.2
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# email-validator
# requests
imagesize==1.2.0
# via sphinx
Expand Down Expand Up @@ -851,6 +863,10 @@ playwright==1.41.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
polyfactory==2.13.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
prompt-toolkit==3.0.36
# via
# -c requirements/ci.txt
Expand All @@ -873,6 +889,11 @@ pycparser==2.20
# -c requirements/ci.txt
# -r requirements/ci.txt
# cffi
pydantic[email]==1.10.14
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# pydantic
pydyf==0.1.2
# via
# -c requirements/ci.txt
Expand Down Expand Up @@ -1092,10 +1113,12 @@ tomlkit==0.12.3
# -c requirements/ci.txt
# -r requirements/ci.txt
# pylint
typing-extensions==4.4.0
typing-extensions==4.10.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# polyfactory
# pydantic
# pyee
# xsdata
uritemplate==4.1.1
Expand Down
1 change: 1 addition & 0 deletions requirements/test-tools.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
coverage < 5.0
django-webtest
factory-boy
polyfactory
freezegun
pep8
pylint>=2.17.7
Expand Down
93 changes: 92 additions & 1 deletion src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.template.defaultfilters import date as django_date
from django.test import override_settings
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext as _

import requests_mock
from cms import api
Expand All @@ -17,10 +17,13 @@
from open_inwoner.accounts.choices import StatusChoices
from open_inwoner.cms.profile.cms_appconfig import ProfileConfig
from open_inwoner.haalcentraal.tests.mixins import HaalCentraalMixin
from open_inwoner.laposta.models import LapostaConfig
from open_inwoner.laposta.tests.factories import LapostaListFactory, SubscriptionFactory
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.pdc.tests.factories import CategoryFactory
from open_inwoner.plans.tests.factories import PlanFactory
from open_inwoner.utils.logentry import LOG_ACTIONS
from open_inwoner.utils.test import ClearCachesMixin
from open_inwoner.utils.tests.helpers import AssertTimelineLogMixin, create_image_bytes

from ...cms.profile.cms_apps import ProfileApphook
Expand Down Expand Up @@ -1048,3 +1051,91 @@ def test_collaborate_notifications_display(self):
form = response.forms["change-notifications"]

self.assertIn("plans_notifications", form.fields)


@requests_mock.Mocker()
@override_settings(
ROOT_URLCONF="open_inwoner.cms.tests.urls", MIDDLEWARE=PATCHED_MIDDLEWARE
)
class NewsletterSubscriptionTests(ClearCachesMixin, WebTest):
def setUp(self):
super().setUp()

self.profile_url = reverse("profile:newsletters")
self.user = DigidUserFactory()

self.config = LapostaConfig.get_solo()
self.config.api_root = "https://laposta.local/api/v2/"
self.config.basic_auth_username = "username"
self.config.basic_auth_password = "password"
self.config.save()

self.list1 = LapostaListFactory.build(
list_id="list1", name="Nieuwsbrief1", remarks="foo"
)
self.list2 = LapostaListFactory.build(
list_id="list2", name="Nieuwsbrief2", remarks="bar"
)

def setUpMocks(self, m):
m.get(
"https://laposta.local/api/v2/list",
json={"data": [{"list": self.list1.dict()}, {"list": self.list2.dict()}]},
)

def test_do_not_render_form_if_config_is_missing(self, m):
self.config.api_root = ""
self.config.save()

response = self.app.get(self.profile_url, user=self.user)

self.assertIn(_("Geen nieuwsbrieven beschikbaar"), response.text)
self.assertNotIn("newsletter-form", response.forms)

def test_do_not_render_form_if_no_newsletters_are_found(self, m):
m.get("https://laposta.local/api/v2/list", json=[])

response = self.app.get(self.profile_url, user=self.user)

self.assertIn(_("Geen nieuwsbrieven beschikbaar"), response.text)
self.assertNotIn("newsletter-form", response.forms)

def test_render_form_if_newsletters_are_found(self, m):
self.setUpMocks(m)

SubscriptionFactory.create(list_id=self.list1.list_id, user=self.user)

response = self.app.get(self.profile_url, user=self.user)

self.assertIn(_("Nieuwsbrieven"), response.text)
self.assertIn("newsletter-form", response.forms)

form = response.forms["newsletter-form"]

# First checkbox should be checked, because the user is already subscribed
self.assertTrue(form.fields["newsletters"][0].checked)
self.assertFalse(form.fields["newsletters"][1].checked)
self.assertIn("Nieuwsbrief1: foo", response.text)
self.assertIn("Nieuwsbrief2: bar", response.text)

def test_render_form_limit_newsletters_to_admin_selection(self, m):
self.setUpMocks(m)

self.config.limit_list_selection_to = ["list1"]
self.config.save()

SubscriptionFactory.create(list_id=self.list1.list_id, user=self.user)

response = self.app.get(self.profile_url, user=self.user)

self.assertIn(_("Nieuwsbrieven"), response.text)
self.assertIn("newsletter-form", response.forms)

form = response.forms["newsletter-form"]

# First checkbox should be checked, because the user is already subscribed
self.assertTrue(form.fields["newsletters"][0].checked)
self.assertIn("Nieuwsbrief1: foo", response.text)

# Second field was excluded by `LapostaConfig.limit_list_selection_to`
self.assertNotIn("Nieuwsbrief2: bar", response.text)
2 changes: 2 additions & 0 deletions src/open_inwoner/accounts/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
MyDataView,
MyNotificationsView,
MyProfileView,
NewsletterSubscribeView,
)
from .registration import CustomRegistrationView, NecessaryFieldsUserView

Expand Down Expand Up @@ -77,6 +78,7 @@
"MyDataView",
"MyNotificationsView",
"MyProfileView",
"NewsletterSubscribeView",
"CustomRegistrationView",
"NecessaryFieldsUserView",
]
31 changes: 30 additions & 1 deletion src/open_inwoner/accounts/views/contactmoments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

from django.conf import settings
from django.contrib.auth.mixins import AccessMixin
from django.http import Http404
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import redirect
from django.urls import reverse
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
from django.views import View
from django.views.generic import TemplateView

from view_breadcrumbs import BaseBreadcrumbMixin
Expand Down Expand Up @@ -244,3 +245,31 @@ def get_context_data(self, **kwargs):
},
]
return ctx


class KlantContactMomentRedirectView(KlantContactMomentAccessMixin, View):
"""
Redirect to `KlantContactMomentDetailView` on the basis of contactmoment uuid
"""

def get(self, request, *args, **kwargs):
klanten_client = build_client("klanten")
contactmoment_client = build_client("contactmomenten")

klant = klanten_client.retrieve_klant(**get_fetch_parameters(self.request))
kcms = contactmoment_client.retrieve_klantcontactmomenten_for_klant(klant)

if not kcms:
raise Http404

contactmoment_uuid = kwargs["uuid"]
kcm = next(
(kcm for kcm in kcms if str(kcm.contactmoment.uuid) == contactmoment_uuid)
)

if not kcm:
raise Http404

return HttpResponseRedirect(
reverse("cases:contactmoment_detail", kwargs={"kcm_uuid": kcm.uuid})
)
Loading

0 comments on commit 6ef5bc7

Please sign in to comment.