maquinaweb-shared-auth 0.2.39__tar.gz → 0.2.41__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.39 → maquinaweb_shared_auth-0.2.41}/PKG-INFO +1 -1
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/maquinaweb_shared_auth.egg-info/PKG-INFO +1 -1
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/pyproject.toml +1 -1
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/middleware.py +16 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/mixins.py +9 -4
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/serializers.py +3 -1
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/README.md +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/maquinaweb_shared_auth.egg-info/SOURCES.txt +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/maquinaweb_shared_auth.egg-info/dependency_links.txt +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/maquinaweb_shared_auth.egg-info/requires.txt +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/maquinaweb_shared_auth.egg-info/top_level.txt +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/setup.cfg +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/setup.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/__init__.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/abstract_models.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/app.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/authentication.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/conf.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/decorators.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/exceptions.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/fields.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/managers.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/models.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/permissions.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/router.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/storage_backend.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/urls.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/utils.py +0 -0
- {maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/views.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.41"
|
|
8
8
|
description = "Models read-only para autenticação compartilhada entre projetos Django."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.13"
|
|
@@ -166,7 +166,10 @@ class OrganizationMiddleware(MiddlewareMixin):
|
|
|
166
166
|
if not organization_id:
|
|
167
167
|
return
|
|
168
168
|
|
|
169
|
+
organization_ids = self._determine_organization_ids(request)
|
|
170
|
+
|
|
169
171
|
request.organization_id = organization_id
|
|
172
|
+
request.organization_ids = organization_ids
|
|
170
173
|
Organization = get_organization_model()
|
|
171
174
|
request.organization = Organization.objects.filter(pk=organization_id).first()
|
|
172
175
|
|
|
@@ -183,6 +186,9 @@ class OrganizationMiddleware(MiddlewareMixin):
|
|
|
183
186
|
|
|
184
187
|
return self._get_organization_from_user(request)
|
|
185
188
|
|
|
189
|
+
def _determine_organization_ids(self, request):
|
|
190
|
+
return self._get_organization_ids_from_user(request)
|
|
191
|
+
|
|
186
192
|
@staticmethod
|
|
187
193
|
def _get_organization_from_header(request):
|
|
188
194
|
if header_value := request.headers.get("X-Organization"):
|
|
@@ -206,6 +212,16 @@ class OrganizationMiddleware(MiddlewareMixin):
|
|
|
206
212
|
|
|
207
213
|
return member.organization_id if member else None
|
|
208
214
|
|
|
215
|
+
@staticmethod
|
|
216
|
+
def _get_organization_ids_from_user(request):
|
|
217
|
+
if not request.user.is_authenticated:
|
|
218
|
+
return None
|
|
219
|
+
|
|
220
|
+
Member = get_member_model()
|
|
221
|
+
member = Member.objects.filter(user_id=request.user.pk)
|
|
222
|
+
|
|
223
|
+
return member.values_list("organization_id", flat=True) if member else None
|
|
224
|
+
|
|
209
225
|
@staticmethod
|
|
210
226
|
def _validate_organization_membership(user, organization_id):
|
|
211
227
|
try:
|
|
@@ -39,14 +39,15 @@ class OrganizationMixin(models.Model):
|
|
|
39
39
|
]
|
|
40
40
|
|
|
41
41
|
@classmethod
|
|
42
|
-
def prefetch_organizations(cls, queryset, request):
|
|
42
|
+
def prefetch_organizations(cls, queryset, request, org_ids=None):
|
|
43
43
|
if not hasattr(request, "_orgs_dict"):
|
|
44
44
|
from shared_auth.utils import get_organization_model
|
|
45
45
|
|
|
46
46
|
Organization = get_organization_model()
|
|
47
|
-
org_ids
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
if org_ids is None:
|
|
48
|
+
org_ids = list(
|
|
49
|
+
queryset.values_list("organization_id", flat=True).distinct()
|
|
50
|
+
)
|
|
50
51
|
if not org_ids:
|
|
51
52
|
request._orgs_dict = {}
|
|
52
53
|
return queryset
|
|
@@ -218,6 +219,10 @@ class LoggedOrganizationMixin(viewsets.ModelViewSet):
|
|
|
218
219
|
"""Obtém o ID da organização logada via maquinaweb-shared-auth"""
|
|
219
220
|
return self.request.organization_id
|
|
220
221
|
|
|
222
|
+
def get_organization_ids(self):
|
|
223
|
+
"""Obtém os IDs das organizações permitidas via maquinaweb-shared-auth"""
|
|
224
|
+
return self.request.organization_ids
|
|
225
|
+
|
|
221
226
|
def get_user(self):
|
|
222
227
|
"""Obtém o usuário atual autenticado"""
|
|
223
228
|
return self.request.user
|
|
@@ -81,7 +81,9 @@ class OrganizationSerializerMixin(serializers.ModelSerializer):
|
|
|
81
81
|
def get_organization(self, obj):
|
|
82
82
|
req = self.context.get("request")
|
|
83
83
|
org = getattr(req, "_orgs_dict", {}).get(obj.organization_id) if req else None
|
|
84
|
-
|
|
84
|
+
if org:
|
|
85
|
+
return self._serialize_org(org)
|
|
86
|
+
return self._serialize_org(obj.organization)
|
|
85
87
|
|
|
86
88
|
def _serialize_org(self, org):
|
|
87
89
|
return {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/abstract_models.py
RENAMED
|
File without changes
|
|
File without changes
|
{maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/authentication.py
RENAMED
|
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
|
{maquinaweb_shared_auth-0.2.39 → maquinaweb_shared_auth-0.2.41}/shared_auth/storage_backend.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|