From 475df7fd676fc726d3a333b14a220550ebd8f0b8 Mon Sep 17 00:00:00 2001 From: Daniel Yohan Date: Wed, 27 Jan 2021 11:01:32 -0300 Subject: [PATCH 1/2] fix send email --- weni/api/v1/account/views.py | 10 ++++----- weni/api/v1/dashboard/serializers.py | 8 +++---- weni/api/v1/tests/test_dashboard.py | 4 +++- weni/authentication/signals.py | 15 ++++++++----- .../migrations/0005_service_type_service.py | 21 +++++++++++++------ weni/settings.py | 5 +++++ 6 files changed, 41 insertions(+), 22 deletions(-) diff --git a/weni/api/v1/account/views.py b/weni/api/v1/account/views.py index cdae7ee2..4fdd2b47 100644 --- a/weni/api/v1/account/views.py +++ b/weni/api/v1/account/views.py @@ -1,5 +1,4 @@ import filetype -from django.conf import settings from django.utils.translation import ugettext_lazy as _ from keycloak import KeycloakGetError from rest_framework import mixins, permissions, parsers @@ -120,10 +119,9 @@ def change_password(self, request, **kwargs): # pragma: no cover user_id=user_id, password=request.data.get("password"), temporary=False ) self.request.user.send_change_password_email() - except KeycloakGetError: - if not settings.DEBUG: - raise ValidationError( - _("System temporarily unavailable, please try again later.") - ) + except KeycloakGetError or ValidationError: + raise ValidationError( + _("System temporarily unavailable, please try again later.") + ) return Response() diff --git a/weni/api/v1/dashboard/serializers.py b/weni/api/v1/dashboard/serializers.py index d716f3d6..360bb8c8 100644 --- a/weni/api/v1/dashboard/serializers.py +++ b/weni/api/v1/dashboard/serializers.py @@ -37,7 +37,7 @@ class Meta: default=Service.TYPE_SERVICE_CHAT, label=_("Type Service"), source="service.type_service", - read_only=True + read_only=True, ) @@ -54,8 +54,8 @@ def get_menu(self, obj): "inteligence": settings.INTELIGENCE_URL, "flows": settings.FLOWS_URL, "chat": list( - obj.service_status.filter(service__type_service=Service.TYPE_SERVICE_CHAT).values_list( - "service__url", flat=True - ) + obj.service_status.filter( + service__type_service=Service.TYPE_SERVICE_CHAT + ).values_list("service__url", flat=True) ), } diff --git a/weni/api/v1/tests/test_dashboard.py b/weni/api/v1/tests/test_dashboard.py index fc8ac974..63e21e84 100644 --- a/weni/api/v1/tests/test_dashboard.py +++ b/weni/api/v1/tests/test_dashboard.py @@ -40,7 +40,9 @@ def setUp(self): self.factory = RequestFactory() self.service = Service.objects.create( - url="http://test-rocketchat.com", status=False, type_service=Service.TYPE_SERVICE_CHAT + url="http://test-rocketchat.com", + status=False, + type_service=Service.TYPE_SERVICE_CHAT, ) self.user, self.token = create_user_and_token() diff --git a/weni/authentication/signals.py b/weni/authentication/signals.py index a89bfe68..5b65d992 100644 --- a/weni/authentication/signals.py +++ b/weni/authentication/signals.py @@ -1,3 +1,5 @@ +import logging + from django.conf import settings from django.db import models from django.dispatch import receiver @@ -9,6 +11,9 @@ from weni.authentication.models import User +logger = logging.getLogger("weni.authentication.signals") + + @receiver(models.signals.pre_save, sender=User) def update_user_keycloak(instance, **kwargs): if not settings.TESTING: @@ -23,8 +28,8 @@ def update_user_keycloak(instance, **kwargs): "lastName": instance.last_name, }, ) - except exceptions.KeycloakGetError: - if not settings.DEBUG: - raise ValidationError( - _("System temporarily unavailable, please try again later.") - ) + except exceptions.KeycloakGetError as e: + logger.error(e) + raise ValidationError( + _("System temporarily unavailable, please try again later.") + ) diff --git a/weni/common/migrations/0005_service_type_service.py b/weni/common/migrations/0005_service_type_service.py index 85c3bf8f..16404e3a 100644 --- a/weni/common/migrations/0005_service_type_service.py +++ b/weni/common/migrations/0005_service_type_service.py @@ -19,18 +19,27 @@ def migrate(apps, schema_editor): # pragma: no cover class Migration(migrations.Migration): dependencies = [ - ('common', '0004_auto_20210114_1405'), + ("common", "0004_auto_20210114_1405"), ] operations = [ migrations.AddField( - model_name='service', - name='type_service', - field=models.CharField(choices=[('type_service_flows', 'Flows service'), ('type_service_inteligence', 'Inteligence Service'), ('type_service_chat', 'Chat Service')], default='type_service_chat', max_length=50, verbose_name='type service'), + model_name="service", + name="type_service", + field=models.CharField( + choices=[ + ("type_service_flows", "Flows service"), + ("type_service_inteligence", "Inteligence Service"), + ("type_service_chat", "Chat Service"), + ], + default="type_service_chat", + max_length=50, + verbose_name="type service", + ), ), migrations.RunPython(migrate, noop), migrations.RemoveField( - model_name='service', - name='rocket_chat', + model_name="service", + name="rocket_chat", ), ] diff --git a/weni/settings.py b/weni/settings.py index f2f01ae8..0928a5df 100644 --- a/weni/settings.py +++ b/weni/settings.py @@ -220,6 +220,11 @@ "handlers": ["console"], "propagate": False, } +LOGGING["loggers"]["weni.authentication.signals"] = { + "level": "ERROR", + "handlers": ["console"], + "propagate": False, +} # rest framework From eaf0b59dfc8d86150a6d778d69e7410babdfef01 Mon Sep 17 00:00:00 2001 From: Daniel Yohan Date: Wed, 27 Jan 2021 11:09:19 -0300 Subject: [PATCH 2/2] Updated README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f1bcff44..935bb54f 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ You can set environment variables in your OS, write on ```.env``` file or pass v | EMAIL_HOST_PASSWORD | ```string``` | ```''``` | Password to use for the SMTP server defined in ```EMAIL_HOST```. | EMAIL_USE_SSL | ```boolean``` | ```False``` | Whether to use an implicit TLS (secure) connection when talking to the SMTP server. | EMAIL_USE_TLS | ```boolean``` | ```False``` | Whether to use a TLS (secure) connection when talking to the SMTP server. -| SEND_EMAILS | ```boolean``` | ```False``` | Send emails flag. +| SEND_EMAILS | ```boolean``` | ```True``` | Send emails flag. | INTELIGENCE_URL | ```string``` | ```https://bothub.it/``` | Specify the URL of the intelligence service. | FLOWS_URL | ```string``` | ```https://new.push.al/``` | Specify the URL of the flows service. | USE_SENTRY | ```bool``` | ```False``` | Enable Support Sentry @@ -58,7 +58,7 @@ You can set environment variables in your OS, write on ```.env``` file or pass v ## License -Distributed under the GPL-3.0 License. See `LICENSE` for more information. +Distributed under the MPL-2.0 License. See `LICENSE` for more information. ## Contributing