elody 0.0.215__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.
@@ -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
 
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: elody
3
- Version: 0.0.215
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
@@ -18,9 +18,9 @@ elody/object_configurations/job_configuration.py,sha256=HMDxaRUyfqhIy0q3yQDDMH9u
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
20
  elody/policies/helpers.py,sha256=0mlTd-hu2TKwVNH3ov4yCEV-P_f2k7XFJ7XYUtGTjXk,2239
21
- elody/policies/permission_handler.py,sha256=Bb4PHlM2A3Y-gknIdh4tNIk4gfv6iRjNeVULnUCITFc,10330
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.215.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.215.dist-info/METADATA,sha256=PsmLEfEJhwLxo523Qr8QnvgR2asF-3nf9AeNvUcJUqg,23358
45
- elody-0.0.215.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
46
- elody-0.0.215.dist-info/top_level.txt,sha256=E0mImupLj0KmtUUCXRYEoLDRaSkuiGaOIIseAa0oQ-M,21
47
- elody-0.0.215.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,,