Skip to content

Commit

Permalink
🐛 [#1302] -- Change component into content with warning when no bsn i…
Browse files Browse the repository at this point in the history
…s available

Instead of changing the component into a selectboxes component or
crashing hard when no submission bsn is available, the error situation
is detected and turned into a warning situation via content component
type instead.
  • Loading branch information
sergei-maertens committed Dec 1, 2022
1 parent fa5a45d commit a673284
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/openforms/formio/components/custom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging
from typing import Callable

from django.utils.html import format_html
from django.utils.translation import gettext as _

from openforms.authentication.constants import AuthAttribute
from openforms.submissions.models import Submission
from openforms.typing import DataMapping
Expand Down Expand Up @@ -86,10 +89,24 @@ def mutate_config_dynamically(
cls, component: Component, submission: Submission, data: DataMapping
) -> None:
# Check authentication details/status before proceeding
if not submission.is_authenticated:
raise RuntimeError("No authenticated person!")
if submission.auth_info.attribute != AuthAttribute.bsn:
raise RuntimeError("No BSN found in the authentication details.")
has_bsn = (
submission.is_authenticated
and submission.auth_info.attribute == AuthAttribute.bsn
)
if not has_bsn:
component.update(
{
"type": "content",
"html": format_html(
"<p>{message}</p>",
message=_(
"Selecting family members is currently not available."
),
),
"input": False,
}
)
return

bsn = submission.auth_info.value

Expand Down

0 comments on commit a673284

Please sign in to comment.