oarepo-runtime 1.5.27__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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.27
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
@@ -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.27.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
118
- oarepo_runtime-1.5.27.dist-info/METADATA,sha256=eoNvUBPIChZDm5WvR3uWxNa8dnww3jjZqEHLOsZ11go,4680
119
- oarepo_runtime-1.5.27.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
120
- oarepo_runtime-1.5.27.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
121
- oarepo_runtime-1.5.27.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
122
- oarepo_runtime-1.5.27.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,,