maquinaweb-shared-auth 0.2.26__tar.gz → 0.2.28__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 (27) hide show
  1. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/PKG-INFO +1 -1
  2. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/maquinaweb_shared_auth.egg-info/PKG-INFO +1 -1
  3. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/pyproject.toml +1 -1
  4. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/models.py +11 -9
  5. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/serializers.py +53 -5
  6. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/README.md +0 -0
  7. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/maquinaweb_shared_auth.egg-info/SOURCES.txt +0 -0
  8. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/maquinaweb_shared_auth.egg-info/dependency_links.txt +0 -0
  9. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/maquinaweb_shared_auth.egg-info/requires.txt +0 -0
  10. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/maquinaweb_shared_auth.egg-info/top_level.txt +0 -0
  11. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/setup.cfg +0 -0
  12. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/setup.py +0 -0
  13. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/__init__.py +0 -0
  14. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/app.py +0 -0
  15. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/authentication.py +0 -0
  16. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/conf.py +0 -0
  17. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/decorators.py +0 -0
  18. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/exceptions.py +0 -0
  19. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/fields.py +0 -0
  20. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/managers.py +0 -0
  21. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/middleware.py +0 -0
  22. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/mixins.py +0 -0
  23. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/permissions.py +0 -0
  24. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/router.py +0 -0
  25. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/storage_backend.py +0 -0
  26. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/shared_auth/urls.py +0 -0
  27. {maquinaweb_shared_auth-0.2.26 → maquinaweb_shared_auth-0.2.28}/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.26
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maquinaweb-shared-auth
3
- Version: 0.2.26
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "maquinaweb-shared-auth"
7
- version = "0.2.26"
7
+ version = "0.2.28"
8
8
  description = "Models read-only para autenticação compartilhada entre projetos Django."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.13"
@@ -3,16 +3,15 @@ Models READ-ONLY para acesso aos dados de autenticação
3
3
  ATENÇÃO: Estes models NÃO devem ser usados para criar migrations
4
4
  """
5
5
 
6
+ import os
7
+
6
8
  from django.contrib.auth.models import AbstractUser
7
9
  from django.db import models
10
+
11
+ from .conf import MEMBER_TABLE, ORGANIZATION_TABLE, TOKEN_TABLE, USER_TABLE
8
12
  from .exceptions import OrganizationNotFoundError
9
- from .conf import MEMBER_TABLE, ORGANIZATION_TABLE, USER_TABLE, TOKEN_TABLE
13
+ from .managers import SharedMemberManager, SharedOrganizationManager, SharedUserManager
10
14
  from .storage_backend import Storage
11
- from .managers import (
12
- SharedMemberManager,
13
- SharedOrganizationManager,
14
- SharedUserManager,
15
- )
16
15
 
17
16
 
18
17
  class SharedToken(models.Model):
@@ -46,6 +45,7 @@ class SharedToken(models.Model):
46
45
  # Implementar lógica de expiração se necessário
47
46
  return True
48
47
 
48
+
49
49
  def organization_image_path(instance, filename):
50
50
  return os.path.join(
51
51
  "organization",
@@ -54,6 +54,7 @@ def organization_image_path(instance, filename):
54
54
  filename,
55
55
  )
56
56
 
57
+
57
58
  class SharedOrganization(models.Model):
58
59
  """
59
60
  Model READ-ONLY da tabela organization
@@ -67,7 +68,9 @@ class SharedOrganization(models.Model):
67
68
  telephone = models.CharField(max_length=50, blank=True, null=True)
68
69
  cellphone = models.CharField(max_length=50, blank=True, null=True)
69
70
  email = models.EmailField(blank=True, null=True)
70
- image_organization = models.ImageField(storage=Storage, upload_to=organization_image_path, null=True)
71
+ image_organization = models.ImageField(
72
+ storage=Storage, upload_to=organization_image_path, null=True
73
+ )
71
74
 
72
75
  # Relacionamentos
73
76
  main_organization_id = models.IntegerField(null=True, blank=True)
@@ -146,7 +149,7 @@ class User(AbstractUser):
146
149
 
147
150
  date_joined = models.DateTimeField()
148
151
  last_login = models.DateTimeField(null=True, blank=True)
149
- avatar = models.ImageField(storage=Storage,blank=True, null=True)
152
+ avatar = models.ImageField(storage=Storage, blank=True, null=True)
150
153
  # Campos customizados
151
154
  createdat = models.DateTimeField()
152
155
  updatedat = models.DateTimeField()
@@ -188,7 +191,6 @@ class User(AbstractUser):
188
191
  return organization
189
192
 
190
193
 
191
-
192
194
  class SharedMember(models.Model):
193
195
  """
194
196
  Model READ-ONLY da tabela organization_member
@@ -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)