diff --git a/invenio_utilities_tuw/cli/drafts.py b/invenio_utilities_tuw/cli/drafts.py index 1ae567fc8bebe39ae8bd389bee3a3c5cf8ee8060..fabf8b639c6727469a9f6efdc3bf6e075506c1de 100644 --- a/invenio_utilities_tuw/cli/drafts.py +++ b/invenio_utilities_tuw/cli/drafts.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2020 - 2021 TU Wien. +# Copyright (C) 2020 - 2025 TU Wien. # # Invenio-Utilities-TUW is free software; you can redistribute it and/or # modify it under the terms of the MIT License; see LICENSE file for more @@ -19,9 +19,10 @@ import click from flask.cli import with_appcontext from invenio_access.permissions import system_identity from invenio_db import db +from invenio_rdm_records.proxies import current_rdm_records_service as service from invenio_records_resources.services.errors import PermissionDeniedError -from ..utils import get_identity_for_user, get_record_service, get_user_by_identifier +from ..utils import get_identity_for_user, get_user_by_identifier from .options import ( option_as_user, option_owners, @@ -86,7 +87,6 @@ def drafts(): def list_drafts(user): """List all drafts accessible to the given user.""" identity = get_identity_for_user(user) - service = get_record_service() recids = [ dm.json["id"] for dm in service.draft_cls.model_cls.query.all() @@ -134,7 +134,6 @@ def create_draft(metadata_path, publish, user, owners, vanity_pid): draft, if such a subdirectory exists. """ recid = None - service = get_record_service() file_service = service.draft_files identity = get_identity_for_user(user) @@ -220,7 +219,6 @@ def show_draft(pid, pid_type, user, pretty_print, raw): """Show the stored data for the specified draft.""" pid = convert_to_recid(pid, pid_type) identity = get_identity_for_user(user) - service = get_record_service() indent = 2 if pretty_print else None draft = service.read_draft(id_=pid, identity=identity) @@ -250,7 +248,6 @@ def update_draft(metadata_file, pid, pid_type, user, patch, owners): """Update the specified draft's metadata.""" pid = convert_to_recid(pid, pid_type) identity = get_identity_for_user(user) - service = get_record_service() metadata = json.load(metadata_file) if patch: @@ -275,7 +272,6 @@ def publish_draft(pid, pid_type, user): """Publish the specified draft.""" pid = convert_to_recid(pid, pid_type) identity = get_identity_for_user(user) - service = get_record_service() service.publish(id_=pid, identity=identity) click.secho(pid, fg="green") @@ -290,7 +286,6 @@ def delete_draft(pid, pid_type, user): """Delete the specified draft.""" pid = convert_to_recid(pid, pid_type) identity = get_identity_for_user(user) - service = get_record_service() service.delete_draft(id_=pid, identity=identity) click.secho(pid, fg="red") @@ -311,7 +306,6 @@ def add_files(filepaths, pid, pid_type, user): """Add the specified files to the draft.""" recid = convert_to_recid(pid, pid_type) identity = get_identity_for_user(user) - service = get_record_service() file_service = service.draft_files draft = service.read_draft(id_=recid, identity=identity)._record @@ -385,7 +379,6 @@ def remove_files(filekeys, pid, pid_type, user): """ recid = convert_to_recid(pid, pid_type) identity = get_identity_for_user(user) - service = get_record_service() file_service = service.draft_files for file_key in filekeys: @@ -412,7 +405,6 @@ def list_files(pid, pid_type, user): """Show a list of files deposited with the draft.""" recid = convert_to_recid(pid, pid_type) identity = get_identity_for_user(user) - service = get_record_service() draft = service.read_draft(id_=recid, identity=identity)._record for name, rec_file in draft.files.entries.items(): @@ -430,7 +422,6 @@ def list_files(pid, pid_type, user): def verify_files(pid, pid_type): """Verify the checksums for each of the draft's files.""" recid = convert_to_recid(pid, pid_type) - service = get_record_service() draft = service.read_draft(id_=recid, identity=system_identity)._record num_errors = 0 @@ -469,7 +460,6 @@ def verify_files(pid, pid_type): @with_appcontext def list_stale_drafts(num_days): """List all drafts that haven't been updated for a while.""" - service = get_record_service() dc, mc = service.draft_cls, service.draft_cls.model_cls cutoff_date = datetime.utcnow() - timedelta(days=abs(num_days)) diff --git a/invenio_utilities_tuw/cli/files.py b/invenio_utilities_tuw/cli/files.py index 7282fa4605a617aff6d20322911f62a6ed09b18a..0c34563059a66de1c028613b7c925e4b5c373209 100644 --- a/invenio_utilities_tuw/cli/files.py +++ b/invenio_utilities_tuw/cli/files.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2020 - 2021 TU Wien. +# Copyright (C) 2020 - 2025 TU Wien. # # Invenio-Utilities-TUW is free software; you can redistribute it and/or # modify it under the terms of the MIT License; see LICENSE file for more @@ -17,9 +17,9 @@ from flask.cli import with_appcontext from invenio_access.permissions import system_identity from invenio_db import db from invenio_files_rest.models import FileInstance, Location, ObjectVersion +from invenio_rdm_records.proxies import current_rdm_records_service as service from sqlalchemy.exc import IntegrityError -from ..utils import get_record_service from .options import option_pid_type, option_pid_value_optional from .utils import convert_to_recid @@ -136,7 +136,6 @@ def list_deleted_files(pid, pid_type): (via its PID). """ recid = convert_to_recid(pid, pid_type) if pid else None - service = get_record_service() identity = system_identity # if a PID was specified, limit the cleaning to this record's bucket @@ -174,7 +173,6 @@ def hard_delete_files(pid, pid_type): (via its PID). """ recid = convert_to_recid(pid, pid_type) if pid else None - service = get_record_service() identity = system_identity # if a PID was specified, limit the cleaning to this record's bucket diff --git a/invenio_utilities_tuw/cli/records.py b/invenio_utilities_tuw/cli/records.py index b062a6e1c5b49afcb3191dc4914fd014bf6a8295..f13a8a23feb935a882dec8ed49bfad42815c149d 100644 --- a/invenio_utilities_tuw/cli/records.py +++ b/invenio_utilities_tuw/cli/records.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2020 - 2021 TU Wien. +# Copyright (C) 2020 - 2025 TU Wien. # # Invenio-Utilities-TUW is free software; you can redistribute it and/or # modify it under the terms of the MIT License; see LICENSE file for more @@ -14,9 +14,10 @@ import sys import click from flask.cli import with_appcontext from invenio_db import db +from invenio_rdm_records.proxies import current_rdm_records_service as service from invenio_records_resources.services.errors import PermissionDeniedError -from ..utils import get_identity_for_user, get_record_service, get_user_by_identifier +from ..utils import get_identity_for_user, get_user_by_identifier from .options import ( option_as_user, option_owners, @@ -40,7 +41,6 @@ def records(): def list_records(user): """List all records accessible to the given user.""" identity = get_identity_for_user(user) - service = get_record_service() rec_model_cls = service.record_cls.model_cls recids = [ @@ -76,7 +76,6 @@ def show_record(pid, pid_type, user, pretty_print, raw): """Show the stored data for the specified draft.""" pid = convert_to_recid(pid, pid_type) identity = get_identity_for_user(user) - service = get_record_service() indent = 2 if pretty_print else None record = service.read(id_=pid, identity=identity) @@ -116,7 +115,6 @@ def update_record(metadata_file, pid, pid_type, user, patch, owners, direct): """Update the specified draft's metadata.""" pid = convert_to_recid(pid, pid_type) identity = get_identity_for_user(user) - service = get_record_service() metadata = json.load(metadata_file) if patch: @@ -167,7 +165,6 @@ def delete_record(pid, pid_type, user): """Delete the specified record.""" identity = get_identity_for_user(user) recid = convert_to_recid(pid, pid_type) - service = get_record_service() service.delete(id_=recid, identity=identity) click.secho(recid, fg="red") @@ -187,7 +184,6 @@ def list_files(pid, pid_type, user): """Show a list of files deposited with the record.""" recid = convert_to_recid(pid, pid_type) identity = get_identity_for_user(user) - service = get_record_service() record = service.read(id_=recid, identity=identity)._record for name, rec_file in record.files.entries.items(): @@ -207,7 +203,6 @@ def verify_files(pid, pid_type, user): """Verify the checksums for each of the record's files.""" recid = convert_to_recid(pid, pid_type) identity = get_identity_for_user(user) - service = get_record_service() record = service.read(id_=recid, identity=identity)._record num_errors = 0 @@ -240,8 +235,6 @@ def verify_files(pid, pid_type, user): @with_appcontext def reindex_records(pids, pid_type): """Reindex all available (or just the specified) records.""" - service = get_record_service() - if pids: records = [ service.record_cls.get_record(get_object_uuid(pid, pid_type)) diff --git a/invenio_utilities_tuw/cli/utils.py b/invenio_utilities_tuw/cli/utils.py index 8fee151bffd3548ceead252eff3e67ced994199f..59c4fb04e1d6fe6b9a7d4da9cd86be80fe052b08 100644 --- a/invenio_utilities_tuw/cli/utils.py +++ b/invenio_utilities_tuw/cli/utils.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2020 - 2021 TU Wien. +# Copyright (C) 2020 - 2025 TU Wien. # # Invenio-Utilities-TUW is free software; you can redistribute it and/or # modify it under the terms of the MIT License; see LICENSE file for more @@ -14,8 +14,7 @@ from collections.abc import Iterable from invenio_db import db from invenio_pidstore.errors import PIDAlreadyExists from invenio_pidstore.models import PersistentIdentifier - -from ..utils import get_record_service +from invenio_rdm_records.proxies import current_rdm_records_service as service def read_metadata(metadata_file_path): @@ -34,8 +33,6 @@ def create_record_from_metadata( metadata, identity, vanity_pid=None, vanity_pid_type="recid" ): """Create a draft from the specified metadata.""" - service = get_record_service() - if vanity_pid is not None: # check if the vanity PID is already taken, before doing anything stupid count = PersistentIdentifier.query.filter_by( diff --git a/invenio_utilities_tuw/config.py b/invenio_utilities_tuw/config.py index 190958f7f99145c84eae8b78e64ca7591c46ae2c..b272ed71c5810891edbbc0d2098e780aa9589cc3 100644 --- a/invenio_utilities_tuw/config.py +++ b/invenio_utilities_tuw/config.py @@ -1,20 +1,9 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2020 - 2021 TU Wien. +# Copyright (C) 2020 - 2025 TU Wien. # # Invenio-Utilities-TUW is free software; you can redistribute it and/or # modify it under the terms of the MIT License; see LICENSE file for more # details. """Configuration for Invenio-Utilities-TUW.""" - -from invenio_rdm_records.proxies import current_rdm_records - - -def default_record_service_factory(): - """Return ``current_rdm_records.records_service.``""" - return current_rdm_records.records_service - - -UTILITIES_TUW_RECORD_SERVICE_FACTORY = default_record_service_factory -"""Factory function for creating a RecordService.""" diff --git a/invenio_utilities_tuw/utils.py b/invenio_utilities_tuw/utils.py index 6fcf4d8a5bef8e5beffc5ffb94272f99a2feeb23..7a84f6e66359fe57c87456d2fe2f504c537da914 100644 --- a/invenio_utilities_tuw/utils.py +++ b/invenio_utilities_tuw/utils.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2020 - 2021 TU Wien. +# Copyright (C) 2020 - 2025 TU Wien. # # Invenio-Utilities-TUW is free software; you can redistribute it and/or # modify it under the terms of the MIT License; see LICENSE file for more @@ -10,14 +10,11 @@ from difflib import SequenceMatcher -from flask import current_app from invenio_access.permissions import any_user, system_identity from invenio_access.utils import get_identity from invenio_accounts import current_accounts from werkzeug.utils import import_string -from .config import default_record_service_factory - def get_or_import(value, default=None): """Try an import if value is an endpoint string, or return value itself.""" @@ -29,18 +26,6 @@ def get_or_import(value, default=None): return default -def get_record_service(): - """Get the configured RecordService.""" - factory = current_app.config.get("UTILITIES_TUW_RECORD_SERVICE_FACTORY", None) - - if factory is not None: - factory = get_or_import(factory) - else: - factory = default_record_service_factory - - return factory() - - def get_user_by_identifier(id_or_email): """Get the user specified via email or ID.""" if id_or_email is not None: