statezero 0.1.0b65__py3-none-any.whl → 0.1.0b66__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,12 +1,13 @@
1
1
  from django.urls import path
2
2
 
3
- from .views import EventsAuthView, ModelListView, ModelView, SchemaView, FileUploadView, FastUploadView, ActionSchemaView, ActionView, ValidateView, FieldPermissionsView
3
+ from .views import EventsAuthView, ModelListView, MeView, ModelView, SchemaView, FileUploadView, FastUploadView, ActionSchemaView, ActionView, ValidateView, FieldPermissionsView
4
4
 
5
5
  app_name = "statezero"
6
6
 
7
7
  urlpatterns = [
8
8
  path("events/auth/", EventsAuthView.as_view(), name="events_auth"),
9
9
  path("models/", ModelListView.as_view(), name="model_list"),
10
+ path("me/", MeView.as_view(), name="me"),
10
11
  path("files/upload/", FileUploadView.as_view(), name="file_upload"),
11
12
  path("files/fast-upload/", FastUploadView.as_view(), name="fast_file_upload"),
12
13
  path("actions/<str:action_name>/", ActionView.as_view(), name="action"),
@@ -23,6 +23,7 @@ from statezero.adaptors.django.exception_handler import \
23
23
  from statezero.adaptors.django.permissions import ORMBridgeViewAccessGate
24
24
  from statezero.adaptors.django.actions import DjangoActionSchemaGenerator
25
25
  from statezero.adaptors.django.action_serializers import get_or_build_action_serializer
26
+ from statezero.adaptors.django.serializers import DRFDynamicSerializer
26
27
  from statezero.core.interfaces import AbstractEventEmitter, AbstractActionPermission
27
28
  from statezero.core.process_request import RequestProcessor
28
29
  from statezero.core.actions import action_registry
@@ -114,6 +115,64 @@ class ModelListView(APIView):
114
115
  model_names.append(model_name)
115
116
  return Response(model_names, status=status.HTTP_200_OK)
116
117
 
118
+ class MeView(APIView):
119
+ """
120
+ Returns the current authenticated user as a guaranteed model summary.
121
+ Uses the existing StateZero serializer with only the PK field requested,
122
+ which includes `pk` and `repr` by design.
123
+ """
124
+
125
+ permission_classes = []
126
+
127
+ def get(self, request, *args, **kwargs):
128
+ try:
129
+ user = config.orm_provider.get_user(request)
130
+ if not user or not getattr(user, "is_authenticated", False):
131
+ raise PermissionDenied(detail="Authentication required.")
132
+
133
+ model = user.__class__
134
+ model_name = config.orm_provider.get_model_name(model)
135
+ pk_field = model._meta.pk.name
136
+ pk_value = getattr(user, pk_field)
137
+
138
+ fields_map = {
139
+ model_name: {pk_field},
140
+ }
141
+
142
+ serializer = DRFDynamicSerializer()
143
+ serialized = serializer.serialize(
144
+ data=user,
145
+ model=model,
146
+ depth=0,
147
+ fields_map=fields_map,
148
+ many=False,
149
+ request=request,
150
+ )
151
+
152
+ included = serialized.get("included", {})
153
+ user_bucket = included.get(model_name, {})
154
+ user_data = user_bucket.get(pk_value)
155
+
156
+ # Defensive fallback to keep the endpoint contract stable.
157
+ if user_data is None:
158
+ user_data = {
159
+ pk_field: pk_value,
160
+ "repr": {
161
+ "str": str(user),
162
+ "img": user.__img__() if hasattr(user, "__img__") else None,
163
+ },
164
+ }
165
+
166
+ return Response(
167
+ {
168
+ "model_name": model_name,
169
+ "data": user_data,
170
+ },
171
+ status=status.HTTP_200_OK,
172
+ )
173
+ except Exception as original_exception:
174
+ return explicit_exception_handler(original_exception)
175
+
117
176
 
118
177
  class ModelView(APIView):
119
178
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: statezero
3
- Version: 0.1.0b65
3
+ Version: 0.1.0b66
4
4
  Summary: Connect your Python backend to a modern JavaScript SPA frontend with 90% less complexity.
5
5
  Author-email: Robert <robert.herring@statezero.dev>
6
6
  Project-URL: homepage, https://www.statezero.dev
@@ -19,9 +19,9 @@ statezero/adaptors/django/schemas.py,sha256=SBYPKre7o6RANCXhzDgyZOvhChIO32W609AT
19
19
  statezero/adaptors/django/serializers.py,sha256=Sh7xp6alXPLv7V0m1ypM1y2q8Q0obpw6rQwpMg4N1Ts,28124
20
20
  statezero/adaptors/django/signals.py,sha256=bL_-vGEFUBbDhCdO7vCXdHcRBWLcs2R7e2mkFq_8-7A,14229
21
21
  statezero/adaptors/django/testing.py,sha256=mRPtDMGGTVe3OFfzIx7uIiiWuuE3Lw15teMJHMU_erw,4818
22
- statezero/adaptors/django/urls.py,sha256=sPalAG8ZCrNbs5u8IV3xzwUGe9tRRgh-WRh0D3BQ2BA,1036
22
+ statezero/adaptors/django/urls.py,sha256=esh05k-EFPqgXeztAkZF1CIzS3rNv4QxHZeVc0rBDMA,1090
23
23
  statezero/adaptors/django/utils.py,sha256=EyRc-R4P47L6eYufDwd1ZADU9Lz9NCVaORmxZdkgu5M,14666
24
- statezero/adaptors/django/views.py,sha256=SE0j3zxByQ7tBX94-qBgFdTvdQ1yRHWi-McKsVahKR4,25227
24
+ statezero/adaptors/django/views.py,sha256=SU-7n-DWU1VMtyuvqBXoPx-NUGrER1qF1Mu77GdA0G4,27250
25
25
  statezero/adaptors/django/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  statezero/adaptors/django/extensions/simple_history.py,sha256=jksS8N6EWE-0raB0qMT-aAHqxibrVvwqTCGlwW7UiNE,1947
27
27
  statezero/adaptors/django/extensions/custom_field_serializers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -51,7 +51,7 @@ statezero/core/process_request.py,sha256=s1yys2ms856KJxV-cIfnVIdMkrOW9nLfzyLor64
51
51
  statezero/core/query_cache.py,sha256=haEBdd4nCm8h8ugj8KmCHUbyiHApU4rv-9PncKJJCys,9528
52
52
  statezero/core/telemetry.py,sha256=EV2yLV6WAS-MTYCQSRQadiMgOD_ViJ_qUspgvbD0GqA,7757
53
53
  statezero/core/types.py,sha256=An57YP1sdd7u6eppXeKMoSudEn_6-Pb6UoC3IdR5E8w,916
54
- statezero-0.1.0b65.dist-info/METADATA,sha256=FvwaAGB2Soi7B43kfR2QspCtY9pypvHRD8C3WFlquUE,9872
55
- statezero-0.1.0b65.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
56
- statezero-0.1.0b65.dist-info/top_level.txt,sha256=UAuZYPKczradU1kcMQxsGjUzEW0qdgsqzhXyscrcLpw,10
57
- statezero-0.1.0b65.dist-info/RECORD,,
54
+ statezero-0.1.0b66.dist-info/METADATA,sha256=CyUxGvEbo_BFe8jgIDWOlFu5e6-J9oCRk-vjbe6BHtA,9872
55
+ statezero-0.1.0b66.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
56
+ statezero-0.1.0b66.dist-info/top_level.txt,sha256=UAuZYPKczradU1kcMQxsGjUzEW0qdgsqzhXyscrcLpw,10
57
+ statezero-0.1.0b66.dist-info/RECORD,,