-
Notifications
You must be signed in to change notification settings - Fork 26
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
✨ [#4344] Configurable objects API group in ZGW registration #4758
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import { | |
ValidationErrorContext, | ||
ValidationErrorsProvider, | ||
} from 'components/admin/forms/ValidationErrors'; | ||
import {ObjectsAPIGroup} from 'components/admin/forms/objects_api'; | ||
|
||
import BasicOptionsFieldset from './BasicOptionsFieldset'; | ||
import ManageVariableToPropertyMappings from './ManageVariableToPropertyMappings'; | ||
|
@@ -25,7 +26,21 @@ import { | |
} from './fields'; | ||
import {filterErrors} from './utils'; | ||
|
||
const ZGWFormFields = ({name, apiGroupChoices, confidentialityLevelChoices}) => { | ||
/** | ||
* Callback to invoke when the API group changes - used to reset the dependent fields. | ||
*/ | ||
const onApiGroupChange = prevValues => ({ | ||
...prevValues, | ||
objecttype: '', | ||
objecttypeVersion: undefined, | ||
}); | ||
sergei-maertens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const ZGWFormFields = ({ | ||
name, | ||
apiGroupChoices, | ||
objectsApiGroupChoices, | ||
confidentialityLevelChoices, | ||
}) => { | ||
const { | ||
values: {propertyMappings = []}, | ||
} = useFormikContext(); | ||
|
@@ -112,6 +127,10 @@ const ZGWFormFields = ({name, apiGroupChoices, confidentialityLevelChoices}) => | |
collapsible | ||
fieldNames={['objecttype', 'objecttypeVersion', 'contentJson']} | ||
> | ||
<ObjectsAPIGroup | ||
apiGroupChoices={objectsApiGroupChoices} | ||
onApiGroupChange={onApiGroupChange} | ||
/> | ||
Comment on lines
+130
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this one should be |
||
<ObjectType /> | ||
<ObjectTypeVersion /> | ||
<ContentJSON /> | ||
|
@@ -137,6 +156,14 @@ ZGWFormFields.propTypes = { | |
]) | ||
) | ||
).isRequired, | ||
objectsApiGroupChoices: PropTypes.arrayOf( | ||
PropTypes.arrayOf( | ||
PropTypes.oneOfType([ | ||
PropTypes.number, // value | ||
PropTypes.string, // label | ||
]) | ||
) | ||
), | ||
confidentialityLevelChoices: PropTypes.arrayOf( | ||
PropTypes.arrayOf(PropTypes.string) // value & label are both string | ||
).isRequired, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
from zgw_consumers.api_models.constants import VertrouwelijkheidsAanduidingen | ||
|
||
from openforms.api.fields import PrimaryKeyRelatedAsChoicesField | ||
from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig | ||
from openforms.contrib.zgw.clients.catalogi import ( | ||
CaseType, | ||
CatalogiClient, | ||
|
@@ -104,6 +105,14 @@ class ZaakOptionsSerializer(JsonSchemaSerializerMixin, serializers.Serializer): | |
) | ||
|
||
# Objects API | ||
objects_api_group = PrimaryKeyRelatedAsChoicesField( | ||
queryset=ObjectsAPIGroupConfig.objects.exclude( | ||
Q(objects_service=None) | Q(objecttypes_service=None) | ||
), | ||
help_text=_("Which Objects API set to use."), | ||
label=_("Objects API set"), | ||
required=False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we may need an There's some more steps involved in this PR I think:
|
||
) | ||
objecttype = serializers.URLField( | ||
label=_("objects API - objecttype"), | ||
help_text=_( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -578,7 +578,9 @@ def register_submission_to_objects_api( | |
) | ||
|
||
# In a follow up PR: the group will be configurable: | ||
api_group = ObjectsAPIGroupConfig.objects.order_by("pk").first() | ||
api_group = options.get( | ||
"objects_api_group", ObjectsAPIGroupConfig.objects.order_by("pk").first() | ||
) | ||
Comment on lines
+581
to
+583
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to remove this default/fallback behaviour entirely so that all configuration is explicit, and we can then also define this accordingly in the options type declarations. api_group = options["objects_api_group"]
assert api_group is not None |
||
if not api_group: # pragma: no cover | ||
raise RegistrationFailed("No API group available at all") | ||
with get_objects_client(api_group) as objects_client: | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,8 @@ | |||||
from typing import TYPE_CHECKING, Literal, NotRequired, TypedDict | ||||||
|
||||||
if TYPE_CHECKING: | ||||||
from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig | ||||||
|
||||||
from .models import ZGWApiGroupConfig | ||||||
|
||||||
|
||||||
|
@@ -37,6 +39,7 @@ class RegistrationOptions(TypedDict): | |||||
organisatie_rsin: NotRequired[str] | ||||||
zaak_vertrouwelijkheidaanduiding: NotRequired[VertrouwelijkheidAanduiding] | ||||||
medewerker_roltype: NotRequired[str] | ||||||
objects_api_group: NotRequired[ObjectsAPIGroupConfig] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think we can enforce this key being set at all times. If the value is |
||||||
objecttype: NotRequired[str] | ||||||
objecttype_version: NotRequired[int] | ||||||
content_json: NotRequired[str] | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update the component prop types accordingly