oarepo-runtime 1.5.9__py3-none-any.whl → 1.5.10__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.
@@ -1,14 +1,22 @@
1
1
  import inspect
2
+ import re
2
3
  from functools import cached_property
4
+ from typing import List, Type
3
5
 
4
6
  from flask import current_app
7
+ from invenio_records_permissions import BasePermissionPolicy
5
8
 
6
9
 
7
10
  class PermissionsPresetsConfigMixin:
8
11
  components = tuple()
12
+ PERMISSIONS_PRESETS_CONFIG_KEY = None
13
+ # PERMISSIONS_PRESETS = [] # noqa (omitted here because of the order of mixins)
9
14
 
10
15
  @cached_property
11
16
  def permission_policy_cls(self):
17
+ """
18
+ Returns a class that contains all permissions from the presets.
19
+ """
12
20
  presets = self._get_preset_classes()
13
21
 
14
22
  permissions = {}
@@ -32,12 +40,51 @@ class PermissionsPresetsConfigMixin:
32
40
  continue
33
41
  yield permission_name, permission_needs
34
42
 
35
- def _get_preset_classes(self):
43
+ def _get_preset_classes(self) -> List[Type[BasePermissionPolicy]]:
44
+ """
45
+ Returns a list of permission presets classes to be used for this service.
46
+
47
+ The list is read from the configuration, if it exists, otherwise it returns
48
+ the default value from the class attribute PERMISSIONS_PRESETS.
49
+ """
36
50
  registered_preset_classes = current_app.config["OAREPO_PERMISSIONS_PRESETS"]
37
51
  preset_classes = [
38
52
  registered_preset_classes[x]
39
- for x in self.PERMISSIONS_PRESETS # noqa (omitted here because of the order of mixins)
53
+ for x in self._get_permissions_presets()
40
54
  ]
41
55
  if hasattr(self, "base_permission_policy_cls"):
42
56
  preset_classes.insert(0, self.base_permission_policy_cls)
43
57
  return preset_classes
58
+
59
+ def _get_permissions_presets(self):
60
+ """
61
+ Returns a list of names of permissions presets to be used for this service.
62
+
63
+ The list is read from the configuration, if it exists, otherwise it returns
64
+ the default value from the class attribute PERMISSIONS_PRESETS.
65
+ """
66
+ config_key = self._get_presents_config_key()
67
+ if config_key in current_app.config:
68
+ return current_app.config[config_key]
69
+ return self.PERMISSIONS_PRESETS # noqa (omitted here because of the order of mixins)
70
+
71
+ def _get_presents_config_key(self):
72
+ """
73
+ Returns the name of the configuration key that contains the list of
74
+ permissions presets to be used for this service.
75
+
76
+ The key is read from the class attribute PERMISSIONS_PRESETS_CONFIG_KEY.
77
+ If it is not set, the key is generated from the name of the service
78
+ configuration class (MyServiceConfig becomes MY_SERVICE_PERMISSIONS_PRESETS).
79
+ """
80
+ if self.PERMISSIONS_PRESETS_CONFIG_KEY:
81
+ return self.PERMISSIONS_PRESETS_CONFIG_KEY
82
+
83
+ # use the base class of the service config file (e.g. MyServiceConfig),
84
+ # remove the "Config" part and convert it to snake uppercase.
85
+ # add "_PERMISSIONS_PRESETS" at the end.
86
+ name = type(self).__name__
87
+ if name.endswith("Config"):
88
+ name = name[:-6]
89
+ name = re.sub(r'(?<!^)(?=[A-Z])', '_', name).upper()
90
+ return f"{name}_PERMISSIONS_PRESETS"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.9
3
+ Version: 1.5.10
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/services/results.py,sha256=DsBPniwhNvOkYucS8Z0v3EC28LemY7JuZNVhl_
68
68
  oarepo_runtime/services/search.py,sha256=ywfwGH7oAM44WeOSjlIsY_qoCMZJ1TlTLd_NgE2ow3Y,5296
69
69
  oarepo_runtime/services/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
70
70
  oarepo_runtime/services/config/permissions_presets.py,sha256=zApeA-2DYAlD--SzVz3vq_OFjq48Ko0pe08e4o2vxr4,6114
71
- oarepo_runtime/services/config/service.py,sha256=Uzo3rJGWljbkLcWd-E1BJOEglJHli8eUSIgFTJt9sXE,1566
71
+ oarepo_runtime/services/config/service.py,sha256=7U-iC5Or51-T2tvWkB6WHQJ0tNVcyEKQutT1Ldl2I7w,3648
72
72
  oarepo_runtime/services/custom_fields/__init__.py,sha256=xJ7XEyMJHPfIgX5JKpgpwh7SYc9Zee2dC5oC8cm99Qc,2282
73
73
  oarepo_runtime/services/custom_fields/mappings.py,sha256=1mb8nYeUlQxbBolsKURGKUIpIV1NDb-7Mcur32jjIjg,4433
74
74
  oarepo_runtime/services/expansions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -108,9 +108,9 @@ oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
108
108
  oarepo_runtime/utils/functools.py,sha256=eueB-4MRv9wrOARs70ey21JvBb63gGeJV6m1fdGcnPQ,319
109
109
  oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
110
110
  tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
111
- oarepo_runtime-1.5.9.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
112
- oarepo_runtime-1.5.9.dist-info/METADATA,sha256=tiavNP9_ZGACPIZvyvuRs4VgInnmgH3rEaqiVCUYoRo,4786
113
- oarepo_runtime-1.5.9.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
114
- oarepo_runtime-1.5.9.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
115
- oarepo_runtime-1.5.9.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
116
- oarepo_runtime-1.5.9.dist-info/RECORD,,
111
+ oarepo_runtime-1.5.10.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
112
+ oarepo_runtime-1.5.10.dist-info/METADATA,sha256=Bf_H3Lyi-01D9RxW8qUm0mLmt55_hLdoD26igXVsl4o,4787
113
+ oarepo_runtime-1.5.10.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
114
+ oarepo_runtime-1.5.10.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
115
+ oarepo_runtime-1.5.10.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
116
+ oarepo_runtime-1.5.10.dist-info/RECORD,,