From 76d33314a90b847454a5def1dc49e071123d8984 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Thu, 14 Nov 2024 14:35:20 +0100 Subject: [PATCH] :ok_hand: [maykinmedia/open-api-framework#66] PR feedback --- CHANGELOG.rst | 16 +++++++ README.rst | 3 -- docs/ref/client.rst | 4 +- ...ationsconfig_authorizations_api_service.py | 25 +++++++++++ vng_api_common/authorizations/models.py | 4 +- vng_api_common/utils.py | 3 -- vng_api_common/validators.py | 45 ------------------- 7 files changed, 44 insertions(+), 56 deletions(-) create mode 100644 vng_api_common/authorizations/migrations/0017_alter_authorizationsconfig_authorizations_api_service.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 21c59f4d..8a01537f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,22 @@ Change history ============== +2.0.0 (2024-11-??) +------------------ + +* upgrade to zgw-consumers 0.35.1 +* remove zds-client dependency + +.. warning:: + + The ``APICredential`` class has been removed in favor of the ``Service`` model from zgw-consumers + +.. warning:: + + Several notifications related models (``NotificationsConfig`` and ``Subscription``) as well as + the constants ``SCOPE_NOTIFICATIES_CONSUMEREN_LABEL`` and ``SCOPE_NOTIFICATIES_PUBLICEREN_LABEL`` have + been removed, since they are defined in ``notifications-api-common`` and were a not deleted yet in ``commonground-api-common`` + 1.13.4 (2024-10-25) ------------------- diff --git a/README.rst b/README.rst index 629264b9..f4c47747 100644 --- a/README.rst +++ b/README.rst @@ -35,9 +35,6 @@ Features * ``UniekeIdentificatieValidator`` (in combinatie met organisatie) * ``InformatieObjectUniqueValidator`` om te valideren dat M2M entries slechts eenmalig voorkomen - * ``ObjectInformatieObjectValidator`` om te valideren dat de synchronisatie - van een object-informatieobject relatie pas kan nadat deze relatie in het - DRC gemaakt is * ``IsImmutableValidator`` - valideer dat bepaalde velden niet gewijzigd worden bij een (partial) update, maar wel mogen gezet worden bij een create * ``ResourceValidator`` - valideer dat een URL een bepaalde resource ontsluit diff --git a/docs/ref/client.rst b/docs/ref/client.rst index f3a2dc75..da71db64 100644 --- a/docs/ref/client.rst +++ b/docs/ref/client.rst @@ -5,8 +5,8 @@ Obtaining a client Internally, the `APIClient`_ client is used to resolve remote API objects. To allow the `APIClient`_ to correctly, e.g use correct credentials for authentication , an `Service`_ instance is required with a matching `api_root`. This replaces -the previous mechanism to use `APICredentials` for this purpose. A data migration -will be performed to migrate `APICredentials` to the `Service`_ model. +the previous mechanism to use `APICredentials` for this purpose. A transition from `APICredentials` to +the `Service`_ model is performed automatically with the data migration. .. _APIClient: https://ape-pie.readthedocs.io/en/stable/reference.html#apiclient-class diff --git a/vng_api_common/authorizations/migrations/0017_alter_authorizationsconfig_authorizations_api_service.py b/vng_api_common/authorizations/migrations/0017_alter_authorizationsconfig_authorizations_api_service.py new file mode 100644 index 00000000..057e73cb --- /dev/null +++ b/vng_api_common/authorizations/migrations/0017_alter_authorizationsconfig_authorizations_api_service.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.15 on 2024-11-14 13:30 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("zgw_consumers", "0022_set_default_service_slug"), + ("authorizations", "0016_remove_authorizationsconfig_api_root_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="authorizationsconfig", + name="authorizations_api_service", + field=models.ForeignKey( + limit_choices_to={"api_type": "ac", "auth_type": "zgw"}, + on_delete=django.db.models.deletion.PROTECT, + to="zgw_consumers.service", + verbose_name="autorisations api service", + ), + ), + ] diff --git a/vng_api_common/authorizations/models.py b/vng_api_common/authorizations/models.py index ee18e6f1..2f22df4f 100644 --- a/vng_api_common/authorizations/models.py +++ b/vng_api_common/authorizations/models.py @@ -37,9 +37,7 @@ class AuthorizationsConfig(SingletonModel): auth_type=AuthTypes.zgw, ), verbose_name=_("autorisations api service"), - on_delete=models.SET_NULL, - blank=True, - null=True, + on_delete=models.PROTECT, ) objects = AuthorizationsConfigManager() diff --git a/vng_api_common/utils.py b/vng_api_common/utils.py index d6df5c64..0207c1bc 100644 --- a/vng_api_common/utils.py +++ b/vng_api_common/utils.py @@ -12,11 +12,8 @@ from django.utils.encoding import smart_str from django.utils.module_loading import import_string -from requests import RequestException from rest_framework.utils import formatting -from .client import get_client, to_internal_data - try: from djangorestframework_camel_case.util import ( underscore_to_camel as _underscore_to_camel, diff --git a/vng_api_common/validators.py b/vng_api_common/validators.py index 1e3b5034..5bdd74af 100644 --- a/vng_api_common/validators.py +++ b/vng_api_common/validators.py @@ -11,10 +11,8 @@ from django.utils.module_loading import import_string from django.utils.translation import gettext_lazy as _ -import requests from rest_framework import serializers, validators -from .client import get_client, to_internal_data from .constants import RSIN_LENGTH from .oas import fetcher, obj_has_shape @@ -221,49 +219,6 @@ def __call__(self, informatieobject: str, serializer): super().__call__(attrs) -class ObjectInformatieObjectValidator: - """ - Validate that the INFORMATIEOBJECT is linked already in the DRC. - """ - - message = _( - "Het informatieobject is in het DRC nog niet gerelateerd aan dit object." - ) - code = "inconsistent-relation" - requires_context = True - - def __call__(self, informatieobject: str, serializer): - object_url = serializer.context["parent_object"].get_absolute_api_url( - self.request - ) - - # dynamic so that it can be mocked in tests easily - client = get_client(informatieobject) - - if not client: - raise ValidationError( - _("Geen service geconfigureerd voor %s") % informatieobject - ) - - try: - response = client.get( - "objectinformatieobject", - params={ - "informatieobject": informatieobject, - "object": object_url, - }, - ) - - oios = to_internal_data(response) - except (requests.RequestException, RuntimeError) as exc: - raise serializers.ValidationError( - exc.args[0], code="relation-validation-error" - ) from exc - - if len(oios) == 0: - raise serializers.ValidationError(self.message, code=self.code) - - @deconstructible class UntilNowValidator: """