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: