oarepo-runtime 1.5.96__py3-none-any.whl → 1.5.98__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.
oarepo_runtime/ext.py CHANGED
@@ -33,7 +33,7 @@ class OARepoRuntime(object):
33
33
  @cached_property
34
34
  def rdm_excluded_components(self):
35
35
  return [
36
- obj_or_import_string(x) for x in self.app.config.get("RDM_EXLUDED_COMPONENTS", [])
36
+ obj_or_import_string(x) for x in self.app.config.get("RDM_EXCLUDED_COMPONENTS", [])
37
37
  ]
38
38
 
39
39
  def init_config(self, app):
@@ -80,6 +80,11 @@ class ReadOnlyPermissionPolicy(RecordPermissionPolicy):
80
80
  can_add_community = [SystemProcess()]
81
81
  can_remove_community = [SystemProcess()]
82
82
 
83
+ can_read_deleted = [SystemProcess()]
84
+ can_manage_record_access = [SystemProcess()]
85
+ can_lift_embargo = [SystemProcess()]
86
+
87
+
83
88
 
84
89
  class EveryonePermissionPolicy(RecordPermissionPolicy):
85
90
  """record policy for read only repository"""
@@ -119,12 +124,17 @@ class EveryonePermissionPolicy(RecordPermissionPolicy):
119
124
  can_add_community = [SystemProcess(), AnyUser()]
120
125
  can_remove_community = [SystemProcess(), AnyUser()]
121
126
 
127
+ can_read_deleted = [SystemProcess(), AnyUser()]
128
+ can_manage_record_access = [SystemProcess(), AnyUser()]
129
+ can_lift_embargo = [SystemProcess(), AnyUser()]
130
+
122
131
 
123
132
  class AuthenticatedPermissionPolicy(RecordPermissionPolicy):
124
133
  """record policy for read only repository"""
125
134
 
126
135
  can_search = [SystemProcess(), AuthenticatedUser()]
127
136
  can_read = [SystemProcess(), AnyUser()]
137
+ can_read_deleted = [SystemProcess(), AnyUser()]
128
138
  can_create = [SystemProcess(), AuthenticatedUser()]
129
139
  can_update = [SystemProcess(), AuthenticatedUser()]
130
140
  can_delete = [SystemProcess(), AuthenticatedUser()]
@@ -136,7 +146,6 @@ class AuthenticatedPermissionPolicy(RecordPermissionPolicy):
136
146
  can_commit_files = [SystemProcess(), AuthenticatedUser()]
137
147
  can_read_files = [SystemProcess(), AnyUser()]
138
148
  can_update_files = [SystemProcess(), AuthenticatedUser()]
139
- can_delete_files = [SystemProcess(), AuthenticatedUser()]
140
149
  can_list_files = [SystemProcess(), AuthenticatedUser()]
141
150
  can_manage_files = [SystemProcess(), AuthenticatedUser()]
142
151
 
@@ -157,3 +166,7 @@ class AuthenticatedPermissionPolicy(RecordPermissionPolicy):
157
166
 
158
167
  can_add_community = [SystemProcess(), AuthenticatedUser()]
159
168
  can_remove_community = [SystemProcess(), AuthenticatedUser()]
169
+
170
+ can_delete_files = [SystemProcess(), AuthenticatedUser()]
171
+ can_manage_record_access = [SystemProcess(), AuthenticatedUser()]
172
+ can_lift_embargo = [SystemProcess(), AuthenticatedUser()]
@@ -121,6 +121,9 @@ def prepare_parent_mapping(parent_class, config):
121
121
  if not parent_class:
122
122
  return
123
123
 
124
+ if not config.record_cls.index._name:
125
+ return
126
+
124
127
  script_dir = str(Path(__file__).resolve().parent)
125
128
  path_parts = script_dir.split('/')
126
129
  path_parts = path_parts[:-2]
@@ -1,5 +1,7 @@
1
1
  import copy
2
2
  import logging
3
+ import operator
4
+ from functools import partial, reduce
3
5
  from typing import List
4
6
 
5
7
  from flask import current_app
@@ -8,6 +10,12 @@ from invenio_access.permissions import system_user_id
8
10
  from invenio_app.helpers import obj_or_import_string
9
11
  from invenio_records_resources.services.records.facets import FacetsResponse
10
12
  from invenio_records_resources.services.records.params import FacetsParam
13
+ from invenio_access.permissions import authenticated_user
14
+ from invenio_records_resources.services.records.params.base import ParamInterpreter
15
+ from invenio_search.engine import dsl
16
+ from invenio_rdm_records.records.systemfields.deletion_status import (
17
+ RecordDeletionStatusEnum,
18
+ )
11
19
 
12
20
  log = logging.getLogger(__name__)
13
21
 
@@ -96,7 +104,7 @@ class GroupedFacetsParam(FacetsParam):
96
104
  for f in filters[1:]:
97
105
  _filter &= f
98
106
 
99
- return search.filter(_filter)
107
+ return search.filter(_filter).post_filter(_filter)
100
108
 
101
109
  def apply(self, identity, search, params):
102
110
  """Evaluate the facets on the search."""
@@ -129,3 +137,56 @@ class GroupedFacetsParam(FacetsParam):
129
137
  for group in groups:
130
138
  user_facets.update(self.facet_groups.get(group, {}))
131
139
  return user_facets
140
+
141
+
142
+ class OARepoAllVersionsParam(ParamInterpreter):
143
+ """Evaluates the 'allversions' parameter."""
144
+ def __init__(self, field_names, config):
145
+ """Construct."""
146
+ self.field_names = field_names
147
+ super().__init__(config)
148
+
149
+ @classmethod
150
+ def factory(cls, field_names: list[str]):
151
+ """Create a new filter parameter."""
152
+ return partial(cls, field_names)
153
+
154
+ def apply(self, identity, search, params):
155
+ """Evaluate the allversions parameter on the search."""
156
+ if not params.get("allversions"):
157
+ queries = [dsl.query.Q("term", **{field_name: True}) for field_name in self.field_names]
158
+ query = reduce(operator.or_, queries)
159
+ search = search.filter(query)
160
+ return search
161
+
162
+ class OARepoPublishedRecordsParam(ParamInterpreter):
163
+ """Evaluates the include_deleted parameter."""
164
+
165
+ def apply(self, identity, search, params):
166
+ """Evaluate the include_deleted parameter on the search."""
167
+
168
+ value = params.pop("include_deleted", None)
169
+ # Filter prevents from displaying deleted records on mainsite search
170
+ # deleted records should appear only in admins panel
171
+ if value is None:
172
+ query = dsl.query.Q(
173
+ "bool",
174
+ should=[
175
+ dsl.query.Q(
176
+ "bool",
177
+ must=[
178
+ dsl.query.Q(
179
+ "term",
180
+ deletion_status=RecordDeletionStatusEnum.PUBLISHED.value,
181
+ )
182
+ ],
183
+ ),
184
+ # Drafts does not have deletion_status so this clause is needed to
185
+ # prevent the above clause from filtering out the drafts
186
+ dsl.query.Q(
187
+ "bool", must_not=[dsl.query.Q("exists", field="deletion_status")]
188
+ ),
189
+ ],
190
+ )
191
+ search = search.filter(query)
192
+ return search
@@ -10,6 +10,7 @@ from invenio_records_resources.proxies import current_service_registry
10
10
  from invenio_records_resources.services.records import (
11
11
  SearchOptions as InvenioSearchOptions,
12
12
  )
13
+ from invenio_drafts_resources.services.records.config import SearchDraftsOptions as InvenioSearchDraftsOptions
13
14
  from invenio_records_resources.services.records.params import (
14
15
  FacetsParam,
15
16
  PaginationParam,
@@ -18,14 +19,16 @@ from invenio_records_resources.services.records.params import (
18
19
  )
19
20
  from invenio_records_resources.services.records.queryparser import SuggestQueryParser
20
21
  from invenio_search.engine import dsl
21
-
22
+ from invenio_drafts_resources.services.records.search_params import AllVersionsParam
22
23
  # TODO: integrate this to invenio_records_resources.services.records and remove SearchOptions class
23
24
  from oarepo_runtime.i18n import lazy_gettext as _
24
25
  from oarepo_runtime.records.systemfields.icu import ICUSuggestField
25
26
  from oarepo_runtime.utils.functools import class_property
26
27
 
27
- from .facets.params import GroupedFacetsParam
28
-
28
+ from .facets.params import GroupedFacetsParam, OARepoAllVersionsParam, OARepoPublishedRecordsParam
29
+ from invenio_drafts_resources.services.records.search_params import AllVersionsParam
30
+ from invenio_rdm_records.services.search_params import PublishedRecordsParam
31
+ from functools import partial
29
32
  try:
30
33
  from invenio_i18n import get_locale
31
34
  except ImportError:
@@ -57,11 +60,19 @@ class SearchOptionsMixin:
57
60
  @class_property
58
61
  def params_interpreters_cls(cls):
59
62
  """Replaces FacetsParam with GroupedFacetsParam."""
63
+ params_replace_map = {FacetsParam: GroupedFacetsParam, AllVersionsParam:
64
+ OARepoAllVersionsParam.factory(["versions.is_latest", "versions.is_latest_draft"]),
65
+ PublishedRecordsParam: OARepoPublishedRecordsParam}
66
+
60
67
  param_interpreters = [*super(SearchOptionsMixin, cls).params_interpreters_cls]
61
68
  # replace FacetsParam with GroupedFacetsParam
62
69
  for idx, interpreter in enumerate(param_interpreters):
63
- if interpreter == FacetsParam:
64
- param_interpreters[idx] = GroupedFacetsParam
70
+ if interpreter in params_replace_map:
71
+ param_interpreters[idx] = params_replace_map[interpreter]
72
+ elif isinstance(interpreter, partial):
73
+ fn = interpreter.func
74
+ if fn in params_replace_map:
75
+ param_interpreters[idx] = params_replace_map[fn]
65
76
  return param_interpreters
66
77
 
67
78
  sort_options = {
@@ -113,6 +124,7 @@ class SearchOptionsDraftMixin(SearchOptionsMixin):
113
124
  }
114
125
 
115
126
 
127
+
116
128
  class SearchOptions(SearchOptionsMixin, InvenioSearchOptions):
117
129
  # TODO: should be changed
118
130
  params_interpreters_cls = [
@@ -122,6 +134,16 @@ class SearchOptions(SearchOptionsMixin, InvenioSearchOptions):
122
134
  GroupedFacetsParam,
123
135
  ]
124
136
 
137
+ class SearchDraftsOptions(SearchOptionsMixin, InvenioSearchDraftsOptions):
138
+ # TODO: should be changed
139
+ params_interpreters_cls = [
140
+ QueryStrParam,
141
+ PaginationParam,
142
+ SortParam,
143
+ GroupedFacetsParam,
144
+ AllVersionsParam.factory("versions.is_latest_draft")
145
+ ]
146
+
125
147
 
126
148
  class RDMSearchOptions(SearchOptionsMixin, BaseRDMSearchOptions):
127
149
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: oarepo-runtime
3
- Version: 1.5.96
3
+ Version: 1.5.98
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -1,5 +1,5 @@
1
1
  oarepo_runtime/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- oarepo_runtime/ext.py,sha256=IK08T5hMdI6Wouh_6PsfhgfJ3cv1JCSR3aip7vrQ9Xk,2564
2
+ oarepo_runtime/ext.py,sha256=6w6bpTpNjjj3txgVu0nfpmPa9CnDS6Zl6U2DCNs9Usc,2565
3
3
  oarepo_runtime/ext_config.py,sha256=NiXqgag3QJABf06r5NiDYjd9AvoYoRY9UWiplo8Vcg4,2056
4
4
  oarepo_runtime/profile.py,sha256=QzrQoZncjoN74ZZnpkEKakNk08KCzBU7m6y42RN8AMY,1637
5
5
  oarepo_runtime/proxies.py,sha256=NN_WNj1xuKc-OveoZmzvTFlUonNjSmLIGsv_JUcHGls,285
@@ -76,13 +76,13 @@ oarepo_runtime/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
76
76
  oarepo_runtime/services/components.py,sha256=QKrdFmroE1hSrRjRkqinynCTb0KSqBhytTb9FoY0OEE,11023
77
77
  oarepo_runtime/services/generators.py,sha256=j87HitHA_w2awsz0C5IAAJ0qjg9JMtvdO3dvh6FQyfg,250
78
78
  oarepo_runtime/services/results.py,sha256=Ap2mUJHl3V4BSduTrBWPuco0inQVq0QsuCbVhez48uY,5705
79
- oarepo_runtime/services/search.py,sha256=mUycojDo26p54ZZPqXcXmdhUrzAP_eKCWls2XYJSM6c,8186
79
+ oarepo_runtime/services/search.py,sha256=t0WEe2VrbCzZ06-Jgz7C9-pc9y27BqAgTEXldEHskfk,9409
80
80
  oarepo_runtime/services/config/__init__.py,sha256=559w4vphVAipa420OwTsxGUP-b7idoqSIX13FSJyVz0,783
81
81
  oarepo_runtime/services/config/link_conditions.py,sha256=evPRd5XU76Ok4J-08bBfplbHZ019rl74FpJmO8iM5yg,3298
82
- oarepo_runtime/services/config/permissions_presets.py,sha256=YF99Vjh1fGqSEXNw7qIfcUQFvzpE54_BafqkO6wlYHk,6668
82
+ oarepo_runtime/services/config/permissions_presets.py,sha256=jV3Ft7xFdBaeShoa3Q3Q-HHWP-wOX4XYDTRzWwUVL7g,7151
83
83
  oarepo_runtime/services/config/service.py,sha256=s-dVbGkLICpsce6jgu7b5kzYFz9opWjSQFDBgbIhKio,4002
84
84
  oarepo_runtime/services/custom_fields/__init__.py,sha256=_gqMcA_I3rdEZcBtCuDjO4wdVCqFML5NzaccuPx5a3o,2565
85
- oarepo_runtime/services/custom_fields/mappings.py,sha256=Y1d0s9lG_VThkzSNlxAS94_9eOFZe9N2C1hpYDZvnvI,7457
85
+ oarepo_runtime/services/custom_fields/mappings.py,sha256=3CIvjWzVRO3fZ2r-3taK1rwuLH9wj5Lguo-GvsbLBf4,7515
86
86
  oarepo_runtime/services/entity/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
87
87
  oarepo_runtime/services/entity/config.py,sha256=1jfdPrxSbMuKj7eOUNKRWTCPbBPyRV6MrWE4Vgf9rX0,399
88
88
  oarepo_runtime/services/entity/schema.py,sha256=8TBpUFRITaBO7qCMz36cly1Hj4I1nLa9PeSAfWSa2YM,157
@@ -97,7 +97,7 @@ oarepo_runtime/services/facets/enum.py,sha256=3LrShQIt9Vt5mkqUkc6FNxXCW5JEFdPwtG
97
97
  oarepo_runtime/services/facets/facet_groups_names.py,sha256=RR8eeUmD8d9t966JqfhslZnILn_xDSfYlL0hjyJT92Y,468
98
98
  oarepo_runtime/services/facets/max_facet.py,sha256=TZ4KMKKVJHzyU1KgNne4V7IMQPu1ALRpkz61Y0labrc,407
99
99
  oarepo_runtime/services/facets/nested_facet.py,sha256=y0xgjx37HsSj2xW7URxNemYTksD8hpPs7kOEfIBw22k,971
100
- oarepo_runtime/services/facets/params.py,sha256=IiRKbR0jIm67hucj3fINosUAysZQSSKqhusEXXub-hA,4194
100
+ oarepo_runtime/services/facets/params.py,sha256=270La-A9582aDF3D4_bMSLWv4VsPeMiqbb9jA301Q5w,6585
101
101
  oarepo_runtime/services/facets/year_histogram.py,sha256=kdfwx1lgw4UmfjdaqqeElJCB8rAduMH2hy42aZjY37w,6257
102
102
  oarepo_runtime/services/files/__init__.py,sha256=K8MStrEQf_BUhvzhwPTF93Hkhwrd1dtv35LDo7iZeTM,268
103
103
  oarepo_runtime/services/files/components.py,sha256=x6Wd-vvkqTqB1phj2a6h42DNQksN8PuR2XKaOGoNHfw,2400
@@ -135,9 +135,9 @@ tests/marshmallow_to_json/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
135
135
  tests/marshmallow_to_json/test_datacite_ui_schema.py,sha256=82iLj8nW45lZOUewpWbLX3mpSkpa9lxo-vK-Qtv_1bU,48552
136
136
  tests/marshmallow_to_json/test_simple_schema.py,sha256=izZN9p0v6kovtSZ6AdxBYmK_c6ZOti2_z_wPT_zXIr0,1500
137
137
  tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
138
- oarepo_runtime-1.5.96.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
139
- oarepo_runtime-1.5.96.dist-info/METADATA,sha256=Icnwu4HU1If11uWxVHRQWl5LFgmzmLi1w_WHD7qU8cw,4720
140
- oarepo_runtime-1.5.96.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
141
- oarepo_runtime-1.5.96.dist-info/entry_points.txt,sha256=k7O5LZUOGsVeSpB7ulU0txBUNp1CVQG7Q7TJIVTPbzU,491
142
- oarepo_runtime-1.5.96.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
143
- oarepo_runtime-1.5.96.dist-info/RECORD,,
138
+ oarepo_runtime-1.5.98.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
139
+ oarepo_runtime-1.5.98.dist-info/METADATA,sha256=sCqpqYHRhCQQsR22KVqP6s_wTAsK5Th1Lfp-LInuT24,4720
140
+ oarepo_runtime-1.5.98.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
141
+ oarepo_runtime-1.5.98.dist-info/entry_points.txt,sha256=k7O5LZUOGsVeSpB7ulU0txBUNp1CVQG7Q7TJIVTPbzU,491
142
+ oarepo_runtime-1.5.98.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
143
+ oarepo_runtime-1.5.98.dist-info/RECORD,,