maquinaweb-shared-auth 0.2.12__tar.gz → 0.2.14__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.
Potentially problematic release.
This version of maquinaweb-shared-auth might be problematic. Click here for more details.
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/PKG-INFO +1 -1
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/maquinaweb_shared_auth.egg-info/PKG-INFO +1 -1
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/pyproject.toml +1 -1
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/authentication.py +3 -3
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/decorators.py +3 -3
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/middleware.py +3 -3
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/mixins.py +2 -2
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/models.py +4 -5
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/README.md +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/maquinaweb_shared_auth.egg-info/SOURCES.txt +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/maquinaweb_shared_auth.egg-info/dependency_links.txt +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/maquinaweb_shared_auth.egg-info/requires.txt +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/maquinaweb_shared_auth.egg-info/top_level.txt +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/setup.cfg +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/setup.py +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/__init__.py +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/app.py +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/conf.py +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/exceptions.py +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/fields.py +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/managers.py +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/permissions.py +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/router.py +0 -0
- {maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/serializers.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "maquinaweb-shared-auth"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.14"
|
|
8
8
|
description = "Models read-only para autenticação compartilhada entre projetos Django."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.13"
|
{maquinaweb_shared_auth-0.2.12 → maquinaweb_shared_auth-0.2.14}/shared_auth/authentication.py
RENAMED
|
@@ -6,7 +6,7 @@ from django.utils.translation import gettext_lazy as _
|
|
|
6
6
|
from rest_framework import exceptions
|
|
7
7
|
from rest_framework.authentication import TokenAuthentication
|
|
8
8
|
|
|
9
|
-
from .models import SharedToken,
|
|
9
|
+
from .models import SharedToken, User
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class SharedTokenAuthentication(TokenAuthentication):
|
|
@@ -34,8 +34,8 @@ class SharedTokenAuthentication(TokenAuthentication):
|
|
|
34
34
|
|
|
35
35
|
# Buscar usuário completo
|
|
36
36
|
try:
|
|
37
|
-
user =
|
|
38
|
-
except
|
|
37
|
+
user = User.objects.get(pk=token.user_id)
|
|
38
|
+
except User.DoesNotExist:
|
|
39
39
|
raise exceptions.AuthenticationFailed(_("Usuário não encontrado."))
|
|
40
40
|
|
|
41
41
|
if not user.is_active:
|
|
@@ -6,7 +6,7 @@ from functools import wraps
|
|
|
6
6
|
|
|
7
7
|
from django.http import JsonResponse
|
|
8
8
|
|
|
9
|
-
from .models import SharedOrganization, SharedToken,
|
|
9
|
+
from .models import SharedOrganization, SharedToken, User
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def require_auth(view_func):
|
|
@@ -30,7 +30,7 @@ def require_auth(view_func):
|
|
|
30
30
|
# Validar token
|
|
31
31
|
try:
|
|
32
32
|
token_obj = SharedToken.objects.get(key=token)
|
|
33
|
-
user =
|
|
33
|
+
user = User.objects.get(pk=token_obj.user_id)
|
|
34
34
|
|
|
35
35
|
if not user.is_active or user.deleted_at is not None:
|
|
36
36
|
return JsonResponse({"error": "Usuário inativo"}, status=401)
|
|
@@ -38,7 +38,7 @@ def require_auth(view_func):
|
|
|
38
38
|
request.user = user
|
|
39
39
|
request.auth = token_obj
|
|
40
40
|
|
|
41
|
-
except (SharedToken.DoesNotExist,
|
|
41
|
+
except (SharedToken.DoesNotExist, User.DoesNotExist):
|
|
42
42
|
return JsonResponse({"error": "Token inválido"}, status=401)
|
|
43
43
|
|
|
44
44
|
return view_func(request, *args, **kwargs)
|
|
@@ -6,7 +6,7 @@ from django.http import JsonResponse
|
|
|
6
6
|
from django.utils.deprecation import MiddlewareMixin
|
|
7
7
|
|
|
8
8
|
from .authentication import SharedTokenAuthentication
|
|
9
|
-
from .models import SharedMember, SharedOrganization, SharedToken,
|
|
9
|
+
from .models import SharedMember, SharedOrganization, SharedToken, User
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class SharedAuthMiddleware(MiddlewareMixin):
|
|
@@ -52,7 +52,7 @@ class SharedAuthMiddleware(MiddlewareMixin):
|
|
|
52
52
|
# Validar token e buscar usuário
|
|
53
53
|
try:
|
|
54
54
|
token_obj = SharedToken.objects.get(key=token)
|
|
55
|
-
user =
|
|
55
|
+
user = User.objects.get(pk=token_obj.user_id)
|
|
56
56
|
|
|
57
57
|
if not user.is_active or user.deleted_at is not None:
|
|
58
58
|
# request.user = None
|
|
@@ -63,7 +63,7 @@ class SharedAuthMiddleware(MiddlewareMixin):
|
|
|
63
63
|
# request.user = user
|
|
64
64
|
request.auth = token_obj
|
|
65
65
|
|
|
66
|
-
except (SharedToken.DoesNotExist,
|
|
66
|
+
except (SharedToken.DoesNotExist, User.DoesNotExist):
|
|
67
67
|
# request.user = None
|
|
68
68
|
request.auth = None
|
|
69
69
|
|
|
@@ -108,9 +108,9 @@ class UserMixin(models.Model):
|
|
|
108
108
|
Acessa usuário do banco de auth (lazy loading com cache)
|
|
109
109
|
"""
|
|
110
110
|
if not hasattr(self, "_cached_user"):
|
|
111
|
-
from shared_auth.models import
|
|
111
|
+
from shared_auth.models import User
|
|
112
112
|
|
|
113
|
-
self._cached_user =
|
|
113
|
+
self._cached_user = User.objects.get_or_fail(self.user_id)
|
|
114
114
|
return self._cached_user
|
|
115
115
|
|
|
116
116
|
@property
|
|
@@ -37,7 +37,7 @@ class SharedToken(models.Model):
|
|
|
37
37
|
def user(self):
|
|
38
38
|
"""Acessa usuário do token"""
|
|
39
39
|
if not hasattr(self, "_cached_user"):
|
|
40
|
-
self._cached_user =
|
|
40
|
+
self._cached_user = User.objects.get_or_fail(self.user_id)
|
|
41
41
|
return self._cached_user
|
|
42
42
|
|
|
43
43
|
def is_valid(self):
|
|
@@ -121,7 +121,7 @@ class SharedOrganization(models.Model):
|
|
|
121
121
|
Usage:
|
|
122
122
|
users = org.users
|
|
123
123
|
"""
|
|
124
|
-
return
|
|
124
|
+
return User.objects.filter(
|
|
125
125
|
id__in=self.members.values_list("user_id", flat=True)
|
|
126
126
|
)
|
|
127
127
|
|
|
@@ -130,7 +130,7 @@ class SharedOrganization(models.Model):
|
|
|
130
130
|
return self.deleted_at is None
|
|
131
131
|
|
|
132
132
|
|
|
133
|
-
class
|
|
133
|
+
class User(AbstractUser):
|
|
134
134
|
"""
|
|
135
135
|
Model READ-ONLY da tabela auth_user
|
|
136
136
|
"""
|
|
@@ -148,7 +148,6 @@ class SharedUser(AbstractUser):
|
|
|
148
148
|
class Meta:
|
|
149
149
|
managed = False
|
|
150
150
|
db_table = USER_TABLE
|
|
151
|
-
default_related_name = "user"
|
|
152
151
|
|
|
153
152
|
|
|
154
153
|
class SharedMember(models.Model):
|
|
@@ -180,7 +179,7 @@ class SharedMember(models.Model):
|
|
|
180
179
|
user = member.user
|
|
181
180
|
print(user.email)
|
|
182
181
|
"""
|
|
183
|
-
return
|
|
182
|
+
return User.objects.get_or_fail(self.user_id)
|
|
184
183
|
|
|
185
184
|
@property
|
|
186
185
|
def organization(self):
|
|
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
|