maquinaweb-shared-auth 0.2.27__py3-none-any.whl → 0.2.28__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.27
3
+ Version: 0.2.28
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
@@ -11,11 +11,11 @@ shared_auth/mixins.py,sha256=BSYNTWYjLRGuxfy7x-uAaNZmrTMsm67ogAQzjrU2DoQ,7388
11
11
  shared_auth/models.py,sha256=vCyssDwKfWRE3ofl6LK_CB1-y5O-_6uvJyGZGoCnb44,6574
12
12
  shared_auth/permissions.py,sha256=FNIp12ePOUlXVp26zNMAyEtzX9kwyP7RuNIgaaCXtPA,2671
13
13
  shared_auth/router.py,sha256=zYidJ7j40lQLrhkCtAQAp-rQLhua_UF0X7SDzYRcV5w,668
14
- shared_auth/serializers.py,sha256=h50UhgOJ6Z6HNtxWjv6OK-Z9F_DOuV-PcCAg6FCzBtU,5125
14
+ shared_auth/serializers.py,sha256=VmajFqnAHB5wyxsdd5_WVegAQygi0KNOMk7vScCPHiQ,7385
15
15
  shared_auth/storage_backend.py,sha256=Eqkjz8aF5UrOpRwYl-J0Td95IObfxnJ8eLQDJVFM3Io,184
16
16
  shared_auth/urls.py,sha256=591wWEWJPaHEGkcOZ8yvfgxddRyOcZLgOc0vNtF7XRI,289
17
17
  shared_auth/views.py,sha256=2hyLnYSWUscfq-jVcskt-ukzDt4vg6IXeKjRDRu9RXk,1519
18
- maquinaweb_shared_auth-0.2.27.dist-info/METADATA,sha256=5xy3iG2RNHGZFu4eC_86xna6tzPpXfefwQLRk0inRJw,26331
19
- maquinaweb_shared_auth-0.2.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
- maquinaweb_shared_auth-0.2.27.dist-info/top_level.txt,sha256=msyYRy02ZV7zz7GR1raUI5LXGFIFn2TIkgkeKZqKufE,12
21
- maquinaweb_shared_auth-0.2.27.dist-info/RECORD,,
18
+ maquinaweb_shared_auth-0.2.28.dist-info/METADATA,sha256=_5GAwOTIYAawX33fPW4kRXYzc1z2Zh_fThPyaLo-Ows,26331
19
+ maquinaweb_shared_auth-0.2.28.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
+ maquinaweb_shared_auth-0.2.28.dist-info/top_level.txt,sha256=msyYRy02ZV7zz7GR1raUI5LXGFIFn2TIkgkeKZqKufE,12
21
+ maquinaweb_shared_auth-0.2.28.dist-info/RECORD,,
@@ -1,12 +1,16 @@
1
1
  """
2
2
  Serializers compartilhados para DRF
3
3
  """
4
- from .models import SharedOrganization, User
4
+
5
5
  from rest_framework import serializers
6
6
 
7
+ from .models import SharedOrganization, User
8
+
9
+
7
10
  class OrganizationSerializerMixin(serializers.ModelSerializer):
8
11
  """
9
12
  Mixin para serializers que incluem dados de organização como objeto aninhado
13
+ e automaticamente setam organization_id no create a partir do request context.
10
14
 
11
15
  Retorna:
12
16
  {
@@ -38,7 +42,9 @@ class OrganizationSerializerMixin(serializers.ModelSerializer):
38
42
  "id": org.pk,
39
43
  "name": org.name,
40
44
  "fantasy_name": org.fantasy_name,
41
- "image_organization": org.image_organization.url if org.image_organization else None,
45
+ "image_organization": org.image_organization.url
46
+ if org.image_organization
47
+ else None,
42
48
  "cnpj": org.cnpj,
43
49
  "email": org.email,
44
50
  "telephone": org.telephone,
@@ -46,9 +52,18 @@ class OrganizationSerializerMixin(serializers.ModelSerializer):
46
52
  "is_branch": org.is_branch,
47
53
  "is_active": org.is_active(),
48
54
  }
49
- except Exception as e:
55
+ except Exception:
50
56
  return None
51
57
 
58
+ def create(self, validated_data):
59
+ """Automatically set organization_id from request context"""
60
+ if self.context.get("request") and hasattr(
61
+ self.context["request"], "organization_id"
62
+ ):
63
+ validated_data["organization_id"] = self.context["request"].organization_id
64
+ return super().create(validated_data)
65
+
66
+
52
67
  class OrganizationSerializer(serializers.ModelSerializer):
53
68
  class Meta:
54
69
  model = SharedOrganization
@@ -71,9 +86,11 @@ class UserSerializer(serializers.ModelSerializer):
71
86
  "last_login",
72
87
  ]
73
88
 
89
+
74
90
  class UserSerializerMixin(serializers.ModelSerializer):
75
91
  """
76
92
  Mixin para serializers que incluem dados de usuário como objeto aninhado
93
+ e automaticamente setam user_id no create a partir do request context.
77
94
 
78
95
  Retorna:
79
96
  {
@@ -111,13 +128,20 @@ class UserSerializerMixin(serializers.ModelSerializer):
111
128
  "full_name": user.get_full_name(),
112
129
  "is_active": user.is_active,
113
130
  }
114
- except Exception as e:
131
+ except Exception:
115
132
  return None
116
133
 
134
+ def create(self, validated_data):
135
+ """Automatically set user_id from request context"""
136
+ if self.context.get("request") and hasattr(self.context["request"], "user"):
137
+ validated_data["user_id"] = self.context["request"].user.id
138
+ return super().create(validated_data)
139
+
117
140
 
118
141
  class OrganizationUserSerializerMixin(OrganizationSerializerMixin, UserSerializerMixin):
119
142
  """
120
143
  Mixin combinado com organization e user como objetos aninhados
144
+ e automaticamente seta organization_id e user_id no create a partir do request context.
121
145
 
122
146
  Retorna:
123
147
  {
@@ -142,13 +166,22 @@ class OrganizationUserSerializerMixin(OrganizationSerializerMixin, UserSerialize
142
166
  fields = ['id', 'titulo', 'conteudo', 'organization', 'user']
143
167
  """
144
168
 
145
- pass
169
+ def create(self, validated_data):
170
+ """Automatically set both organization_id and user_id from request context"""
171
+ if self.context.get("request"):
172
+ request = self.context["request"]
173
+ if hasattr(request, "organization_id"):
174
+ validated_data["organization_id"] = request.organization_id
175
+ if hasattr(request, "user"):
176
+ validated_data["user_id"] = request.user.id
177
+ return super(UserSerializerMixin, self).create(validated_data)
146
178
 
147
179
 
148
180
  # Versões simplificadas (opcional)
149
181
  class OrganizationSimpleSerializerMixin(serializers.ModelSerializer):
150
182
  """
151
183
  Versão simplificada que retorna apenas campos essenciais da organização
184
+ e automaticamente seta organization_id no create a partir do request context.
152
185
  """
153
186
 
154
187
  organization = serializers.SerializerMethodField()
@@ -164,10 +197,19 @@ class OrganizationSimpleSerializerMixin(serializers.ModelSerializer):
164
197
  except:
165
198
  return None
166
199
 
200
+ def create(self, validated_data):
201
+ """Automatically set organization_id from request context"""
202
+ if self.context.get("request") and hasattr(
203
+ self.context["request"], "organization_id"
204
+ ):
205
+ validated_data["organization_id"] = self.context["request"].organization_id
206
+ return super().create(validated_data)
207
+
167
208
 
168
209
  class UserSimpleSerializerMixin(serializers.ModelSerializer):
169
210
  """
170
211
  Versão simplificada que retorna apenas campos essenciais do usuário
212
+ e automaticamente seta user_id no create a partir do request context.
171
213
  """
172
214
 
173
215
  user = serializers.SerializerMethodField()
@@ -182,3 +224,9 @@ class UserSimpleSerializerMixin(serializers.ModelSerializer):
182
224
  }
183
225
  except:
184
226
  return None
227
+
228
+ def create(self, validated_data):
229
+ """Automatically set user_id from request context"""
230
+ if self.context.get("request") and hasattr(self.context["request"], "user"):
231
+ validated_data["user_id"] = self.context["request"].user.id
232
+ return super().create(validated_data)