oarepo-runtime 1.5.26__py3-none-any.whl → 1.5.28__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
 
@@ -1,3 +1,42 @@
1
1
  from .polymorphic import PolymorphicSchema
2
2
 
3
- __all__ = ("PolymorphicSchema",)
3
+
4
+ def consistent_resolution(*classes):
5
+ """
6
+ A helper function to solve resolution order of classes.
7
+ If the classes are in a correct mro order, it will return
8
+ them in the same order. Otherwise it will try to reorder
9
+ them and remove those that are already contained in mro
10
+ of others.
11
+ """
12
+
13
+ # remove classes that are already in mro of others
14
+ filtered_classes = []
15
+ for cls in classes:
16
+ for other_cls in classes:
17
+ if cls != other_cls and issubclass(other_cls, cls):
18
+ break
19
+ else:
20
+ if cls not in filtered_classes:
21
+ filtered_classes.append(cls)
22
+
23
+ name = [cls.__name__ for cls in filtered_classes]
24
+ name = "".join(name) + "ConsistentResolution"
25
+ try:
26
+ return type(name, tuple(filtered_classes), {})
27
+ except TypeError:
28
+ pass
29
+
30
+ filtered_classes.sort(key=lambda cls: -len(cls.mro()))
31
+ try:
32
+ return type(name, tuple(filtered_classes), {})
33
+ except TypeError:
34
+ pass
35
+
36
+ bases = ", ".join(cls.__name__ for cls in filtered_classes)
37
+ orig_bases = ", ".join(cls.__name__ for cls in classes)
38
+ raise TypeError(f"Cannot create a consistent method resolution order (MRO) "
39
+ f"for bases {orig_bases}, tried {bases}")
40
+
41
+
42
+ __all__ = ("PolymorphicSchema", "consistent_resolution")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.26
3
+ Version: 1.5.28
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -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=bN054QERsMAvkyqVoyPCZYI5D4KajAK8cqK-jtlK6lQ,4402
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=UlvRcgQObm3HfULPwDi_QFh1uzLvZSGKNns-GgnGRQ0,8468
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
@@ -94,7 +94,7 @@ oarepo_runtime/services/relations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeR
94
94
  oarepo_runtime/services/relations/components.py,sha256=3g0VdnGUM-2yYt50fPi-OADReBGJb4h05vmYHfh-QFs,592
95
95
  oarepo_runtime/services/relations/errors.py,sha256=VtlOKq9MEUeJ4IsiZhY7lWoshrusA_RL4SOHe2titno,552
96
96
  oarepo_runtime/services/relations/mapping.py,sha256=D7IYk83SXVgTv-0ohSnHOCzvCwbFLXJsayO1eQfQn0U,1285
97
- oarepo_runtime/services/schema/__init__.py,sha256=XGfNjYk7ha5JhVERuqjl-yDaI1O9dDQItZJEdMzDe4w,77
97
+ oarepo_runtime/services/schema/__init__.py,sha256=gD0II1Lz6fnW1Cgt4gtneZeyKWl_YZ47Wu0gmeKqtH8,1395
98
98
  oarepo_runtime/services/schema/cf.py,sha256=-m9seIH5VYUdxDsJlPVXS0-8f7xkpN7YfW1q9E1GacI,475
99
99
  oarepo_runtime/services/schema/i18n.py,sha256=myyg0tU8up0BmMt9IESKD91w5KC0V9v8Qa-9fF0ptIs,1341
100
100
  oarepo_runtime/services/schema/i18n_ui.py,sha256=18tA6uA067TP_wcit47hTel2M4hz88wYtwBgaeZDrew,1880
@@ -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.26.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
118
- oarepo_runtime-1.5.26.dist-info/METADATA,sha256=P2aE9x8lip8a2G-51JG4-6fCo7sHsXIxsTQKcDBvqIA,4680
119
- oarepo_runtime-1.5.26.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
120
- oarepo_runtime-1.5.26.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
121
- oarepo_runtime-1.5.26.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
122
- oarepo_runtime-1.5.26.dist-info/RECORD,,
117
+ oarepo_runtime-1.5.28.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
118
+ oarepo_runtime-1.5.28.dist-info/METADATA,sha256=ck-L-b49r3ffcCAjvGjsUxW173E2ay8T_-sx7q1LYkY,4680
119
+ oarepo_runtime-1.5.28.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
120
+ oarepo_runtime-1.5.28.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
121
+ oarepo_runtime-1.5.28.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
122
+ oarepo_runtime-1.5.28.dist-info/RECORD,,