maquinaweb-shared-auth 0.1.3__py3-none-any.whl → 0.1.4__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.
Potentially problematic release.
This version of maquinaweb-shared-auth might be problematic. Click here for more details.
- {maquinaweb_shared_auth-0.1.3.dist-info → maquinaweb_shared_auth-0.1.4.dist-info}/METADATA +1 -1
- {maquinaweb_shared_auth-0.1.3.dist-info → maquinaweb_shared_auth-0.1.4.dist-info}/RECORD +5 -5
- shared_auth/mixins.py +58 -0
- {maquinaweb_shared_auth-0.1.3.dist-info → maquinaweb_shared_auth-0.1.4.dist-info}/WHEEL +0 -0
- {maquinaweb_shared_auth-0.1.3.dist-info → maquinaweb_shared_auth-0.1.4.dist-info}/top_level.txt +0 -0
|
@@ -6,12 +6,12 @@ shared_auth/exceptions.py,sha256=eiII-REupK6GeFinisteYO3FsGUDAN5zAajXPhTREm8,404
|
|
|
6
6
|
shared_auth/fields.py,sha256=RAcmFh1D_nkbai_7t_OrPZhfhAipesy5kKnEj4LUvvM,1254
|
|
7
7
|
shared_auth/managers.py,sha256=NfMhsAFuVmo8MUY2fveB_xVAT5_67nlkVOXS_C8bhew,6920
|
|
8
8
|
shared_auth/middleware.py,sha256=OycDHgHh-1GkicU91xDaxXw_AR43JeQn8PsJXm4w_3E,5979
|
|
9
|
-
shared_auth/mixins.py,sha256=
|
|
9
|
+
shared_auth/mixins.py,sha256=3ARghQ4TvtENKoA5UTOHTrRHa6ufMRVJJHGFkV8-BL8,7550
|
|
10
10
|
shared_auth/models.py,sha256=iszFHOhpD78tqcXaxxZ9_57wLdRq9i_ZsHWrfy5W9Nc,6997
|
|
11
11
|
shared_auth/permissions.py,sha256=kkEMtClmV9VB3EOhKDyinSr4r5v9g-3DCCKNtqpaTz8,2473
|
|
12
12
|
shared_auth/router.py,sha256=nYbqnqjoylD0yeSY7rqyH8N4H6j1MHYD2sMnrhi3sm4,646
|
|
13
13
|
shared_auth/serializers.py,sha256=TDpuZVsOL-6igINSOOOyELWbTUeet4XWRoBkvcMGjW4,4290
|
|
14
|
-
maquinaweb_shared_auth-0.1.
|
|
15
|
-
maquinaweb_shared_auth-0.1.
|
|
16
|
-
maquinaweb_shared_auth-0.1.
|
|
17
|
-
maquinaweb_shared_auth-0.1.
|
|
14
|
+
maquinaweb_shared_auth-0.1.4.dist-info/METADATA,sha256=nzMW_SX5YSnQrtpPH-f33d1jXc8_bmG6XHVnlKvy-OU,27150
|
|
15
|
+
maquinaweb_shared_auth-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
16
|
+
maquinaweb_shared_auth-0.1.4.dist-info/top_level.txt,sha256=msyYRy02ZV7zz7GR1raUI5LXGFIFn2TIkgkeKZqKufE,12
|
|
17
|
+
maquinaweb_shared_auth-0.1.4.dist-info/RECORD,,
|
shared_auth/mixins.py
CHANGED
|
@@ -3,6 +3,8 @@ Mixins para facilitar a criação de models com referências ao sistema de auth
|
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
from django.db import models
|
|
6
|
+
from rest_framework import viewsets, status
|
|
7
|
+
from rest_framework.response import Response
|
|
6
8
|
|
|
7
9
|
from shared_auth.managers import BaseAuthManager
|
|
8
10
|
|
|
@@ -190,6 +192,62 @@ class OrganizationUserMixin(OrganizationMixin, UserMixin):
|
|
|
190
192
|
.exists()
|
|
191
193
|
)
|
|
192
194
|
|
|
195
|
+
class LoggedOrganizationMixin(viewsets.ModelViewSet):
|
|
196
|
+
"""
|
|
197
|
+
Mixin para ViewSets que dependem de uma organização logada.
|
|
198
|
+
Integra com a lib maquinaweb-shared-auth.
|
|
199
|
+
"""
|
|
200
|
+
|
|
201
|
+
def get_organization_id(self):
|
|
202
|
+
"""Obtém o ID da organização logada via maquinaweb-shared-auth"""
|
|
203
|
+
return self.request.organization_id
|
|
204
|
+
|
|
205
|
+
def get_user(self):
|
|
206
|
+
"""Obtém o usuário atual autenticado"""
|
|
207
|
+
return self.request.user
|
|
208
|
+
|
|
209
|
+
def check_logged_organization(self):
|
|
210
|
+
"""Verifica se há uma organização logada"""
|
|
211
|
+
return self.get_organization_id() is not None
|
|
212
|
+
|
|
213
|
+
def require_logged_organization(self):
|
|
214
|
+
"""Retorna erro se não houver organização logada"""
|
|
215
|
+
if not self.check_logged_organization():
|
|
216
|
+
return Response(
|
|
217
|
+
{
|
|
218
|
+
"detail": "Nenhuma organização logada. Defina uma organização antes de continuar."
|
|
219
|
+
},
|
|
220
|
+
status=status.HTTP_403_FORBIDDEN,
|
|
221
|
+
)
|
|
222
|
+
return None
|
|
223
|
+
|
|
224
|
+
def get_queryset(self):
|
|
225
|
+
"""Filtra os objetos pela organização logada, se aplicável"""
|
|
226
|
+
queryset = super().get_queryset()
|
|
227
|
+
|
|
228
|
+
response = self.require_logged_organization()
|
|
229
|
+
if response:
|
|
230
|
+
return queryset.none()
|
|
231
|
+
|
|
232
|
+
organization_id = self.get_organization_id()
|
|
233
|
+
if hasattr(queryset.model, "organization_id"):
|
|
234
|
+
return queryset.filter(organization_id=organization_id)
|
|
235
|
+
elif hasattr(queryset.model, "organization"):
|
|
236
|
+
return queryset.filter(organization_id=organization_id)
|
|
237
|
+
return queryset
|
|
238
|
+
|
|
239
|
+
def perform_create(self, serializer):
|
|
240
|
+
"""Define a organização automaticamente ao criar um objeto"""
|
|
241
|
+
response = self.require_logged_organization()
|
|
242
|
+
if response:
|
|
243
|
+
return response
|
|
244
|
+
|
|
245
|
+
organization_id = self.get_organization_id()
|
|
246
|
+
|
|
247
|
+
if "organization" in serializer.fields:
|
|
248
|
+
serializer.save(organization_id=organization_id)
|
|
249
|
+
else:
|
|
250
|
+
serializer.save()
|
|
193
251
|
|
|
194
252
|
class TimestampedMixin(models.Model):
|
|
195
253
|
"""
|
|
File without changes
|
{maquinaweb_shared_auth-0.1.3.dist-info → maquinaweb_shared_auth-0.1.4.dist-info}/top_level.txt
RENAMED
|
File without changes
|