statezero 0.1.0b64__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.
- statezero/adaptors/django/urls.py +2 -1
- statezero/adaptors/django/views.py +79 -0
- {statezero-0.1.0b64.dist-info → statezero-0.1.0b66.dist-info}/METADATA +1 -1
- {statezero-0.1.0b64.dist-info → statezero-0.1.0b66.dist-info}/RECORD +6 -6
- {statezero-0.1.0b64.dist-info → statezero-0.1.0b66.dist-info}/WHEEL +0 -0
- {statezero-0.1.0b64.dist-info → statezero-0.1.0b66.dist-info}/top_level.txt +0 -0
|
@@ -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
|
|
@@ -44,6 +45,18 @@ class EventsAuthView(APIView):
|
|
|
44
45
|
permission_classes = [permission_class]
|
|
45
46
|
|
|
46
47
|
def post(self, request, *args, **kwargs):
|
|
48
|
+
sync_token = getattr(settings, "STATEZERO_SYNC_TOKEN", None)
|
|
49
|
+
client_token = request.headers.get("X-StateZero-Sync-Token")
|
|
50
|
+
if client_token is not None:
|
|
51
|
+
if not sync_token or client_token != sync_token:
|
|
52
|
+
return Response(
|
|
53
|
+
{
|
|
54
|
+
"error": "Sync token mismatch for events auth.",
|
|
55
|
+
"header": "X-StateZero-Sync-Token",
|
|
56
|
+
},
|
|
57
|
+
status=status.HTTP_409_CONFLICT,
|
|
58
|
+
)
|
|
59
|
+
|
|
47
60
|
channel_name = request.data.get("channel_name")
|
|
48
61
|
socket_id = request.data.get("socket_id")
|
|
49
62
|
|
|
@@ -77,6 +90,14 @@ class EventsAuthView(APIView):
|
|
|
77
90
|
|
|
78
91
|
# Delegate authentication to the event emitter.
|
|
79
92
|
response = event_emitter.authenticate(request)
|
|
93
|
+
if client_token is not None:
|
|
94
|
+
if isinstance(response, dict):
|
|
95
|
+
response["statezero_sync_token_match"] = True
|
|
96
|
+
else:
|
|
97
|
+
response = {
|
|
98
|
+
"auth": response,
|
|
99
|
+
"statezero_sync_token_match": True,
|
|
100
|
+
}
|
|
80
101
|
logger.debug(f"Authentication successful for channel: {channel_name}")
|
|
81
102
|
return Response(response, status=status.HTTP_200_OK)
|
|
82
103
|
|
|
@@ -94,6 +115,64 @@ class ModelListView(APIView):
|
|
|
94
115
|
model_names.append(model_name)
|
|
95
116
|
return Response(model_names, status=status.HTTP_200_OK)
|
|
96
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
|
+
|
|
97
176
|
|
|
98
177
|
class ModelView(APIView):
|
|
99
178
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: statezero
|
|
3
|
-
Version: 0.1.
|
|
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=
|
|
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=
|
|
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.
|
|
55
|
-
statezero-0.1.
|
|
56
|
-
statezero-0.1.
|
|
57
|
-
statezero-0.1.
|
|
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,,
|
|
File without changes
|
|
File without changes
|