elody 0.0.214__py3-none-any.whl → 0.0.216__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,3 +1,4 @@
1
+ from copy import deepcopy
1
2
  from datetime import datetime, timezone
2
3
  from elody.object_configurations.base_object_configuration import (
3
4
  BaseObjectConfiguration,
@@ -158,6 +159,9 @@ class ElodyConfiguration(BaseObjectConfiguration):
158
159
  lines = value.splitlines()
159
160
  value = "\n".join(line.strip() for line in lines).strip()
160
161
  element[object_list_value_field_name] = value.strip()
162
+ for key, value in deepcopy(element).items():
163
+ if not value:
164
+ del element[key]
161
165
  return sanitized_document
162
166
 
163
167
  def __patch_document_audit_info(self, crud, document, timestamp):
@@ -35,6 +35,10 @@ class BaseUserTenantValidationPolicy(ABC):
35
35
 
36
36
  return self.user
37
37
 
38
+ @abstractmethod
39
+ def promote_role(self, user_context: UserContext):
40
+ pass
41
+
38
42
  @abstractmethod
39
43
  def build_user_context_for_anonymous_user(
40
44
  self, request, user_context: UserContext
@@ -86,30 +90,37 @@ class BaseUserTenantValidationPolicy(ABC):
86
90
  """
87
91
 
88
92
  roles = []
89
- for metadata in self.user.get("metadata", []):
90
- if (
91
- metadata["key"]
92
- == user_context.bag["user_metadata_key_for_global_roles"]
93
+ try:
94
+ for metadata in self.user.get("metadata", []):
95
+ if (
96
+ metadata["key"]
97
+ == user_context.bag["user_metadata_key_for_global_roles"]
98
+ ):
99
+ roles.extend(metadata["value"])
100
+
101
+ if user_context.x_tenant.id:
102
+ tenant_ids = user_context.x_tenant.id.split(",")
103
+ for tenant_id in tenant_ids:
104
+ try:
105
+ user_tenant_relation = self.__get_user_tenant_relation(
106
+ tenant_id, user_context.bag["user_tenant_relation_type"]
107
+ )
108
+ except Forbidden as error:
109
+ user_tenant_relation = {}
110
+ if len(roles) == 0:
111
+ raise Forbidden(error.description)
112
+ roles.extend(user_tenant_relation.get("roles", []))
113
+
114
+ if len(roles) == 0 and not regex.match(
115
+ "(/[^/]+/v[0-9]+)?/tenants$", request.path
93
116
  ):
94
- roles.extend(metadata["value"])
95
-
96
- if user_context.x_tenant.id:
97
- tenant_ids = user_context.x_tenant.id.split(",")
98
- for tenant_id in tenant_ids:
99
- try:
100
- user_tenant_relation = self.__get_user_tenant_relation(
101
- tenant_id, user_context.bag["user_tenant_relation_type"]
102
- )
103
- except Forbidden as error:
104
- user_tenant_relation = {}
105
- if len(roles) == 0:
106
- raise Forbidden(error.description)
107
- roles.extend(user_tenant_relation.get("roles", []))
108
-
109
- if len(roles) == 0 and not regex.match(
110
- "(/[^/]+/v[0-9]+)?/tenants$", request.path
111
- ):
112
- raise Forbidden("User has no global roles, switch to a specific tenant.")
117
+ raise Forbidden(
118
+ "User has no global roles, switch to a specific tenant."
119
+ )
120
+ except Forbidden as exception:
121
+ if not (promoted_role := self.promote_role(user_context)):
122
+ raise exception
123
+ roles.append(promoted_role)
113
124
 
114
125
  return list(set(roles))
115
126
 
elody/policies/helpers.py CHANGED
@@ -44,7 +44,15 @@ def get_item(storage_manager, user_context_bag, view_args) -> dict:
44
44
  view_args = view_args or {}
45
45
  if id := view_args.get("id"):
46
46
  resolve_collections = user_context_bag.get("collection_resolver")
47
- collections = resolve_collections(collection=view_args.get("collection"), id=id)
47
+ collection = (
48
+ get_object_configuration_mapper()
49
+ .get(view_args.get("type"))
50
+ .crud()
51
+ .get("collection")
52
+ )
53
+ collections = resolve_collections(
54
+ collection=view_args.get("collection", collection), id=id
55
+ )
48
56
  for collection in collections:
49
57
  if item := storage_manager.get_db_engine().get_item_from_collection_by_id(
50
58
  collection, id
@@ -222,7 +222,7 @@ def __is_allowed_to_crud_item_keys(
222
222
  if key_to_check and key_to_check == restricted_key:
223
223
  user_context.bag["restricted_keys"].append(restricted_key)
224
224
  else:
225
- if flat_request_body.get(restricted_key):
225
+ if flat_request_body.get(restricted_key) is not None:
226
226
  user_context.bag["restricted_keys"].append(restricted_key)
227
227
 
228
228
  user_context.bag["requested_item"] = item
@@ -260,7 +260,11 @@ def __item_value_in_values(
260
260
  if key_of_relation:
261
261
  if isinstance(item_value, list):
262
262
  item_value = item_value[0]
263
- item = get_item(StorageManager(), user_context.bag, {"id": item_value})
263
+ item = get_item(
264
+ StorageManager(),
265
+ user_context.bag,
266
+ {"type": keys[1].split("-", 1)[0], "id": item_value},
267
+ )
264
268
  flat_item, _ = get_flat_item_and_object_lists(item)
265
269
  return __item_value_in_values(
266
270
  flat_item, key_of_relation, values, flat_request_body, user_context
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: elody
3
- Version: 0.0.214
3
+ Version: 0.0.216
4
4
  Summary: elody SDK for Python
5
5
  Author-email: Inuits <developers@inuits.eu>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -13,14 +13,14 @@ elody/migration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  elody/migration/base_object_migrator.py,sha256=n8uvgGfjEUy60G47RD7Y-oxp1vHLOauwPMDl87LcxtU,436
14
14
  elody/object_configurations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  elody/object_configurations/base_object_configuration.py,sha256=8wyUq_zqRkGb4Mp198pyxOaGdz2WMZzVOO65s1SDCRw,7393
16
- elody/object_configurations/elody_configuration.py,sha256=SQJbO1BlPT3FjZ7RXZbTfVfNfiUe7wH7fHzYfrLfwJE,10369
16
+ elody/object_configurations/elody_configuration.py,sha256=pktiS14jeZja-G6677Hse5zzeUpH5rHRzy7YK-H2wNU,10519
17
17
  elody/object_configurations/job_configuration.py,sha256=HMDxaRUyfqhIy0q3yQDDMH9uW5iCd7VCmqknQofXNt0,2039
18
18
  elody/object_configurations/saved_search_configuration.py,sha256=ddOry4EqYOeEKRF7q2M_fHoqZv8DXpQjFq8VaZ7jhVI,732
19
19
  elody/policies/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
- elody/policies/helpers.py,sha256=LTV_Hmg8AN64e6t4glpKhZMsRNYCLN8FC-KQ0-7EmR8,2035
21
- elody/policies/permission_handler.py,sha256=ovQ1id67GtiEZYl3_2f_QPDn7XkCMGae6xgnpMWNHs8,10233
20
+ elody/policies/helpers.py,sha256=0mlTd-hu2TKwVNH3ov4yCEV-P_f2k7XFJ7XYUtGTjXk,2239
21
+ elody/policies/permission_handler.py,sha256=9vxiYjkPrnqIxWi8X9qoGwb09SQaZmQeF4f_9LSQRDs,10342
22
22
  elody/policies/authentication/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
- elody/policies/authentication/base_user_tenant_validation_policy.py,sha256=zQo9tyGDwHHh6Wt3akbaT5CIEG5rqz1DT-BsAtbJNhw,5419
23
+ elody/policies/authentication/base_user_tenant_validation_policy.py,sha256=p7draxPCqly1vy7vnJX-gpmRfDeyaTxt9Cf0YpH9PZI,5829
24
24
  elody/policies/authentication/multi_tenant_policy.py,sha256=g4ZYUQMmCjgLg09wj0-0lGKsJsRt7h4ppI25o1VdZHw,4039
25
25
  elody/policies/authorization/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  elody/policies/authorization/filter_generic_objects_policy.py,sha256=mF32moh8hRetBgG8vQW-rz4xjoRQD2yOxdI740SFSUo,6522
@@ -35,13 +35,13 @@ elody/policies/authorization/mediafile_derivatives_policy.py,sha256=OwNpbS8i7-Lz
35
35
  elody/policies/authorization/mediafile_download_policy.py,sha256=XMsKavBucmTh4W1kWOzpFWxJ_ZXgHVK1RS7JB4HjtQo,1979
36
36
  elody/policies/authorization/multi_tenant_policy.py,sha256=SA9H7SBjzuh8mY3gYN7pDG8TV7hdI3GEUtNeiZeNL3M,3164
37
37
  elody/policies/authorization/tenant_request_policy.py,sha256=dEgblwRAqwWVcE-O7Jn8hVL3OnwDlQhDEOcPlcElBrk,1185
38
- elody-0.0.214.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
38
+ elody-0.0.216.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
39
39
  tests/__init_.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
40
  tests/data.py,sha256=Q3oxduf-E3m-Z5G_p3fcs8jVy6g10I7zXKL1m94UVMI,2906
41
41
  tests/unit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
42
  tests/unit/test_csv.py,sha256=NQaOhehfQ4GuXku0Y1SA8DYjJeqqidbF50zEHAi8RZA,15923
43
43
  tests/unit/test_utils.py,sha256=g63szcEZyHhCOtrW4BnNbcgVca3oYPIOLjBdIzNwwN0,8784
44
- elody-0.0.214.dist-info/METADATA,sha256=lgZZtsjnTM2AvqgvmTdLrvPhqqM25WpJ3a1tJyE1Igs,23358
45
- elody-0.0.214.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
46
- elody-0.0.214.dist-info/top_level.txt,sha256=E0mImupLj0KmtUUCXRYEoLDRaSkuiGaOIIseAa0oQ-M,21
47
- elody-0.0.214.dist-info/RECORD,,
44
+ elody-0.0.216.dist-info/METADATA,sha256=aluptX2OzAe9pg2-5jQRl3bFUG9GmFJdlO_wteHFDXk,23358
45
+ elody-0.0.216.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
46
+ elody-0.0.216.dist-info/top_level.txt,sha256=E0mImupLj0KmtUUCXRYEoLDRaSkuiGaOIIseAa0oQ-M,21
47
+ elody-0.0.216.dist-info/RECORD,,