From 8f168cad4ac7399c18823a97d8471dad9af1417b Mon Sep 17 00:00:00 2001 From: irinaschubert Date: Tue, 12 Apr 2022 11:48:53 +0200 Subject: [PATCH] fix(groups): dsp-tools should not allow group creation if group name already in use (DEV-798) (#183) * Fix bug * improve code --- knora/dsplib/utils/onto_create_ontology.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/knora/dsplib/utils/onto_create_ontology.py b/knora/dsplib/utils/onto_create_ontology.py index c4080b828..72a418272 100644 --- a/knora/dsplib/utils/onto_create_ontology.py +++ b/knora/dsplib/utils/onto_create_ontology.py @@ -123,13 +123,13 @@ def create_groups(con: Connection, groups: list[dict[str, str]], project: Projec # check if the group already exists, skip if so all_groups: Optional[list[Group]] = Group.getAllGroups(con) + group_exists: bool = False if all_groups: - for group_item in all_groups: - if group_item.project == project.id and group_item.name == group_name: - group_exists = True + group_exists = any(group_item.name == group_name for group_item in all_groups) + if group_exists: - print(f"WARN Group '{group_name}' already exists. Skipping...") + print(f"WARN Group name '{group_name}' already in use. Skipping...") continue # check if status is defined, set default value if not