Skip to content

Commit

Permalink
[#2106] Renamed config field to send_email_confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van der Schoor committed Apr 18, 2024
1 parent 7998855 commit 0143e9d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 46 deletions.
8 changes: 4 additions & 4 deletions src/open_inwoner/cms/cases/tests/test_contactform.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,14 @@ def test_form_success_with_both_email_and_api(

mock_send_confirm.assert_called_once_with("[email protected]", ANY)

def test_api_sends_email_confirmation_is_configurable__api_does_not_send(
def test_send_email_confirmation_is_configurable__send_enabled(
self, m, mock_contactmoment, mock_send_confirm
):
self._setUpMocks(m)
self._setUpExtraMocks(m)

config = OpenKlantConfig.get_solo()
config.api_sends_email_confirmation = False
config.send_email_confirmation = True
config.save()

response = self.app.get(self.case_detail_url, user=self.user)
Expand All @@ -628,14 +628,14 @@ def test_api_sends_email_confirmation_is_configurable__api_does_not_send(
response = form.submit()
mock_send_confirm.assert_called_once()

def test_api_sends_email_confirmation_is_configurable__api_sends(
def test_send_email_confirmation_is_configurable__send_disabled(
self, m, mock_contactmoment, mock_send_confirm
):
self._setUpMocks(m)
self._setUpExtraMocks(m)

config = OpenKlantConfig.get_solo()
config.api_sends_email_confirmation = True
config.send_email_confirmation = False
config.save()

response = self.app.get(self.case_detail_url, user=self.user)
Expand Down
5 changes: 1 addition & 4 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,7 @@ def post(self, request, *args, **kwargs):
if config.register_contact_moment:
api_success = self.register_by_api(form, config)
if api_success:
if config.api_sends_email_confirmation:
send_confirmation = False
else:
send_confirmation = True
send_confirmation = config.send_email_confirmation
# else keep the send_confirmation if email set it

if send_confirmation:
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/openklant/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class OpenKlantConfigAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin):
"register_channel",
"register_employee_id",
"use_rsin_for_innNnpId_query_parameter",
"api_sends_email_confirmation",
"send_email_confirmation",
],
},
),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.11 on 2024-04-18 07:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
(
"openklant",
"0011_alter_openklantconfig_use_rsin_for_innnnpid_query_parameter",
),
]

operations = [
migrations.AddField(
model_name="openklantconfig",
name="send_email_confirmation",
field=models.BooleanField(
default=False,
help_text="If enabled the 'contactform_confirmation' email template will be sent. If disabled the external API will send a confirmation email.",
verbose_name="Stuur contactformulier e-mailbevestiging",
),
),
]
8 changes: 4 additions & 4 deletions src/open_inwoner/openklant/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ class OpenKlantConfig(SingletonModel):
),
default=False,
)
api_sends_email_confirmation = models.BooleanField(
verbose_name=_("API stuurt bevestiging"),
send_email_confirmation = models.BooleanField(
verbose_name=_("Stuur contactformulier e-mailbevestiging"),
help_text=_(
"If enabled the external API will send a confirmation email."
"If not enabled the 'contactform_confirmation' email template will be sent"
"If enabled the 'contactform_confirmation' email template will be sent. "
"If disabled the external API will send a confirmation email."
),
default=False,
)
Expand Down
14 changes: 7 additions & 7 deletions src/open_inwoner/openklant/tests/test_contactform.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ def test_submit_and_register_kvk_or_rsin_user_via_api_and_update_klant(
)
mock_send_confirm.reset_mock()

def test_api_sends_email_confirmation_is_configurable(self, m, mock_send_confirm):
def test_send_email_confirmation_is_configurable(self, m, mock_send_confirm):
MockAPICreateData.setUpServices()

config = OpenKlantConfig.get_solo()
Expand All @@ -748,9 +748,9 @@ def test_api_sends_email_confirmation_is_configurable(self, m, mock_send_confirm
subject="Aanvraag document",
subject_code="afdeling-xyz",
)
for api_sends in [True, False]:
with self.subTest(api_sends=api_sends):
config.api_sends_email_confirmation = api_sends
for send in [True, False]:
with self.subTest(send=send):
config.send_email_confirmation = send
config.save()

response = self.app.get(self.url)
Expand All @@ -765,8 +765,8 @@ def test_api_sends_email_confirmation_is_configurable(self, m, mock_send_confirm

response = form.submit().follow()

if api_sends:
mock_send_confirm.assert_not_called()
else:
if send:
mock_send_confirm.assert_called_once()
else:
mock_send_confirm.assert_not_called()
mock_send_confirm.reset_mock()
5 changes: 1 addition & 4 deletions src/open_inwoner/openklant/views/contactform.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ def form_valid(self, form):
if config.register_contact_moment:
api_success, api_user_email = self.register_by_api(form, config)
if api_success:
if config.api_sends_email_confirmation:
send_confirmation = False
else:
send_confirmation = True
send_confirmation = config.send_email_confirmation
# else keep the send_confirmation if email set it

# it is possible we don't have an email, user didn't enter it but we got it from the Klant
Expand Down

0 comments on commit 0143e9d

Please sign in to comment.