maquinaweb-shared-auth 0.2.38__py3-none-any.whl → 0.2.40__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maquinaweb-shared-auth
3
- Version: 0.2.38
3
+ Version: 0.2.40
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
@@ -8,16 +8,16 @@ shared_auth/exceptions.py,sha256=VKamHjBl2yjXG2RsMrLrXru1_Q9IJXmy4xmDcXlpWsU,627
8
8
  shared_auth/fields.py,sha256=RAcmFh1D_nkbai_7t_OrPZhfhAipesy5kKnEj4LUvvM,1254
9
9
  shared_auth/managers.py,sha256=OQd76OeAkeyRoFnifQ0zZdp45h27QVwBpR0BgiiTFbQ,6968
10
10
  shared_auth/middleware.py,sha256=A8yc8Ld4EslEcPCdekfCrU7eAXgql_AntYjy1xMchu8,6335
11
- shared_auth/mixins.py,sha256=kcTkjrNu-UGLwXQHsq9vQDx7qQjILa3Na8HvouLU3Ms,7588
11
+ shared_auth/mixins.py,sha256=gaoJcAt2xmGR_2FWJ85rKJohBhvIaS7_U7EhwvBrd28,8379
12
12
  shared_auth/models.py,sha256=HCVIog61J0xeygYIs_amSA-MsSRhxIlGTSkegA9b51c,1444
13
13
  shared_auth/permissions.py,sha256=l48n9qCUMrhQOTa5_Cv1vynv-bb3i5T05yLoyKvKmOM,2713
14
14
  shared_auth/router.py,sha256=JhlDjosViMBmuvYm08vJzKyvrg5P5ECtrU4tKAGsuoU,684
15
- shared_auth/serializers.py,sha256=GCypQOZJvsUHxxYOwrVt0PvV7ePPr3Dqed_BIymfULk,14255
15
+ shared_auth/serializers.py,sha256=V-FqMMZCj71gIXw292230Ax-eXqz4EQ4esPmo-NhQz8,14322
16
16
  shared_auth/storage_backend.py,sha256=Eqkjz8aF5UrOpRwYl-J0Td95IObfxnJ8eLQDJVFM3Io,184
17
17
  shared_auth/urls.py,sha256=591wWEWJPaHEGkcOZ8yvfgxddRyOcZLgOc0vNtF7XRI,289
18
18
  shared_auth/utils.py,sha256=E3Ox5FA1D6OHfesZV8Z5D-T4h-zhpHbiHQYfdmRDH8U,4119
19
19
  shared_auth/views.py,sha256=2hyLnYSWUscfq-jVcskt-ukzDt4vg6IXeKjRDRu9RXk,1519
20
- maquinaweb_shared_auth-0.2.38.dist-info/METADATA,sha256=otqotf7PbIaKkB2lYH8jCGr-fjmKVSOH50Okzr-TE2k,26325
21
- maquinaweb_shared_auth-0.2.38.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
- maquinaweb_shared_auth-0.2.38.dist-info/top_level.txt,sha256=msyYRy02ZV7zz7GR1raUI5LXGFIFn2TIkgkeKZqKufE,12
23
- maquinaweb_shared_auth-0.2.38.dist-info/RECORD,,
20
+ maquinaweb_shared_auth-0.2.40.dist-info/METADATA,sha256=ShSEN-12F39dplOh5DDy9dw7OaJwmhiHSWcFCmtywBk,26325
21
+ maquinaweb_shared_auth-0.2.40.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
+ maquinaweb_shared_auth-0.2.40.dist-info/top_level.txt,sha256=msyYRy02ZV7zz7GR1raUI5LXGFIFn2TIkgkeKZqKufE,12
23
+ maquinaweb_shared_auth-0.2.40.dist-info/RECORD,,
shared_auth/mixins.py CHANGED
@@ -38,11 +38,27 @@ class OrganizationMixin(models.Model):
38
38
  models.Index(fields=["organization_id"]),
39
39
  ]
40
40
 
41
+ @classmethod
42
+ def prefetch_organizations(cls, queryset, request, org_ids=None):
43
+ if not hasattr(request, "_orgs_dict"):
44
+ from shared_auth.utils import get_organization_model
45
+
46
+ Organization = get_organization_model()
47
+ if org_ids is None:
48
+ org_ids = list(
49
+ queryset.values_list("organization_id", flat=True).distinct()
50
+ )
51
+ if not org_ids:
52
+ request._orgs_dict = {}
53
+ return queryset
54
+
55
+ orgs_qs = Organization.objects.filter(pk__in=org_ids)
56
+ request._orgs_dict = {org.pk: org for org in orgs_qs}
57
+
58
+ return queryset
59
+
41
60
  @property
42
61
  def organization(self):
43
- """
44
- Acessa organização do banco de auth (lazy loading com cache)
45
- """
46
62
  if not hasattr(self, "_cached_organization"):
47
63
  from shared_auth.utils import get_organization_model
48
64
 
@@ -251,6 +267,12 @@ class LoggedOrganizationMixin(viewsets.ModelViewSet):
251
267
  serializer.save()
252
268
 
253
269
 
270
+ class PrefetchOrganizationsMixin(LoggedOrganizationMixin):
271
+ def get_queryset(self):
272
+ queryset = super().get_queryset()
273
+ return OrganizationMixin.prefetch_organizations(queryset, self.request)
274
+
275
+
254
276
  class TimestampedMixin(models.Model):
255
277
  """
256
278
  Mixin para adicionar timestamps
@@ -79,25 +79,27 @@ 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
+ if org:
85
+ return self._serialize_org(org)
86
+ return self._serialize_org(obj.organization)
87
+
88
+ def _serialize_org(self, org):
89
+ return {
90
+ "id": org.pk,
91
+ "name": org.name,
92
+ "fantasy_name": org.fantasy_name,
93
+ "image_organization": org.image_organization.url
94
+ if org.image_organization
95
+ else None,
96
+ "cnpj": org.cnpj,
97
+ "email": org.email,
98
+ "telephone": org.telephone,
99
+ "cellphone": org.cellphone,
100
+ "is_branch": org.is_branch,
101
+ "is_active": org.is_active(),
102
+ }
101
103
 
102
104
 
103
105
  class OrganizationListCreateSerializerMixin(