oarepo-runtime 1.5.27__py3-none-any.whl → 1.5.29__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- oarepo_runtime/cli/fixtures.py +26 -0
- oarepo_runtime/datastreams/fixtures.py +7 -2
- oarepo_runtime/resources/localized_ui_json_serializer.py +10 -5
- {oarepo_runtime-1.5.27.dist-info → oarepo_runtime-1.5.29.dist-info}/METADATA +1 -1
- {oarepo_runtime-1.5.27.dist-info → oarepo_runtime-1.5.29.dist-info}/RECORD +9 -9
- {oarepo_runtime-1.5.27.dist-info → oarepo_runtime-1.5.29.dist-info}/LICENSE +0 -0
- {oarepo_runtime-1.5.27.dist-info → oarepo_runtime-1.5.29.dist-info}/WHEEL +0 -0
- {oarepo_runtime-1.5.27.dist-info → oarepo_runtime-1.5.29.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.5.27.dist-info → oarepo_runtime-1.5.29.dist-info}/top_level.txt +0 -0
oarepo_runtime/cli/fixtures.py
CHANGED
@@ -2,6 +2,10 @@ import click
|
|
2
2
|
import tqdm
|
3
3
|
from flask import current_app
|
4
4
|
from flask.cli import with_appcontext
|
5
|
+
from flask_login import login_user
|
6
|
+
from flask_principal import Identity, identity_changed, identity_loaded, UserNeed, RoleNeed
|
7
|
+
from invenio_access.permissions import system_identity, any_user, authenticated_user
|
8
|
+
from invenio_accounts.models import User
|
5
9
|
|
6
10
|
from oarepo_runtime.cli import oarepo
|
7
11
|
from oarepo_runtime.datastreams import SynchronousDataStream
|
@@ -35,6 +39,7 @@ def fixtures():
|
|
35
39
|
"will be committed in a single transaction and indexed together",
|
36
40
|
)
|
37
41
|
@click.option("--batch-size", help="Alias for --bulk-size", type=int)
|
42
|
+
@click.option("--identity", help="Email of the identity that will be used to import the data")
|
38
43
|
@with_appcontext
|
39
44
|
def load(
|
40
45
|
fixture_dir=None,
|
@@ -45,6 +50,7 @@ def load(
|
|
45
50
|
bulk_size=100,
|
46
51
|
on_background=False,
|
47
52
|
batch_size=None,
|
53
|
+
identity=None
|
48
54
|
):
|
49
55
|
"""Loads fixtures"""
|
50
56
|
if batch_size:
|
@@ -57,7 +63,26 @@ def load(
|
|
57
63
|
if fixture_dir:
|
58
64
|
system_fixtures = False
|
59
65
|
|
66
|
+
if not identity:
|
67
|
+
user = None
|
68
|
+
identity = system_identity
|
69
|
+
else:
|
70
|
+
# identity is user email
|
71
|
+
user = User.query.filter_by(email=identity).one()
|
72
|
+
identity = Identity(user.id)
|
73
|
+
|
74
|
+
# TODO: add provides. How to do it better? It seems that we can not use
|
75
|
+
# flask signals to add these, as they depend on request context that is
|
76
|
+
# not available here
|
77
|
+
identity.provides.add(any_user)
|
78
|
+
identity.provides.add(authenticated_user)
|
79
|
+
identity.provides.add(UserNeed(user.id))
|
80
|
+
for role in getattr(user, 'roles', []):
|
81
|
+
identity.provides.add(RoleNeed(role.name))
|
82
|
+
# TODO: community roles ...
|
83
|
+
|
60
84
|
with current_app.wsgi_app.mounts["/api"].app_context():
|
85
|
+
|
61
86
|
load_fixtures(
|
62
87
|
fixture_dir,
|
63
88
|
_make_list(include),
|
@@ -68,6 +93,7 @@ def load(
|
|
68
93
|
datastreams_impl=(
|
69
94
|
AsynchronousDataStream if on_background else SynchronousDataStream
|
70
95
|
),
|
96
|
+
identity=identity
|
71
97
|
)
|
72
98
|
if not on_background:
|
73
99
|
_show_stats(callback, "Load fixtures")
|
@@ -6,6 +6,7 @@ import pkg_resources
|
|
6
6
|
import yaml
|
7
7
|
from celery import shared_task
|
8
8
|
from flask import current_app
|
9
|
+
from invenio_access.permissions import system_identity
|
9
10
|
from invenio_records_resources.proxies import current_service_registry
|
10
11
|
|
11
12
|
from oarepo_runtime.datastreams import (
|
@@ -34,6 +35,7 @@ def load_fixtures(
|
|
34
35
|
callback: FixturesCallback = None,
|
35
36
|
batch_size=100,
|
36
37
|
datastreams_impl=SynchronousDataStream,
|
38
|
+
identity=system_identity
|
37
39
|
):
|
38
40
|
"""
|
39
41
|
Loads fixtures. If fixture dir is set, fixtures are loaded from that directory first.
|
@@ -62,6 +64,7 @@ def load_fixtures(
|
|
62
64
|
callback,
|
63
65
|
batch_size=batch_size,
|
64
66
|
datastreams_impl=datastreams_impl,
|
67
|
+
identity=identity
|
65
68
|
)
|
66
69
|
|
67
70
|
if system_fixtures:
|
@@ -91,11 +94,13 @@ def load_fixtures(
|
|
91
94
|
callback,
|
92
95
|
batch_size=batch_size,
|
93
96
|
datastreams_impl=datastreams_impl,
|
97
|
+
identity=identity
|
94
98
|
)
|
95
99
|
|
96
100
|
|
97
101
|
def _load_fixtures_from_catalogue(
|
98
|
-
catalogue, fixtures, include, exclude, callback, batch_size, datastreams_impl
|
102
|
+
catalogue, fixtures, include, exclude, callback, batch_size, datastreams_impl,
|
103
|
+
identity=system_identity
|
99
104
|
):
|
100
105
|
for catalogue_datastream in catalogue.get_datastreams():
|
101
106
|
if catalogue_datastream.stream_name in fixtures:
|
@@ -118,7 +123,7 @@ def _load_fixtures_from_catalogue(
|
|
118
123
|
callback=callback,
|
119
124
|
batch_size=batch_size,
|
120
125
|
)
|
121
|
-
datastream.process()
|
126
|
+
datastream.process(identity=identity)
|
122
127
|
if hasattr(callback, "fixture_finished"):
|
123
128
|
callback.fixture_finished(catalogue_datastream.stream_name)
|
124
129
|
|
@@ -27,13 +27,15 @@ class LocalizedUIJSONSerializer(MarshmallowSerializer):
|
|
27
27
|
self.object_schema_cls = object_schema_cls
|
28
28
|
self.list_schema_cls = list_schema_cls
|
29
29
|
|
30
|
-
def dump_obj(self, obj):
|
30
|
+
def dump_obj(self, obj, *args, **kwargs):
|
31
31
|
"""Dump the object using object schema class."""
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
ctx = {**self.schema_context, "locale": get_locale()}
|
33
|
+
if "extra_context" in kwargs:
|
34
|
+
ctx |= kwargs["extra_context"]
|
35
35
|
|
36
|
-
|
36
|
+
return self.object_schema_cls(context=ctx).dump(obj)
|
37
|
+
|
38
|
+
def dump_list(self, obj_list, *args, **kwargs):
|
37
39
|
"""Dump the list of objects."""
|
38
40
|
ctx = {
|
39
41
|
"object_schema_cls": self.object_schema_cls,
|
@@ -41,6 +43,9 @@ class LocalizedUIJSONSerializer(MarshmallowSerializer):
|
|
41
43
|
ctx.update(self.schema_context)
|
42
44
|
ctx["locale"] = get_locale()
|
43
45
|
|
46
|
+
if "extra_context" in kwargs:
|
47
|
+
ctx |= kwargs["extra_context"]
|
48
|
+
|
44
49
|
if self.list_schema_cls is None:
|
45
50
|
return self.object_schema_cls(context=self.schema_context).dump(
|
46
51
|
obj_list, many=True
|
@@ -10,7 +10,7 @@ oarepo_runtime/cli/base.py,sha256=94RBTa8TOSPxEyEUmYLGXaWen-XktP2-MIbTtZSlCZo,54
|
|
10
10
|
oarepo_runtime/cli/cf.py,sha256=W0JEJK2JqKubQw8qtZJxohmADDRUBode4JZAqYLDGvc,339
|
11
11
|
oarepo_runtime/cli/check.py,sha256=AvC5VHAnwmtCd8R-Caj8v6nCAREKjObTdNtLJ24aJO8,4935
|
12
12
|
oarepo_runtime/cli/configuration.py,sha256=cLXoGDtjuA5uv9ZfYFcH0C4wcadj0qWC3P_E4Bf5-z0,1061
|
13
|
-
oarepo_runtime/cli/fixtures.py,sha256=
|
13
|
+
oarepo_runtime/cli/fixtures.py,sha256=teMbU-ocrSOmmCJvK-ICl6lMTAOWxJ5Tpkg6JQc0Y0s,5486
|
14
14
|
oarepo_runtime/cli/index.py,sha256=H4nSZnClnlCSI8Thlz_jx-uPpgNVVQyagpWIPtQoIr4,7239
|
15
15
|
oarepo_runtime/cli/validate.py,sha256=HpSvHQCGHlrdgdpKix9cIlzlBoJEiT1vACZdMnOUGEY,2827
|
16
16
|
oarepo_runtime/datastreams/__init__.py,sha256=_i52Ek9J8DMARST0ejZAZPzUKm55xrrlKlCSO7dl6y4,1008
|
@@ -19,7 +19,7 @@ oarepo_runtime/datastreams/catalogue.py,sha256=D6leq-FPT3RP3SniEAXPm66v3q8ZdQnaU
|
|
19
19
|
oarepo_runtime/datastreams/datastreams.py,sha256=wnMk1UFv-cWXRO0jHwRNoJBO0cbZaHqrLnH7vgfnf78,4485
|
20
20
|
oarepo_runtime/datastreams/errors.py,sha256=WyZLU53EdFJTLv6K2ooM_M6ISjLS-U1dDw6B7guOLSc,1540
|
21
21
|
oarepo_runtime/datastreams/ext.py,sha256=ivugdVMCqwugK-5SeX14a-dMq6VaTt7DM2wFU357tR4,1406
|
22
|
-
oarepo_runtime/datastreams/fixtures.py,sha256=
|
22
|
+
oarepo_runtime/datastreams/fixtures.py,sha256=hKV3BuIK7TzfOsNPM8VR9qkBAeDLyLOhafP-DZG15uI,8667
|
23
23
|
oarepo_runtime/datastreams/json.py,sha256=OAiaH93eqpH5qNQSPKKc8K-hXKAn5lB0PUKwwZFqJSw,153
|
24
24
|
oarepo_runtime/datastreams/semi_asynchronous.py,sha256=TJWby2MDKXm5feRocoWB-8OhsShq5R9HoZ74O1rGBOk,2934
|
25
25
|
oarepo_runtime/datastreams/synchronous.py,sha256=t5lfnMkLqy3jK5zMl-nIuA0HlMPiHGjwCqZ8XQP-3GM,2595
|
@@ -66,7 +66,7 @@ oarepo_runtime/records/systemfields/selectors.py,sha256=VlbV3FKP2h3PLU7H4-YsI4qr
|
|
66
66
|
oarepo_runtime/records/systemfields/synthetic.py,sha256=zRsQdekcgsrD9R2UuI2kgVLjyQMIT8j3HAYav_e-xfM,4238
|
67
67
|
oarepo_runtime/resources/__init__.py,sha256=v8BGrOTu_FjKzd0eozV7Q4GoGxyfybsL2cI-tbP5Pys,185
|
68
68
|
oarepo_runtime/resources/file_resource.py,sha256=Ta3bFce7l0xwqkkOMOEu9mxbB8BbKj5HUHRHmidhnl8,414
|
69
|
-
oarepo_runtime/resources/localized_ui_json_serializer.py,sha256=
|
69
|
+
oarepo_runtime/resources/localized_ui_json_serializer.py,sha256=3V9cJaG_e1PMXKVX_wKfBp1LmbeForwHyBNYdyha4uQ,1878
|
70
70
|
oarepo_runtime/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
71
71
|
oarepo_runtime/services/components.py,sha256=9wt9CmoCFA8Utbb8eNA-Mvzo5LCApHT9zHpWIWZNyXY,1506
|
72
72
|
oarepo_runtime/services/generators.py,sha256=V582uA813AIXnFhzqUwakmDgBOI1SQe3XZeJtUXNbwM,872
|
@@ -114,9 +114,9 @@ oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
114
114
|
oarepo_runtime/utils/functools.py,sha256=gKS9YZtlIYcDvdNA9cmYO00yjiXBYV1jg8VpcRUyQyg,1324
|
115
115
|
oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
|
116
116
|
tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
117
|
-
oarepo_runtime-1.5.
|
118
|
-
oarepo_runtime-1.5.
|
119
|
-
oarepo_runtime-1.5.
|
120
|
-
oarepo_runtime-1.5.
|
121
|
-
oarepo_runtime-1.5.
|
122
|
-
oarepo_runtime-1.5.
|
117
|
+
oarepo_runtime-1.5.29.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
118
|
+
oarepo_runtime-1.5.29.dist-info/METADATA,sha256=CGu5jtrm_4D0h-vZma0WRJdTcjL5k6jLqIR8O0aQJcs,4680
|
119
|
+
oarepo_runtime-1.5.29.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
120
|
+
oarepo_runtime-1.5.29.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
|
121
|
+
oarepo_runtime-1.5.29.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
|
122
|
+
oarepo_runtime-1.5.29.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|