From 4c7073e351b8082d198b35c8af862d753fbb6de7 Mon Sep 17 00:00:00 2001 From: Florian Spreckelsen <f.spreckelsen@indiscale.com> Date: Fri, 24 Jan 2025 15:06:02 +0100 Subject: [PATCH] ENH: Add container-upload post processing --- .../container_update_post_processing.py | 33 +++++++++++++++++++ .../scripting/bin/update_containers.py | 9 ++--- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 sample-management-custom/caosdb-server/scripting/bin/sample_helpers/container_update_post_processing.py diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/container_update_post_processing.py b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/container_update_post_processing.py new file mode 100644 index 0000000..e8f696b --- /dev/null +++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/container_update_post_processing.py @@ -0,0 +1,33 @@ +# +# Copyright (C) 2025 Indiscale GmbH <info@indiscale.com> +# Copyright (C) 2025 Florian Spreckelsen <f.spreckelsen@indiscale.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +import linkahead as db + + +def post_process_containers_before_sync(child_containers): + + return child_containers + + +def post_process_parent_containers_before_sync(parent_containers): + + return parent_containers + + +def post_process_inserts_and_updates(inserts, updates): + + return inserts, updates diff --git a/sample-management-custom/caosdb-server/scripting/bin/update_containers.py b/sample-management-custom/caosdb-server/scripting/bin/update_containers.py index 4739d5c..44c6c73 100755 --- a/sample-management-custom/caosdb-server/scripting/bin/update_containers.py +++ b/sample-management-custom/caosdb-server/scripting/bin/update_containers.py @@ -37,6 +37,7 @@ from linkahead.cached import cached_query, cached_get_entity_by from bis_utils import (get_do_not_insert_type_names, replace_entity_urls_by_ids, whitespace_cleanup_in_df) from sample_helpers.container_update_get_parent import get_container_by_identifier +from sample_helpers.container_update_post_processing import (post_process_containers_before_sync, post_process_parent_containers_before_sync, post_process_inserts_and_updates) from sample_helpers.utils import (CONSTANTS, get_column_header_name, get_entity_name) # suppress warning of diff function @@ -287,6 +288,8 @@ def main(): parent_containers.remove(par) # TODO Add notes as CommentAnnotation crawler = Crawler(securityMode=SecurityMode.UPDATE) + child_containers = post_process_containers_before_sync(child_containers) + parent_containers = post_process_parent_containers_before_sync(parent_containers) to_be_synchronized = child_containers + parent_containers inserts, updates = crawler.synchronize( @@ -296,10 +299,8 @@ def main(): if "SHARED_DIR" in os.environ: _notify_about_inserts_and_updates(len(inserts), len(updates), htmluserlog_public, crawler.run_id) - for ent in inserts + updates: - ent.retrieve_acl() - ent.grant(role='Stock Manager', priority=False, permission="EDIT:ACL") - ent.update_acl() + inserts, updates = post_process_inserts_and_updates(isnerts, updates) + logger.info(f"Successfully processed {len(child_containers)} containers and " f"{len(parent_containers)} parent containers.") -- GitLab