maquinaweb-shared-auth 0.2.37__tar.gz → 0.2.39__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.

Files changed (29) hide show
  1. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/PKG-INFO +1 -1
  2. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/maquinaweb_shared_auth.egg-info/PKG-INFO +1 -1
  3. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/pyproject.toml +1 -1
  4. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/mixins.py +24 -3
  5. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/serializers.py +19 -19
  6. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/utils.py +8 -4
  7. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/README.md +0 -0
  8. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/maquinaweb_shared_auth.egg-info/SOURCES.txt +0 -0
  9. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/maquinaweb_shared_auth.egg-info/dependency_links.txt +0 -0
  10. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/maquinaweb_shared_auth.egg-info/requires.txt +0 -0
  11. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/maquinaweb_shared_auth.egg-info/top_level.txt +0 -0
  12. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/setup.cfg +0 -0
  13. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/setup.py +0 -0
  14. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/__init__.py +0 -0
  15. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/abstract_models.py +0 -0
  16. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/app.py +0 -0
  17. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/authentication.py +0 -0
  18. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/conf.py +0 -0
  19. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/decorators.py +0 -0
  20. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/exceptions.py +0 -0
  21. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/fields.py +0 -0
  22. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/managers.py +0 -0
  23. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/middleware.py +0 -0
  24. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/models.py +0 -0
  25. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/permissions.py +0 -0
  26. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/router.py +0 -0
  27. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/storage_backend.py +0 -0
  28. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/urls.py +0 -0
  29. {maquinaweb_shared_auth-0.2.37 → maquinaweb_shared_auth-0.2.39}/shared_auth/views.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maquinaweb-shared-auth
3
- Version: 0.2.37
3
+ Version: 0.2.39
4
4
  Summary: Models read-only para autenticação compartilhada entre projetos Django.
5
5
  Author-email: Seu Nome <seuemail@dominio.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maquinaweb-shared-auth
3
- Version: 0.2.37
3
+ Version: 0.2.39
4
4
  Summary: Models read-only para autenticação compartilhada entre projetos Django.
5
5
  Author-email: Seu Nome <seuemail@dominio.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "maquinaweb-shared-auth"
7
- version = "0.2.37"
7
+ version = "0.2.39"
8
8
  description = "Models read-only para autenticação compartilhada entre projetos Django."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.13"
@@ -38,11 +38,26 @@ class OrganizationMixin(models.Model):
38
38
  models.Index(fields=["organization_id"]),
39
39
  ]
40
40
 
41
+ @classmethod
42
+ def prefetch_organizations(cls, queryset, request):
43
+ if not hasattr(request, "_orgs_dict"):
44
+ from shared_auth.utils import get_organization_model
45
+
46
+ Organization = get_organization_model()
47
+ org_ids = list(
48
+ queryset.values_list("organization_id", flat=True).distinct()
49
+ )
50
+ if not org_ids:
51
+ request._orgs_dict = {}
52
+ return queryset
53
+
54
+ orgs_qs = Organization.objects.filter(pk__in=org_ids)
55
+ request._orgs_dict = {org.pk: org for org in orgs_qs}
56
+
57
+ return queryset
58
+
41
59
  @property
42
60
  def organization(self):
43
- """
44
- Acessa organização do banco de auth (lazy loading com cache)
45
- """
46
61
  if not hasattr(self, "_cached_organization"):
47
62
  from shared_auth.utils import get_organization_model
48
63
 
@@ -251,6 +266,12 @@ class LoggedOrganizationMixin(viewsets.ModelViewSet):
251
266
  serializer.save()
252
267
 
253
268
 
269
+ class PrefetchOrganizationsMixin(LoggedOrganizationMixin):
270
+ def get_queryset(self):
271
+ queryset = super().get_queryset()
272
+ return OrganizationMixin.prefetch_organizations(queryset, self.request)
273
+
274
+
254
275
  class TimestampedMixin(models.Model):
255
276
  """
256
277
  Mixin para adicionar timestamps
@@ -79,25 +79,25 @@ class OrganizationSerializerMixin(serializers.ModelSerializer):
79
79
  organization = serializers.SerializerMethodField()
80
80
 
81
81
  def get_organization(self, obj):
82
- """Retorna dados da organização como objeto"""
83
- try:
84
- org = obj.organization
85
- return {
86
- "id": org.pk,
87
- "name": org.name,
88
- "fantasy_name": org.fantasy_name,
89
- "image_organization": org.image_organization.url
90
- if org.image_organization
91
- else None,
92
- "cnpj": org.cnpj,
93
- "email": org.email,
94
- "telephone": org.telephone,
95
- "cellphone": org.cellphone,
96
- "is_branch": org.is_branch,
97
- "is_active": org.is_active(),
98
- }
99
- except Exception:
100
- return None
82
+ req = self.context.get("request")
83
+ org = getattr(req, "_orgs_dict", {}).get(obj.organization_id) if req else None
84
+ return self._serialize_org(org) if org else None
85
+
86
+ def _serialize_org(self, org):
87
+ return {
88
+ "id": org.pk,
89
+ "name": org.name,
90
+ "fantasy_name": org.fantasy_name,
91
+ "image_organization": org.image_organization.url
92
+ if org.image_organization
93
+ else None,
94
+ "cnpj": org.cnpj,
95
+ "email": org.email,
96
+ "telephone": org.telephone,
97
+ "cellphone": org.cellphone,
98
+ "is_branch": org.is_branch,
99
+ "is_active": org.is_active(),
100
+ }
101
101
 
102
102
 
103
103
  class OrganizationListCreateSerializerMixin(
@@ -118,12 +118,16 @@ def get_member_model():
118
118
 
119
119
 
120
120
  def get_organization_serializer():
121
- model_string = get_setting("SHARED_AUTH_ORGANIZATION_SERIALIZER", None)
121
+ import_path_serializer = get_setting("SHARED_AUTH_ORGANIZATION_SERIALIZER", None)
122
122
 
123
- if not model_string:
123
+ if not import_path_serializer:
124
124
  return serializers.ModelSerializer
125
125
 
126
126
  try:
127
- return importlib.import_module(model_string)
128
- except Exception:
127
+ module_path, class_name = import_path_serializer.rsplit(".", 1)
128
+ module = importlib.import_module(module_path)
129
+ serializer_class = getattr(module, class_name)
130
+ return serializer_class
131
+ except Exception as e:
132
+ print(f"Erro ao importar serializer: {import_path_serializer}: {e}")
129
133
  return serializers.ModelSerializer