Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dyohan9 committed Jan 22, 2021
2 parents 2be6b71 + 0cbdb2d commit ce6468c
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 7 deletions.
3 changes: 2 additions & 1 deletion weni/api/v1/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
from weni.api.v1.keycloak import KeycloakControl
from weni.authentication.models import User
from weni.common.models import Service
from weni.utils import upload_photo_rocket


Expand Down Expand Up @@ -67,7 +68,7 @@ def upload_photo(self, request, **kwargs): # pragma: no cover

# Update avatar in all rocket chat registered
for service in self.request.user.service_status.filter(
service__rocket_chat=True
service__type_service=Service.TYPE_SERVICE_CHAT
):
upload_photo_rocket(
server_rocket=service.service.url,
Expand Down
13 changes: 11 additions & 2 deletions weni/api/v1/dashboard/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers

from weni.authentication.models import User
from weni.common.models import Newsletter, ServiceStatus
from weni.common.models import Newsletter, ServiceStatus, Service


class NewsletterSerializer(serializers.ModelSerializer):
Expand All @@ -22,6 +23,7 @@ class Meta:
"service__url",
"service__default",
"service__last_updated",
"service__type_service",
"created_at",
]
ref_name = None
Expand All @@ -30,6 +32,13 @@ class Meta:
service__url = serializers.CharField(source="service.url")
service__default = serializers.BooleanField(source="service.default")
service__last_updated = serializers.DateTimeField(source="service.last_updated")
service__type_service = serializers.ChoiceField(
choices=Service.TYPE_SERVICE_CHOICES,
default=Service.TYPE_SERVICE_CHAT,
label=_("Type Service"),
source="service.type_service",
read_only=True
)


class DashboardInfoSerializer(serializers.ModelSerializer):
Expand All @@ -45,7 +54,7 @@ def get_menu(self, obj):
"inteligence": settings.INTELIGENCE_URL,
"flows": settings.FLOWS_URL,
"chat": list(
obj.service_status.filter(service__rocket_chat=True).values_list(
obj.service_status.filter(service__type_service=Service.TYPE_SERVICE_CHAT).values_list(
"service__url", flat=True
)
),
Expand Down
3 changes: 2 additions & 1 deletion weni/api/v1/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class StatusServiceViewSet(mixins.ListModelMixin, GenericViewSet):

def get_queryset(self, *args, **kwargs):
return self.queryset.filter(
Q(user=self.request.user) & Q(service__default=True)
(Q(user=self.request.user) & Q(service__default=True))
| Q(user=self.request.user)
)


Expand Down
2 changes: 1 addition & 1 deletion weni/api/v1/tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def setUp(self):
self.factory = RequestFactory()

self.service = Service.objects.create(
url="http://test-rocketchat.com", status=False, rocket_chat=True
url="http://test-rocketchat.com", status=False, type_service=Service.TYPE_SERVICE_CHAT
)

self.user, self.token = create_user_and_token()
Expand Down
36 changes: 36 additions & 0 deletions weni/common/migrations/0005_service_type_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 2.2.17 on 2021-01-22 19:07

from django.db import migrations, models


def noop(apps, schema_editor): # pragma: no cover
pass


def migrate(apps, schema_editor): # pragma: no cover
Service = apps.get_model("common", "Service")

for service in Service.objects.all():
if service.rocket_chat:
service.type_service = "type_service_chat"
service.save(update_fields=["type_service"])


class Migration(migrations.Migration):

dependencies = [
('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'),
),
migrations.RunPython(migrate, noop),
migrations.RemoveField(
model_name='service',
name='rocket_chat',
),
]
26 changes: 25 additions & 1 deletion weni/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,33 @@ class Service(models.Model):
class Meta:
verbose_name = _("service")

TYPE_SERVICE_FLOWS = "type_service_flows"
TYPE_SERVICE_INTELIGENCE = "type_service_inteligence"
TYPE_SERVICE_CHAT = "type_service_chat"

TYPE_SERVICE_CHOICES = [
(
TYPE_SERVICE_FLOWS,
_("Flows service"),
),
(
TYPE_SERVICE_INTELIGENCE,
_("Inteligence Service"),
),
(
TYPE_SERVICE_CHAT,
_("Chat Service"),
),
]

url = models.URLField(_("service url"), unique=True)
status = models.BooleanField(_("status service"), default=False)
rocket_chat = models.BooleanField(_("is it a rocketchat server?"), default=False)
type_service = models.CharField(
_("type service"),
max_length=50,
choices=TYPE_SERVICE_CHOICES,
default=TYPE_SERVICE_CHAT,
)
created_at = models.DateTimeField(_("created at"), auto_now_add=True)
last_updated = models.DateTimeField(_("last updated"), auto_now_add=True)
default = models.BooleanField(_("service default"), default=False)
Expand Down
2 changes: 1 addition & 1 deletion weni/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
schema_view = get_schema_view(
openapi.Info(
title="API Documentation",
default_version="v1.0.5",
default_version="v1.0.8",
license=openapi.License(name="GPL-3.0 License"),
),
public=True,
Expand Down

0 comments on commit ce6468c

Please sign in to comment.