cardo-python-utils 0.5.dev14__py3-none-any.whl → 0.5.dev15__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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cardo-python-utils
3
- Version: 0.5.dev14
3
+ Version: 0.5.dev15
4
4
  Summary: Python library enhanced with a wide range of functions for different scenarios.
5
5
  Author-email: CardoAI <hello@cardoai.com>
6
6
  License: MIT
@@ -1,4 +1,4 @@
1
- cardo_python_utils-0.5.dev14.dist-info/licenses/LICENSE,sha256=N-YtxDy8n5A1Mo7JKKItNIlboiK_pMOZ48ojx76jo3g,1046
1
+ cardo_python_utils-0.5.dev15.dist-info/licenses/LICENSE,sha256=N-YtxDy8n5A1Mo7JKKItNIlboiK_pMOZ48ojx76jo3g,1046
2
2
  python_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  python_utils/choices.py,sha256=_sLNkSnQqhg55gGKNRsOQCJ75W6gnz8J8Q00528MEYk,2548
4
4
  python_utils/data_structures.py,sha256=ZqkZYPy20zyGYOVhwb9qst4vF_P7X2A9z5E36rMUC6I,16820
@@ -18,12 +18,12 @@ python_utils/django/keycloak/admin/auth.py,sha256=0aB3kP7r3Vk1xTM341os5-pv_JVv1l
18
18
  python_utils/django/keycloak/admin/user_group.py,sha256=3-zfrehLR_nVP-60Zw4ViJjBY1lLAmmlbXaUW1pQs4Q,2668
19
19
  python_utils/django/keycloak/admin/user_groups_changelist.html,sha256=KbO6bsH-nh3DDYCq4UB8j25NdjLP_nh_GuGZ4lYSarM,182
20
20
  python_utils/django/keycloak/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- python_utils/django/keycloak/api/drf.py,sha256=PKvOMIugv2-NalDoVp-XmgurbmY9tEHV4jfHKENKumg,2256
21
+ python_utils/django/keycloak/api/drf.py,sha256=PtMA0j9nlUxQ9VxAlP5_FnoxlMdjNZLi2ilKplh9A0c,2701
22
22
  python_utils/django/keycloak/api/ninja.py,sha256=PO_i-Wr_sK8f45KddKDg5kMAfiEEN1DibYlsMEYYom8,4727
23
23
  python_utils/django/keycloak/api/utils.py,sha256=TktKfgASNySjn5y8UkU1hc7yML1lDYkVllpL4YYjGQ4,2878
24
24
  python_utils/django/keycloak/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  python_utils/django/keycloak/models/user_group.py,sha256=WU_KClfj-pboDIKUDHZQfQuhAPIPXgP-LrEvg9XJjmA,504
26
- cardo_python_utils-0.5.dev14.dist-info/METADATA,sha256=NbzSWVUBztV_cEVBleZdn4e0M3ZTExJ_lN7xAFJRfvM,2915
27
- cardo_python_utils-0.5.dev14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
- cardo_python_utils-0.5.dev14.dist-info/top_level.txt,sha256=zAx6OfEsjJs8BEW3okSiG_j9gpkI69xWShzum6oBgKI,13
29
- cardo_python_utils-0.5.dev14.dist-info/RECORD,,
26
+ cardo_python_utils-0.5.dev15.dist-info/METADATA,sha256=-oC58K9m_7MXJhU7JP8XmFmJMWSLQ4qHPPmK_b-9wCQ,2915
27
+ cardo_python_utils-0.5.dev15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
+ cardo_python_utils-0.5.dev15.dist-info/top_level.txt,sha256=zAx6OfEsjJs8BEW3okSiG_j9gpkI69xWShzum6oBgKI,13
29
+ cardo_python_utils-0.5.dev15.dist-info/RECORD,,
@@ -42,18 +42,32 @@ class HasScope(BasePermission):
42
42
  allowed_scopes = ["jobs"]
43
43
  ...
44
44
 
45
+ It is possible to define different scopes per HTTP method
46
+ by setting `allowed_scopes` as a dict:
47
+
48
+ class MyApiView(APIView):
49
+ permission_classes = [IsAuthenticated, HasScope]
50
+ allowed_scopes = {
51
+ "get": ["jobs"],
52
+ "post": ["jobs_admin"],
53
+ }
54
+ ...
55
+
45
56
  If no particular scope is required, you can set `allowed_scopes = "*"`
46
57
  to allow access without scope checks.
47
58
  """
48
59
 
49
60
  def has_permission(self, request, view):
50
- allowed_scopes = getattr(view, "allowed_scopes", [])
61
+ allowed_scopes = getattr(view, "allowed_scopes", None)
51
62
 
52
63
  if not allowed_scopes:
53
64
  raise Exception(
54
65
  f"No allowed_scopes defined on the view '{view.__class__.__name__}'. "
55
66
  "Define allowed_scopes or set it to '*' to allow any scope."
56
67
  )
68
+
69
+ if isinstance(allowed_scopes, dict):
70
+ allowed_scopes = allowed_scopes.get(request.method.lower(), [])
57
71
 
58
72
  if allowed_scopes == "*":
59
73
  return True