|
| 1 | +#!/usr/bin/env python |
| 2 | +import sys |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import django |
| 6 | + |
| 7 | +from tabulate import tabulate |
| 8 | + |
| 9 | +SRC_DIR = Path(__file__).parent.parent / "src" |
| 10 | +sys.path.insert(0, str(SRC_DIR.resolve())) |
| 11 | + |
| 12 | + |
| 13 | +def check_for_null_services_in_api_groups(): |
| 14 | + from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig |
| 15 | + from openforms.registrations.contrib.zgw_apis.models import ZGWApiGroupConfig |
| 16 | + |
| 17 | + problems: list[tuple[str, int, str, str]] = [] |
| 18 | + |
| 19 | + objects_groups = ObjectsAPIGroupConfig.objects.exclude( |
| 20 | + objects_service__isnull=False, |
| 21 | + objecttypes_service__isnull=False, |
| 22 | + ).values_list("id", "name", "objects_service_id", "objecttypes_service_id") |
| 23 | + |
| 24 | + for pk, name, objects_service_id, objecttypes_service_id in objects_groups: |
| 25 | + problem = ("Objects API", pk, name) |
| 26 | + if objects_service_id is None: |
| 27 | + problems.append((*problem, "No objects service configured")) |
| 28 | + if objecttypes_service_id is None: |
| 29 | + problems.append((*problem, "No object types service configured")) |
| 30 | + |
| 31 | + zgw_groups = ZGWApiGroupConfig.objects.exclude( |
| 32 | + zrc_service__isnull=False, |
| 33 | + drc_service__isnull=False, |
| 34 | + ztc_service__isnull=False, |
| 35 | + ).values_list( |
| 36 | + "id", |
| 37 | + "name", |
| 38 | + "zrc_service_id", |
| 39 | + "drc_service_id", |
| 40 | + "ztc_service_id", |
| 41 | + ) |
| 42 | + for pk, name, zrc_service_id, drc_service_id, ztc_service_id in zgw_groups: |
| 43 | + problem = ("ZGW APIs", pk, name) |
| 44 | + if zrc_service_id is None: |
| 45 | + problems.append((*problem, "No Zaken API service configured")) |
| 46 | + if drc_service_id is None: |
| 47 | + problems.append((*problem, "No Documenten API service configured")) |
| 48 | + if ztc_service_id is None: |
| 49 | + problems.append((*problem, "No Catalogi API service configured")) |
| 50 | + |
| 51 | + if not problems: |
| 52 | + return False |
| 53 | + |
| 54 | + print( |
| 55 | + "Can't upgrade yet - some API group services are not properly configured yet." |
| 56 | + ) |
| 57 | + print( |
| 58 | + "Go into the admin to fix their configuration, and then try to upgrade again." |
| 59 | + ) |
| 60 | + print( |
| 61 | + tabulate( |
| 62 | + problems, |
| 63 | + headers=("API group type", "ID", "Name", "Problem"), |
| 64 | + ) |
| 65 | + ) |
| 66 | + return True |
| 67 | + |
| 68 | + |
| 69 | +def main(skip_setup=False) -> bool: |
| 70 | + from openforms.setup import setup_env |
| 71 | + |
| 72 | + if not skip_setup: |
| 73 | + setup_env() |
| 74 | + django.setup() |
| 75 | + |
| 76 | + return check_for_null_services_in_api_groups() |
| 77 | + |
| 78 | + |
| 79 | +if __name__ == "__main__": |
| 80 | + main() |
0 commit comments