oarepo-runtime 1.5.75__py3-none-any.whl → 1.5.77__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.
@@ -48,7 +48,6 @@ def get_record_service_for_record_deprecated(record):
48
48
  if service_record == type(record):
49
49
  return svc
50
50
 
51
-
52
51
  def get_file_service_for_record_class(record_class):
53
52
  if not record_class:
54
53
  return None
@@ -60,6 +59,9 @@ def get_file_service_for_record_class(record_class):
60
59
  continue
61
60
  return svc
62
61
 
62
+ def get_file_service_for_file_record_class(file_record_class):
63
+ record_class = file_record_class.record_cls
64
+ return get_file_service_for_record_class(record_class)
63
65
 
64
66
  def get_file_service_for_record_service(
65
67
  record_service, check_draft_files=True, record=None
@@ -1,5 +1,6 @@
1
1
  from typing import Type
2
2
 
3
+ from deprecated import deprecated
3
4
  from invenio_records_resources.records import Record
4
5
 
5
6
 
@@ -11,20 +12,39 @@ def select_record_for_update(record_cls: Type[Record], persistent_identifier):
11
12
  return record_cls(obj.data, model=obj)
12
13
 
13
14
 
14
- def is_published_record(record, ctx):
15
- """Shortcut for links to determine if record is a published record."""
16
- return not getattr(record, "is_draft", False)
15
+ @deprecated("Moved to oarepo_runtime.services.config.link_conditions")
16
+ def is_published_record_function():
17
+ """Shortcut for links to determine if record is a published.
17
18
 
19
+ This function is deprecated. Use oarepo_runtime.services.config.is_published_record instead.
20
+ """
21
+ from oarepo_runtime.services.config.link_conditions import is_published_record
18
22
 
19
- def is_draft_record(record, ctx):
20
- """Shortcut for links to determine if record is a draft record."""
21
- return getattr(record, "is_draft", False)
23
+ return is_published_record()
22
24
 
23
25
 
24
- def has_draft(record, ctx):
25
- """Shortcut for links to determine if record is either a draft or a published one with a draft associated."""
26
- if getattr(record, "is_draft", False):
27
- return True
28
- if getattr(record, "has_draft", False):
29
- return True
30
- return False
26
+ @deprecated("Moved to oarepo_runtime.services.config.link_conditions")
27
+ def is_draft_record_function():
28
+ """Shortcut for links to determine if record is a draft record.
29
+
30
+ This function is deprecated. Use oarepo_runtime.services.config.is_draft_record instead.
31
+ """
32
+ from oarepo_runtime.services.config.link_conditions import is_draft_record
33
+
34
+ return is_draft_record()
35
+
36
+
37
+ @deprecated("Moved to oarepo_runtime.services.config.link_conditions")
38
+ def has_draft_function():
39
+ """Shortcut for links to determine if record is either a draft or a published one with a draft associated.
40
+
41
+ This function is deprecated. Use oarepo_runtime.services.config.has_draft instead.
42
+ """
43
+ from oarepo_runtime.services.config.link_conditions import has_draft
44
+
45
+ return has_draft()
46
+
47
+
48
+ is_published_record = is_published_record_function()
49
+ is_draft = is_draft_record_function()
50
+ has_draft = has_draft_function()
@@ -1,3 +1,11 @@
1
+ from .link_conditions import (
2
+ has_draft,
3
+ has_permission,
4
+ has_permission_file_service,
5
+ has_published_record,
6
+ is_draft_record,
7
+ is_published_record,
8
+ )
1
9
  from .permissions_presets import (
2
10
  AuthenticatedPermissionPolicy,
3
11
  EveryonePermissionPolicy,
@@ -12,4 +20,10 @@ __all__ = (
12
20
  "ReadOnlyPermissionPolicy",
13
21
  "EveryonePermissionPolicy",
14
22
  "AuthenticatedPermissionPolicy",
23
+ "is_published_record",
24
+ "is_draft_record",
25
+ "has_draft",
26
+ "has_permission",
27
+ "has_permission_file_service",
28
+ "has_published_record",
15
29
  )
@@ -0,0 +1,101 @@
1
+ from abc import abstractmethod
2
+
3
+ from invenio_pidstore.errors import PIDDoesNotExistError, PIDUnregistered
4
+ from invenio_records_resources.records.api import FileRecord
5
+ from invenio_records.api import RecordBase
6
+ from invenio_records_resources.records.api import Record
7
+ from logging import getLogger
8
+ from ...datastreams.utils import (
9
+ get_file_service_for_file_record_class,
10
+ get_file_service_for_record_class,
11
+ get_record_service_for_record,
12
+ )
13
+ log = getLogger(__name__)
14
+
15
+ class Condition:
16
+
17
+ @abstractmethod
18
+ def __call__(self, obj, ctx: dict):
19
+ raise NotImplementedError
20
+
21
+ def __and__(self, other):
22
+ return type(
23
+ "CompositeCondition",
24
+ (Condition,),
25
+ {"__call__": lambda _, obj, ctx: self(obj, ctx) and other(obj, ctx)},
26
+ )()
27
+
28
+ def __or__(self, other):
29
+ return type(
30
+ "CompositeCondition",
31
+ (Condition,),
32
+ {"__call__": lambda _, obj, ctx: self(obj, ctx) or other(obj, ctx)},
33
+ )()
34
+
35
+
36
+ class is_published_record(Condition):
37
+ """Shortcut for links to determine if record is a published record."""
38
+
39
+ def __call__(self, obj: Record, ctx: dict):
40
+ return not getattr(obj, "is_draft", False)
41
+
42
+
43
+ class is_draft_record(Condition):
44
+ """Shortcut for links to determine if record is a draft record."""
45
+
46
+ def __call__(self, obj: Record, ctx: dict):
47
+ return getattr(obj, "is_draft", False)
48
+
49
+
50
+ class has_draft(Condition):
51
+ """Shortcut for links to determine if record is either a draft or a published one with a draft associated."""
52
+
53
+ def __call__(self, obj: Record, ctx: dict):
54
+ if getattr(obj, "is_draft", False):
55
+ return True
56
+ if getattr(obj, "has_draft", False):
57
+ return True
58
+ return False
59
+
60
+
61
+ class has_permission(Condition):
62
+ def __init__(self, action_name):
63
+ self.action_name = action_name
64
+
65
+ def __call__(self, obj: RecordBase, ctx: dict):
66
+ if isinstance(obj, FileRecord):
67
+ obj = obj.record
68
+ service = get_record_service_for_record(obj)
69
+ try:
70
+ return service.check_permission(
71
+ action_name=self.action_name, record=obj, **ctx
72
+ )
73
+ except Exception as e:
74
+ log.exception(f"Unexpected exception {e}.")
75
+
76
+
77
+
78
+ class has_permission_file_service(has_permission):
79
+
80
+ def __call__(self, obj: RecordBase, ctx: dict):
81
+ if isinstance(obj, FileRecord):
82
+ service = get_file_service_for_file_record_class(type(obj))
83
+ else:
84
+ service = get_file_service_for_record_class(type(obj))
85
+ try:
86
+ return service.check_permission(
87
+ action_name=self.action_name, record=obj, **ctx
88
+ )
89
+ except Exception as e:
90
+ log.exception(f"Unexpected exception {e}.")
91
+
92
+
93
+ class has_published_record(Condition):
94
+
95
+ def __call__(self, obj: Record, ctx: dict):
96
+ service = get_record_service_for_record(obj)
97
+ try:
98
+ service.record_cls.pid.resolve(obj["id"])
99
+ except (PIDUnregistered, PIDDoesNotExistError):
100
+ return False
101
+ return True
@@ -31,6 +31,7 @@ class OaiHarvesterPermissionPolicy(RecordPermissionPolicy):
31
31
  can_update_draft = [SystemProcess()]
32
32
  can_delete_draft = [SystemProcess()]
33
33
  can_publish = [SystemProcess()]
34
+ can_search_versions = [SystemProcess()]
34
35
  can_draft_create_files = [SystemProcess()]
35
36
  can_draft_set_content_files = [SystemProcess()]
36
37
  can_draft_get_content_files = [SystemProcess()]
@@ -39,6 +40,7 @@ class OaiHarvesterPermissionPolicy(RecordPermissionPolicy):
39
40
  can_draft_update_files = [SystemProcess()]
40
41
 
41
42
 
43
+
42
44
  class ReadOnlyPermissionPolicy(RecordPermissionPolicy):
43
45
  """record policy for read only repository"""
44
46
 
@@ -56,6 +58,7 @@ class ReadOnlyPermissionPolicy(RecordPermissionPolicy):
56
58
  can_read_files = [AnyUser(), SystemProcess()]
57
59
  can_update_files = [SystemProcess()]
58
60
  can_delete_files = [SystemProcess()]
61
+ can_list_files = [SystemProcess()]
59
62
 
60
63
  can_edit = [SystemProcess()]
61
64
  can_new_version = [SystemProcess()]
@@ -64,6 +67,7 @@ class ReadOnlyPermissionPolicy(RecordPermissionPolicy):
64
67
  can_update_draft = [SystemProcess()]
65
68
  can_delete_draft = [SystemProcess()]
66
69
  can_publish = [SystemProcess()]
70
+ can_search_versions = [SystemProcess()]
67
71
  can_draft_create_files = [SystemProcess()]
68
72
  can_draft_set_content_files = [SystemProcess()]
69
73
  can_draft_get_content_files = [SystemProcess()]
@@ -92,11 +96,13 @@ class EveryonePermissionPolicy(RecordPermissionPolicy):
92
96
  can_read_files = [SystemProcess(), AnyUser()]
93
97
  can_update_files = [SystemProcess(), AnyUser()]
94
98
  can_delete_files = [SystemProcess(), AnyUser()]
99
+ can_list_files = [SystemProcess(), AnyUser()]
95
100
 
96
101
  can_edit = [SystemProcess(), AnyUser()]
97
102
  can_new_version = [SystemProcess(), AnyUser()]
98
103
  can_search_drafts = [SystemProcess(), AnyUser()]
99
104
  can_read_draft = [SystemProcess(), AnyUser()]
105
+ can_search_versions = [SystemProcess(), AnyUser()]
100
106
  can_update_draft = [SystemProcess(), AnyUser()]
101
107
  can_delete_draft = [SystemProcess(), AnyUser()]
102
108
  can_publish = [SystemProcess(), AnyUser()]
@@ -128,6 +134,7 @@ class AuthenticatedPermissionPolicy(RecordPermissionPolicy):
128
134
  can_read_files = [SystemProcess(), AnyUser()]
129
135
  can_update_files = [SystemProcess(), AuthenticatedUser()]
130
136
  can_delete_files = [SystemProcess(), AuthenticatedUser()]
137
+ can_list_files = [SystemProcess(), AuthenticatedUser()]
131
138
 
132
139
  can_edit = [SystemProcess(), AuthenticatedUser()]
133
140
  can_new_version = [SystemProcess(), AuthenticatedUser()]
@@ -136,6 +143,7 @@ class AuthenticatedPermissionPolicy(RecordPermissionPolicy):
136
143
  can_update_draft = [SystemProcess(), AuthenticatedUser()]
137
144
  can_delete_draft = [SystemProcess(), AuthenticatedUser()]
138
145
  can_publish = [SystemProcess(), AuthenticatedUser()]
146
+ can_search_versions = [SystemProcess(), AuthenticatedUser()]
139
147
  can_draft_create_files = [SystemProcess(), AuthenticatedUser()]
140
148
  can_draft_set_content_files = [SystemProcess(), AuthenticatedUser()]
141
149
  can_draft_get_content_files = [SystemProcess(), AuthenticatedUser()]
@@ -114,7 +114,12 @@ class RecordList(BaseRecordList):
114
114
  record=record,
115
115
  ),
116
116
  )
117
- if self._links_item_tpl:
117
+ if hasattr(self._service.config, "links_search_item"):
118
+ links_tpl = self._service.config.search_item_links_template(
119
+ self._service.config.links_search_item
120
+ )
121
+ projection["links"] = links_tpl.expand(self._identity, record)
122
+ elif self._links_item_tpl:
118
123
  projection["links"] = self._links_item_tpl.expand(
119
124
  self._identity, record
120
125
  )
@@ -122,7 +127,7 @@ class RecordList(BaseRecordList):
122
127
  for c in self.components:
123
128
  c.update_data(
124
129
  identity=self._identity,
125
- record=self._record,
130
+ record=record,
126
131
  projection=projection,
127
132
  expand=self._expand,
128
133
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.75
3
+ Version: 1.5.77
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -26,7 +26,7 @@ oarepo_runtime/datastreams/semi_asynchronous.py,sha256=kNc6BBnV6oFoY9kHgf5l8fd1w
26
26
  oarepo_runtime/datastreams/synchronous.py,sha256=t5lfnMkLqy3jK5zMl-nIuA0HlMPiHGjwCqZ8XQP-3GM,2595
27
27
  oarepo_runtime/datastreams/transformers.py,sha256=q5KzHPl2kJg7HP1BtKJ7F_UMqg_7L1ZGDX0O7s8D6UI,521
28
28
  oarepo_runtime/datastreams/types.py,sha256=KZjblc3T_UFFW7LrMDmiR8lqVf86V484LAHj6yg05EI,9908
29
- oarepo_runtime/datastreams/utils.py,sha256=WvYwvCnmS0vrcQ-Fbptu-GvBTMx_8UVhUqs_-BN-p-E,4111
29
+ oarepo_runtime/datastreams/utils.py,sha256=w24qRRw1ZawPFbgqtxhpYnxPnghSn0pp49JLLy8wTms,4280
30
30
  oarepo_runtime/datastreams/readers/__init__.py,sha256=P1n3llZQ3AFHnSPbeT1VaCJcEtRFz9AbHfjkZv5LG7s,1103
31
31
  oarepo_runtime/datastreams/readers/attachments.py,sha256=A7EC1TqyTHG-go5DIaRotlBSOm6o9hGqAKyVVAceCRU,1956
32
32
  oarepo_runtime/datastreams/readers/excel.py,sha256=CM8lr8mejN7NgoK5TJb1oXpjq0HxklQKMsuj3uqjTjA,3653
@@ -44,7 +44,7 @@ oarepo_runtime/i18n/__init__.py,sha256=h0knW_HwiyIt5TBHfdGqN7_BBYfpz1Fw6zhVy0C28
44
44
  oarepo_runtime/info/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
45
  oarepo_runtime/info/check.py,sha256=6O5Wjsdorx4eqiBiPU3z33XhCiwPTO_FGkzMDK7UH6I,3049
46
46
  oarepo_runtime/info/views.py,sha256=q9PG46aM-1ihaVxJGjfcD5HvJWanM28gMefao8FIQk4,12440
47
- oarepo_runtime/records/__init__.py,sha256=3vzRsAPxl4d5QOnGyls-vUg4E6PunmR4ACObtacMAIQ,1038
47
+ oarepo_runtime/records/__init__.py,sha256=JUf9_o09_6q4vuG43JzhSeTu7c-m_CVDSmgTQ7epYEo,1776
48
48
  oarepo_runtime/records/dumpers/__init__.py,sha256=OmzNhLdMNKibmCksnj9eTX9xPBG30dziiK3j3bAAp3k,233
49
49
  oarepo_runtime/records/dumpers/edtf_interval.py,sha256=YCShZAoqBQYaxVilEVotS-jXZsxxoXO67yu2urhkaMA,1198
50
50
  oarepo_runtime/records/dumpers/multilingual_dumper.py,sha256=PbNFCLsiH4XV3E1v8xga_fzlcEImHy8OXn_UKh_8VBU,1090
@@ -73,10 +73,11 @@ oarepo_runtime/resources/localized_ui_json_serializer.py,sha256=3V9cJaG_e1PMXKVX
73
73
  oarepo_runtime/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
74
  oarepo_runtime/services/components.py,sha256=k--zu1RinwoKzg5qHp4H-Ddp9AFyjMJ97fydQ0DvI-A,4238
75
75
  oarepo_runtime/services/generators.py,sha256=j87HitHA_w2awsz0C5IAAJ0qjg9JMtvdO3dvh6FQyfg,250
76
- oarepo_runtime/services/results.py,sha256=HVBEPAMFwwCJDqBhaP3t3ekH1CpNDtE6ovVNKgWxuw8,5409
76
+ oarepo_runtime/services/results.py,sha256=Ap2mUJHl3V4BSduTrBWPuco0inQVq0QsuCbVhez48uY,5705
77
77
  oarepo_runtime/services/search.py,sha256=9xGTN5Yg6eTdptQ9qjO_umbacf9ooMuHYGXWYfla4-M,6227
78
- oarepo_runtime/services/config/__init__.py,sha256=dtlD84pJ6xI77UF22IPrCOt7tHD3g5DAEDApUdjDVFE,406
79
- oarepo_runtime/services/config/permissions_presets.py,sha256=zApeA-2DYAlD--SzVz3vq_OFjq48Ko0pe08e4o2vxr4,6114
78
+ oarepo_runtime/services/config/__init__.py,sha256=EOpmlw0rjAUGmErTRcLOOBADeXKJKdsk62lAgFbRKQ8,731
79
+ oarepo_runtime/services/config/link_conditions.py,sha256=xCusAqc7zqh0EGu2f6CF84ImyYHvzEKIOmLQYpyewzE,3113
80
+ oarepo_runtime/services/config/permissions_presets.py,sha256=V0dMrikzTzTiM2NRtdGgTML7AtXlrlYZ_vm3btzbJd4,6472
80
81
  oarepo_runtime/services/config/service.py,sha256=s-dVbGkLICpsce6jgu7b5kzYFz9opWjSQFDBgbIhKio,4002
81
82
  oarepo_runtime/services/custom_fields/__init__.py,sha256=_gqMcA_I3rdEZcBtCuDjO4wdVCqFML5NzaccuPx5a3o,2565
82
83
  oarepo_runtime/services/custom_fields/mappings.py,sha256=tg9CAdxGOkd_n6RB5Z2_wSwo_A0wqEey8RMcZ79AHo0,6906
@@ -132,9 +133,9 @@ tests/marshmallow_to_json/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
132
133
  tests/marshmallow_to_json/test_datacite_ui_schema.py,sha256=82iLj8nW45lZOUewpWbLX3mpSkpa9lxo-vK-Qtv_1bU,48552
133
134
  tests/marshmallow_to_json/test_simple_schema.py,sha256=izZN9p0v6kovtSZ6AdxBYmK_c6ZOti2_z_wPT_zXIr0,1500
134
135
  tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
135
- oarepo_runtime-1.5.75.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
136
- oarepo_runtime-1.5.75.dist-info/METADATA,sha256=hd71O2EzxcURIGg7qgV2G41KUG1ZBaoazG-lox_VHMw,4720
137
- oarepo_runtime-1.5.75.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
138
- oarepo_runtime-1.5.75.dist-info/entry_points.txt,sha256=k7O5LZUOGsVeSpB7ulU0txBUNp1CVQG7Q7TJIVTPbzU,491
139
- oarepo_runtime-1.5.75.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
140
- oarepo_runtime-1.5.75.dist-info/RECORD,,
136
+ oarepo_runtime-1.5.77.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
137
+ oarepo_runtime-1.5.77.dist-info/METADATA,sha256=zTSdUbRgidqR57Pu8hNATAZPLbTdJ4Qr0UABAVaAtZc,4720
138
+ oarepo_runtime-1.5.77.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
139
+ oarepo_runtime-1.5.77.dist-info/entry_points.txt,sha256=k7O5LZUOGsVeSpB7ulU0txBUNp1CVQG7Q7TJIVTPbzU,491
140
+ oarepo_runtime-1.5.77.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
141
+ oarepo_runtime-1.5.77.dist-info/RECORD,,