oarepo-runtime 1.9.4__py3-none-any.whl → 1.10.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,10 @@ class OARepoDataStreamsExt:
26
26
  if inst.name not in config_classes:
27
27
  raise KeyError(f"'{inst.name}' not found in config {config_name}")
28
28
  reader_class = config_classes[inst.name]
29
- return reader_class(**(inst.kwargs or {}), **kwargs, identity=identity)
29
+ all_kwargs = {**(inst.kwargs or {}), **kwargs}
30
+ if "identity" not in all_kwargs:
31
+ all_kwargs["identity"] = identity
32
+ return reader_class(**all_kwargs)
30
33
  else:
31
34
  return inst
32
35
 
@@ -5,6 +5,7 @@ from invenio_records_resources.proxies import current_service_registry
5
5
  from invenio_records_resources.services.uow import UnitOfWork
6
6
 
7
7
  from ...uow import BulkUnitOfWork
8
+ from ...utils.identity_utils import get_user_and_identity
8
9
  from ..types import StreamBatch, StreamEntry
9
10
  from ..utils import attachments_requests, get_file_service_for_record_service
10
11
  from . import BaseWriter
@@ -35,6 +36,10 @@ class AttachmentsServiceWriter(BaseWriter):
35
36
  if isinstance(service, str):
36
37
  service = current_service_registry.get(service)
37
38
 
39
+ if isinstance(identity, str):
40
+ _, identity = get_user_and_identity(email=identity)
41
+ elif isinstance(identity, int):
42
+ _, identity = get_user_and_identity(user_id=identity)
38
43
  self._identity = identity or system_identity
39
44
  self._update = update
40
45
 
@@ -5,6 +5,8 @@ from oarepo_runtime.datastreams.types import StreamBatch, StreamEntry
5
5
  from oarepo_runtime.datastreams.writers import BaseWriter
6
6
  from oarepo_runtime.datastreams.writers.utils import record_invenio_exceptions
7
7
 
8
+ from ...utils.identity_utils import get_user_and_identity
9
+
8
10
 
9
11
  class PublishWriter(BaseWriter):
10
12
  def __init__(
@@ -20,6 +22,10 @@ class PublishWriter(BaseWriter):
20
22
  service = current_service_registry.get(service)
21
23
 
22
24
  self._service = service
25
+ if isinstance(identity, str):
26
+ _, identity = get_user_and_identity(email=identity)
27
+ elif isinstance(identity, int):
28
+ _, identity = get_user_and_identity(user_id=identity)
23
29
  self._identity = identity or system_identity
24
30
  self._request_name = request_name
25
31
  self._direct_call = direct_call
@@ -37,7 +43,7 @@ class PublishWriter(BaseWriter):
37
43
  data = self._service.publish(self._identity, entry.id)
38
44
  else:
39
45
  data = self._publish_via_request(self._identity, entry.id)
40
-
46
+
41
47
  entry.entry = data.to_dict()
42
48
 
43
49
  def _publish_via_request(self, identity, entry_id):
@@ -61,4 +67,4 @@ class PublishWriter(BaseWriter):
61
67
  identity, request.id, "accept"
62
68
  )
63
69
 
64
- return self._service.read(identity, draft["id"])
70
+ return self._service.read(identity, draft["id"])
@@ -5,6 +5,7 @@ from invenio_records_resources.services.uow import UnitOfWork
5
5
  from sqlalchemy.exc import NoResultFound
6
6
 
7
7
  from ...uow import BulkUnitOfWork
8
+ from ...utils.identity_utils import get_user_and_identity
8
9
  from ..types import StreamBatch, StreamEntry, StreamEntryError
9
10
  from . import BaseWriter
10
11
  from .utils import record_invenio_exceptions
@@ -35,6 +36,10 @@ class ServiceWriter(BaseWriter):
35
36
  service = current_service_registry.get(service)
36
37
 
37
38
  self._service = service
39
+ if isinstance(identity, str):
40
+ _, identity = get_user_and_identity(email=identity)
41
+ elif isinstance(identity, int):
42
+ _, identity = get_user_and_identity(user_id=identity)
38
43
  self._identity = identity or system_identity
39
44
  self._update = update
40
45
 
@@ -0,0 +1,27 @@
1
+ from flask import current_app
2
+ from flask_principal import Identity, UserNeed, identity_loaded
3
+ from invenio_access.models import User
4
+
5
+
6
+ def get_user_and_identity(user_id=None, username=None, email=None):
7
+ def lookup_user():
8
+ if user_id is not None:
9
+ return User.query.filter_by(id=user_id).one()
10
+ elif username is not None:
11
+ return User.query.filter_by(username=username).one()
12
+ elif email is not None:
13
+ return User.query.filter_by(email=email).one()
14
+ else:
15
+ raise ValueError(
16
+ "At least one of user_id, username, or email must be provided."
17
+ )
18
+
19
+ user = lookup_user()
20
+
21
+ identity = Identity(user.id)
22
+ identity.provides.add(UserNeed(user.id))
23
+ api_app = current_app.wsgi_app.mounts["/api"]
24
+ with api_app.app_context():
25
+ with current_app.test_request_context("/api"):
26
+ identity_loaded.send(api_app, identity=identity)
27
+ return user, identity
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oarepo-runtime
3
- Version: 1.9.4
3
+ Version: 1.10.0
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -25,7 +25,7 @@ oarepo_runtime/datastreams/asynchronous.py,sha256=JwT-Hx6P7KwV0vSJlxX6kLSIX5vtse
25
25
  oarepo_runtime/datastreams/catalogue.py,sha256=D6leq-FPT3RP3SniEAXPm66v3q8ZdQnaUYJ5XM0dIFY,5021
26
26
  oarepo_runtime/datastreams/datastreams.py,sha256=N9XXwIaBTADkPhE-XG6uotMwd-8Kn0vEZOoeV2BnMGI,4679
27
27
  oarepo_runtime/datastreams/errors.py,sha256=WyZLU53EdFJTLv6K2ooM_M6ISjLS-U1dDw6B7guOLSc,1540
28
- oarepo_runtime/datastreams/ext.py,sha256=ivugdVMCqwugK-5SeX14a-dMq6VaTt7DM2wFU357tR4,1406
28
+ oarepo_runtime/datastreams/ext.py,sha256=dLdWK45W366e9Ksmy1bOIfkIg-875kI3DroKddGkILw,1522
29
29
  oarepo_runtime/datastreams/fixtures.py,sha256=oc3b1XP7gJmEXVskZTltZUasdeTux-wbgxox66OyIT8,8901
30
30
  oarepo_runtime/datastreams/json.py,sha256=OkIkGKUawtYoGelyS5V92DVk7Ei7SlkMMny2Ue2dDWc,132
31
31
  oarepo_runtime/datastreams/semi_asynchronous.py,sha256=kNc6BBnV6oFoY9kHgf5l8fd1wibRfI0dwyzLtu4fmUA,2940
@@ -41,9 +41,9 @@ oarepo_runtime/datastreams/readers/service.py,sha256=izIMcrsUr4_qRZXHKQZs7Tyn1Op
41
41
  oarepo_runtime/datastreams/readers/yaml.py,sha256=U4nyJQ8ocM_ohp-eUN1RjVoNzYV9z7xQ1XiQKG_B9Kk,408
42
42
  oarepo_runtime/datastreams/writers/__init__.py,sha256=PWufWNrixFhXv5wSv3_pzmrimroqVB2DVgTxVtY5FCg,526
43
43
  oarepo_runtime/datastreams/writers/attachments_file.py,sha256=kV_IPAWawJ9PX-IfoncmLQXpdTbzRMsJie8uKX1vNp0,3161
44
- oarepo_runtime/datastreams/writers/attachments_service.py,sha256=g_tbjUA3YnTE5gP21zlG2kIxneZsn0q95EVjlxB8s1M,4152
45
- oarepo_runtime/datastreams/writers/publish.py,sha256=XUuYjrbLMX77eIvY7I40On8SkrwpLuh2Y4yjltANcfE,2162
46
- oarepo_runtime/datastreams/writers/service.py,sha256=8oXGG365ro_XEoZUncFltule_6TAbPPbSr-SBgcbWRA,6224
44
+ oarepo_runtime/datastreams/writers/attachments_service.py,sha256=g72781UnSgdYvYvAaDPAB_RqW9cBH7WcOOyTsICZIGY,4418
45
+ oarepo_runtime/datastreams/writers/publish.py,sha256=XHs74_1vJhE82cpImZ7MruGX4F3qN3M0I6tR8AxT7L4,2422
46
+ oarepo_runtime/datastreams/writers/service.py,sha256=IqIPk477vLVxOsFYDxAmqRkk3YuZJ7KdqOia4cFjLLw,6490
47
47
  oarepo_runtime/datastreams/writers/utils.py,sha256=Lk_ZLNeXTLuFEn04lw1-6bJ7duG6kwA8X4wf9c_GiL4,1067
48
48
  oarepo_runtime/datastreams/writers/validation_errors.py,sha256=wOCXdniR6so_4ExpdFYYgBRyENp7_6kVFZM2L-Hy3G8,661
49
49
  oarepo_runtime/datastreams/writers/yaml.py,sha256=XchUJHQ58E2Mfgs8elImXbL38jFtI8Hfoye6yaR0gKI,1482
@@ -148,15 +148,16 @@ oarepo_runtime/translations/en/LC_MESSAGES/messages.mo,sha256=tq5pTCpH7cuzdwrQlp
148
148
  oarepo_runtime/translations/en/LC_MESSAGES/messages.po,sha256=oWFA5kjT-sBNoZ3UIzYS03GQOvri5VqL9NcYnQnYsyQ,2562
149
149
  oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
150
150
  oarepo_runtime/utils/functools.py,sha256=gKS9YZtlIYcDvdNA9cmYO00yjiXBYV1jg8VpcRUyQyg,1324
151
+ oarepo_runtime/utils/identity_utils.py,sha256=88EVuhKPywR-ExG8SkE2hEkMqnnoe2AouoQ4xl6KApY,974
151
152
  oarepo_runtime/utils/index.py,sha256=ArrUUXB-KowUcUksRKqcFpmqct4bn9alO1zd_kX2tmU,292
152
153
  oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
153
- oarepo_runtime-1.9.4.dist-info/licenses/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
154
+ oarepo_runtime-1.10.0.dist-info/licenses/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
154
155
  tests/marshmallow_to_json/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
155
156
  tests/marshmallow_to_json/test_datacite_ui_schema.py,sha256=82iLj8nW45lZOUewpWbLX3mpSkpa9lxo-vK-Qtv_1bU,48552
156
157
  tests/marshmallow_to_json/test_simple_schema.py,sha256=izZN9p0v6kovtSZ6AdxBYmK_c6ZOti2_z_wPT_zXIr0,1500
157
158
  tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
158
- oarepo_runtime-1.9.4.dist-info/METADATA,sha256=CVIJjZW7XgCVhHpzqhlMe-ljTHMwsXtm4Tl3u3a1554,4788
159
- oarepo_runtime-1.9.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
160
- oarepo_runtime-1.9.4.dist-info/entry_points.txt,sha256=k7O5LZUOGsVeSpB7ulU0txBUNp1CVQG7Q7TJIVTPbzU,491
161
- oarepo_runtime-1.9.4.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
162
- oarepo_runtime-1.9.4.dist-info/RECORD,,
159
+ oarepo_runtime-1.10.0.dist-info/METADATA,sha256=72OmTjxiORWXpCk0zxKHheyRAu6lRFIPrUqDyxEWT-E,4789
160
+ oarepo_runtime-1.10.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
161
+ oarepo_runtime-1.10.0.dist-info/entry_points.txt,sha256=k7O5LZUOGsVeSpB7ulU0txBUNp1CVQG7Q7TJIVTPbzU,491
162
+ oarepo_runtime-1.10.0.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
163
+ oarepo_runtime-1.10.0.dist-info/RECORD,,