-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4916 from open-formulieren/cleanup/3283-make-fiel…
…ds-not-nullable 💥 Make service FKs in API group config models not nullable
- Loading branch information
Showing
19 changed files
with
215 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
from pathlib import Path | ||
|
||
import django | ||
|
||
from tabulate import tabulate | ||
|
||
SRC_DIR = Path(__file__).parent.parent / "src" | ||
sys.path.insert(0, str(SRC_DIR.resolve())) | ||
|
||
|
||
def check_for_null_services_in_api_groups(): | ||
from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig | ||
from openforms.registrations.contrib.zgw_apis.models import ZGWApiGroupConfig | ||
|
||
problems: list[tuple[str, int, str, str]] = [] | ||
|
||
objects_groups = ObjectsAPIGroupConfig.objects.exclude( | ||
objects_service__isnull=False, | ||
objecttypes_service__isnull=False, | ||
).values_list("id", "name", "objects_service_id", "objecttypes_service_id") | ||
|
||
for pk, name, objects_service_id, objecttypes_service_id in objects_groups: | ||
problem = ("Objects API", pk, name) | ||
if objects_service_id is None: | ||
problems.append((*problem, "No objects service configured")) | ||
if objecttypes_service_id is None: | ||
problems.append((*problem, "No object types service configured")) | ||
|
||
zgw_groups = ZGWApiGroupConfig.objects.exclude( | ||
zrc_service__isnull=False, | ||
drc_service__isnull=False, | ||
ztc_service__isnull=False, | ||
).values_list( | ||
"id", | ||
"name", | ||
"zrc_service_id", | ||
"drc_service_id", | ||
"ztc_service_id", | ||
) | ||
for pk, name, zrc_service_id, drc_service_id, ztc_service_id in zgw_groups: | ||
problem = ("ZGW APIs", pk, name) | ||
if zrc_service_id is None: | ||
problems.append((*problem, "No Zaken API service configured")) | ||
if drc_service_id is None: | ||
problems.append((*problem, "No Documenten API service configured")) | ||
if ztc_service_id is None: | ||
problems.append((*problem, "No Catalogi API service configured")) | ||
|
||
if not problems: | ||
return False | ||
|
||
print( | ||
"Can't upgrade yet - some API group services are not properly configured yet." | ||
) | ||
print( | ||
"Go into the admin to fix their configuration, and then try to upgrade again." | ||
) | ||
print( | ||
tabulate( | ||
problems, | ||
headers=("API group type", "ID", "Name", "Problem"), | ||
) | ||
) | ||
return True | ||
|
||
|
||
def main(skip_setup=False) -> bool: | ||
from openforms.setup import setup_env | ||
|
||
if not skip_setup: | ||
setup_env() | ||
django.setup() | ||
|
||
return check_for_null_services_in_api_groups() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ntrib/objects_api/migrations/0004_alter_objectsapigroupconfig_objects_service_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Generated by Django 4.2.17 on 2024-12-12 22:40 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("zgw_consumers", "0022_set_default_service_slug"), | ||
("objects_api", "0003_objectsapigroupconfig_identifier_unique"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="objectsapigroupconfig", | ||
name="objects_service", | ||
field=models.ForeignKey( | ||
limit_choices_to={"api_type": "orc"}, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="+", | ||
to="zgw_consumers.service", | ||
verbose_name="Objects API", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="objectsapigroupconfig", | ||
name="objecttypes_service", | ||
field=models.ForeignKey( | ||
limit_choices_to={"api_type": "orc"}, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="+", | ||
to="zgw_consumers.service", | ||
verbose_name="Objecttypes API", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.