From 6fc8d816c0987c512e53615b4cd69f816543a070 Mon Sep 17 00:00:00 2001 From: LeandroJatai Date: Tue, 6 Sep 2022 00:23:16 -0300 Subject: [PATCH] =?UTF-8?q?HOT-FIX:=20corrige=20display,edi=C3=A7=C3=A3o?= =?UTF-8?q?=20e=20cria=C3=A7=C3=A3o=20de=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Em uma instalação do zero via docker, os usuários criados por docker/create_admin.py, ao que parece, não aciona o post_save de criação de token, desta forma os usuários ficam sem token e trava a tela de detail e update destes na Administração de usuário. --- sapl/api/views.py | 2 +- sapl/base/forms.py | 3 ++- sapl/base/views.py | 2 +- sapl/templates/base/layouts.yaml | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sapl/api/views.py b/sapl/api/views.py index 1c2bc988e..cfbea93a8 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -20,7 +20,7 @@ def create_auth_token(sender, instance=None, created=False, **kwargs): @api_view(['POST']) @permission_classes([IsAdminUser]) def recria_token(request, pk): - Token.objects.get(user_id=pk).delete() + Token.objects.filter(user_id=pk).delete() token = Token.objects.create(user_id=pk) return Response({"message": "Token recriado com sucesso!", "token": token.key}) diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 99d6842ad..292548b18 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -183,7 +183,8 @@ class UserAdminForm(ModelForm): else: operadorautor = self.instance.operadorautor_set.first() votante = self.instance.votante_set.first() - self.fields['token'].initial = self.instance.auth_token.key + self.fields['token'].initial = self.instance.auth_token.key \ + if hasattr(self.instance, 'auth_token') else '' self.fields['autor'].initial = operadorautor.autor if operadorautor else None self.fields['parlamentar'].initial = votante.parlamentar if votante else None diff --git a/sapl/base/views.py b/sapl/base/views.py index 05a6c8f49..e61ce624d 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -1937,7 +1937,7 @@ class UserCrud(Crud): ) def hook_auth_token(self, obj): - return 'Token', str(obj.auth_token) + return 'Token', str(obj.auth_token) if hasattr(obj, 'auth_token') else ' ' def hook_username(self, obj): return 'username', obj.username diff --git a/sapl/templates/base/layouts.yaml b/sapl/templates/base/layouts.yaml index e9029810d..b918af8a7 100644 --- a/sapl/templates/base/layouts.yaml +++ b/sapl/templates/base/layouts.yaml @@ -13,8 +13,8 @@ CasaLegislativa: UserDetail: {% trans 'Usuário' %}: - usuario username:3 is_active:2 - - auth_token votante_set__parlamentar|m2m_urlize_for_detail operadorautor_set__autor|m2m_urlize_for_detail - - groups + - votante_set__parlamentar|m2m_urlize_for_detail operadorautor_set__autor|m2m_urlize_for_detail + - groups auth_token:5 - user_permissions AppConfig: