maquinaweb-shared-auth 0.2.40__py3-none-any.whl → 0.2.42__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.40
3
+ Version: 0.2.42
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
@@ -7,8 +7,8 @@ shared_auth/decorators.py,sha256=-2RHRzvPJzN0c8Q-cB1_hf5tk386jcHZ9-GixKSe0ds,334
7
7
  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
- shared_auth/middleware.py,sha256=A8yc8Ld4EslEcPCdekfCrU7eAXgql_AntYjy1xMchu8,6335
11
- shared_auth/mixins.py,sha256=gaoJcAt2xmGR_2FWJ85rKJohBhvIaS7_U7EhwvBrd28,8379
10
+ shared_auth/middleware.py,sha256=f8KbWI0HowPrxPgHRVd7ByFcMSGjhpR40s34E61W_uU,6954
11
+ shared_auth/mixins.py,sha256=PKu055ey-HsHxc14VbSt1IzYxA-OEtqACxRaJ4_ViuQ,8646
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
@@ -17,7 +17,7 @@ shared_auth/storage_backend.py,sha256=Eqkjz8aF5UrOpRwYl-J0Td95IObfxnJ8eLQDJVFM3I
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.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,,
20
+ maquinaweb_shared_auth-0.2.42.dist-info/METADATA,sha256=OI7q3qHFt2nbcdg0Ajbs6h_eshZYavN7TamsiTHwK2I,26325
21
+ maquinaweb_shared_auth-0.2.42.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
+ maquinaweb_shared_auth-0.2.42.dist-info/top_level.txt,sha256=msyYRy02ZV7zz7GR1raUI5LXGFIFn2TIkgkeKZqKufE,12
23
+ maquinaweb_shared_auth-0.2.42.dist-info/RECORD,,
shared_auth/middleware.py CHANGED
@@ -155,6 +155,7 @@ class OrganizationMiddleware(MiddlewareMixin):
155
155
 
156
156
  organization_id = self._determine_organization_id(request)
157
157
  user = self._authenticate_user(request)
158
+ request.user = user
158
159
 
159
160
  if not organization_id and not user:
160
161
  return
@@ -166,7 +167,10 @@ class OrganizationMiddleware(MiddlewareMixin):
166
167
  if not organization_id:
167
168
  return
168
169
 
170
+ organization_ids = self._determine_organization_ids(request)
171
+
169
172
  request.organization_id = organization_id
173
+ request.organization_ids = organization_ids
170
174
  Organization = get_organization_model()
171
175
  request.organization = Organization.objects.filter(pk=organization_id).first()
172
176
 
@@ -183,6 +187,9 @@ class OrganizationMiddleware(MiddlewareMixin):
183
187
 
184
188
  return self._get_organization_from_user(request)
185
189
 
190
+ def _determine_organization_ids(self, request):
191
+ return self._get_organization_ids_from_user(request)
192
+
186
193
  @staticmethod
187
194
  def _get_organization_from_header(request):
188
195
  if header_value := request.headers.get("X-Organization"):
@@ -206,6 +213,18 @@ class OrganizationMiddleware(MiddlewareMixin):
206
213
 
207
214
  return member.organization_id if member else None
208
215
 
216
+ @staticmethod
217
+ def _get_organization_ids_from_user(request):
218
+ if not request.user.is_authenticated:
219
+ return None
220
+
221
+ Member = get_member_model()
222
+ member = Member.objects.filter(user_id=request.user.pk)
223
+
224
+ return (
225
+ list(member.values_list("organization_id", flat=True)) if member else None
226
+ )
227
+
209
228
  @staticmethod
210
229
  def _validate_organization_membership(user, organization_id):
211
230
  try:
shared_auth/mixins.py CHANGED
@@ -28,7 +28,10 @@ class OrganizationMixin(models.Model):
28
28
  """
29
29
 
30
30
  organization_id = models.IntegerField(
31
- db_index=True, help_text="ID da organização no sistema de autenticação"
31
+ db_index=True,
32
+ help_text="ID da organização no sistema de autenticação",
33
+ null=True,
34
+ default=None,
32
35
  )
33
36
  objects = BaseAuthManager()
34
37
 
@@ -109,7 +112,10 @@ class UserMixin(models.Model):
109
112
  """
110
113
 
111
114
  user_id = models.IntegerField(
112
- db_index=True, help_text="ID do usuário no sistema de autenticação"
115
+ db_index=True,
116
+ help_text="ID do usuário no sistema de autenticação",
117
+ null=True,
118
+ default=None,
113
119
  )
114
120
  objects = BaseAuthManager()
115
121
 
@@ -219,6 +225,10 @@ class LoggedOrganizationMixin(viewsets.ModelViewSet):
219
225
  """Obtém o ID da organização logada via maquinaweb-shared-auth"""
220
226
  return self.request.organization_id
221
227
 
228
+ def get_organization_ids(self):
229
+ """Obtém os IDs das organizações permitidas via maquinaweb-shared-auth"""
230
+ return self.request.organization_ids
231
+
222
232
  def get_user(self):
223
233
  """Obtém o usuário atual autenticado"""
224
234
  return self.request.user