maquinaweb-shared-auth 0.1.3__tar.gz → 0.1.5__tar.gz
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.
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/PKG-INFO +1 -1
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/maquinaweb_shared_auth.egg-info/PKG-INFO +1 -1
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/maquinaweb_shared_auth.egg-info/SOURCES.txt +1 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/pyproject.toml +1 -1
- maquinaweb_shared_auth-0.1.5/shared_auth/app.py +6 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/managers.py +4 -3
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/mixins.py +58 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/README.md +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/maquinaweb_shared_auth.egg-info/dependency_links.txt +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/maquinaweb_shared_auth.egg-info/requires.txt +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/maquinaweb_shared_auth.egg-info/top_level.txt +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/setup.cfg +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/setup.py +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/__init__.py +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/authentication.py +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/conf.py +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/decorators.py +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/exceptions.py +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/fields.py +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/middleware.py +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/models.py +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/permissions.py +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/router.py +0 -0
- {maquinaweb_shared_auth-0.1.3 → maquinaweb_shared_auth-0.1.5}/shared_auth/serializers.py +0 -0
|
@@ -7,6 +7,7 @@ maquinaweb_shared_auth.egg-info/dependency_links.txt
|
|
|
7
7
|
maquinaweb_shared_auth.egg-info/requires.txt
|
|
8
8
|
maquinaweb_shared_auth.egg-info/top_level.txt
|
|
9
9
|
shared_auth/__init__.py
|
|
10
|
+
shared_auth/app.py
|
|
10
11
|
shared_auth/authentication.py
|
|
11
12
|
shared_auth/conf.py
|
|
12
13
|
shared_auth/decorators.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "maquinaweb-shared-auth"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.5"
|
|
8
8
|
description = "Models read-only para autenticação compartilhada entre projetos Django."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.13"
|
|
@@ -3,8 +3,6 @@ Managers customizados para os models compartilhados
|
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
from django.db import models
|
|
6
|
-
|
|
7
|
-
from . import SharedOrganization, SharedUser, SharedMember
|
|
8
6
|
from .exceptions import OrganizationNotFoundError, UserNotFoundError
|
|
9
7
|
|
|
10
8
|
|
|
@@ -95,7 +93,7 @@ class OrganizationQuerySetMixin:
|
|
|
95
93
|
Lista de objetos com _cached_organization
|
|
96
94
|
"""
|
|
97
95
|
objects = list(self.all())
|
|
98
|
-
|
|
96
|
+
from . import SharedOrganization
|
|
99
97
|
if not objects:
|
|
100
98
|
return objects
|
|
101
99
|
|
|
@@ -132,6 +130,7 @@ class UserQuerySetMixin:
|
|
|
132
130
|
"""
|
|
133
131
|
Pré-carrega dados de usuários (evita N+1)
|
|
134
132
|
"""
|
|
133
|
+
from . import SharedUser
|
|
135
134
|
objects = list(self.all())
|
|
136
135
|
|
|
137
136
|
if not objects:
|
|
@@ -157,6 +156,7 @@ class OrganizationUserQuerySetMixin(OrganizationQuerySetMixin, UserQuerySetMixin
|
|
|
157
156
|
"""
|
|
158
157
|
Pré-carrega dados de organizações E usuários (evita N+1)
|
|
159
158
|
"""
|
|
159
|
+
from . import SharedOrganization, SharedUser
|
|
160
160
|
objects = list(self.all())
|
|
161
161
|
|
|
162
162
|
if not objects:
|
|
@@ -190,6 +190,7 @@ class OrganizationUserQuerySetMixin(OrganizationQuerySetMixin, UserQuerySetMixin
|
|
|
190
190
|
"""
|
|
191
191
|
Cria objeto com validação de organização e usuário
|
|
192
192
|
"""
|
|
193
|
+
from . import SharedOrganization, SharedMember
|
|
193
194
|
# Valida organização
|
|
194
195
|
SharedOrganization.objects.using("auth_db").get_or_fail(organization_id)
|
|
195
196
|
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|