oarepo-runtime 1.5.25__py3-none-any.whl → 1.5.27__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,14 @@
1
1
  from invenio_accounts.models import User
2
+
3
+ from oarepo_runtime.services.generators import RecordOwners
4
+
2
5
  try:
3
6
  from invenio_drafts_resources.services.records.uow import ParentRecordCommitOp
4
7
  except ImportError:
5
- from invenio_records_resources.services.uow import RecordCommitOp as ParentRecordCommitOp
8
+ from invenio_records_resources.services.uow import (
9
+ RecordCommitOp as ParentRecordCommitOp,
10
+ )
11
+
6
12
  from invenio_records_resources.services.records.components import ServiceComponent
7
13
 
8
14
 
@@ -12,16 +18,26 @@ class OwnersComponent(ServiceComponent):
12
18
  self.add_owner(identity, record)
13
19
 
14
20
  def add_owner(self, identity, record, commit=False):
21
+ if not hasattr(identity, "id") or not isinstance(identity.id, int):
22
+ return
23
+
15
24
  owners = getattr(record.parent, "owners", None)
16
25
  if owners is not None:
17
26
  user = User.query.filter_by(id=identity.id).first()
18
27
  record.parent.owners.add(user)
19
28
  if commit:
20
29
  self.uow.register(ParentRecordCommitOp(record.parent))
30
+
21
31
  def update(self, identity, *, record, **kwargs):
22
32
  """Update handler."""
23
33
  self.add_owner(identity, record, commit=True)
24
34
 
25
35
  def update_draft(self, identity, *, record, **kwargs):
26
36
  """Update handler."""
27
- self.add_owner(identity, record, commit=True)
37
+ self.add_owner(identity, record, commit=True)
38
+
39
+ def search_drafts(self, identity, search, params, **kwargs):
40
+ new_term = RecordOwners().query_filter(identity)
41
+ if new_term:
42
+ return search.filter(new_term)
43
+ return search
@@ -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.25
3
+ Version: 1.5.27
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -68,7 +68,7 @@ oarepo_runtime/resources/__init__.py,sha256=v8BGrOTu_FjKzd0eozV7Q4GoGxyfybsL2cI-
68
68
  oarepo_runtime/resources/file_resource.py,sha256=Ta3bFce7l0xwqkkOMOEu9mxbB8BbKj5HUHRHmidhnl8,414
69
69
  oarepo_runtime/resources/localized_ui_json_serializer.py,sha256=4Kle34k-_uu3Y9JJ2vAXcQ9DqYRxXgy-_iZhiFuukmE,1684
70
70
  oarepo_runtime/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
71
- oarepo_runtime/services/components.py,sha256=Wu-UAQR3AYtne9ZNaHen7hWI9fDdwVEjcHND3_gbeSw,1119
71
+ oarepo_runtime/services/components.py,sha256=9wt9CmoCFA8Utbb8eNA-Mvzo5LCApHT9zHpWIWZNyXY,1506
72
72
  oarepo_runtime/services/generators.py,sha256=V582uA813AIXnFhzqUwakmDgBOI1SQe3XZeJtUXNbwM,872
73
73
  oarepo_runtime/services/results.py,sha256=F3A0U3MRUOYlxNglJPQeGMKdD8QNq1il106jQZ0c9gQ,1499
74
74
  oarepo_runtime/services/search.py,sha256=ywfwGH7oAM44WeOSjlIsY_qoCMZJ1TlTLd_NgE2ow3Y,5296
@@ -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.25.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
118
- oarepo_runtime-1.5.25.dist-info/METADATA,sha256=NP21eoZqbsqPigc8QEHotGZS83vb9qtlWPXoKvrWo80,4680
119
- oarepo_runtime-1.5.25.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
120
- oarepo_runtime-1.5.25.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
121
- oarepo_runtime-1.5.25.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
122
- oarepo_runtime-1.5.25.dist-info/RECORD,,
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,,