diff --git a/.travis.yml b/.travis.yml index 6060fb82..50c18502 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,33 @@ python: services: - docker + +before_install: + # install the chosen PG version + - sudo -E apt-get -yq --no-install-suggests --no-install-recommends install postgresql-11 postgresql-client-11 + - sudo -E sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf + - sudo -E sed -i 's/port = 5433/port = 5432/' /etc/postgresql/*/main/postgresql.conf + + # give PG some time to finish setup + - sleep 10 + + # stop any running postgres versions + - sudo -E service postgresql stop 10 + - sudo -E ps axuwww | grep -i postg + + # possibly a Travis bug but data directory sometimes not initialized + - if [ ! -d /var/ramfs/postgresql/11/main ]; then sudo -u postgres /usr/lib/postgresql/11/bin/initdb -D /var/ramfs/postgresql/11/main; fi + + # start the chosen PG version + - sudo -E systemctl -l restart postgresql@11-main + - sudo -E systemctl -l status postgresql@11-main + +before_script: + # setup test database + - psql -U postgres -c "CREATE USER connect WITH PASSWORD 'connect';" + - psql -U postgres -c "ALTER ROLE connect WITH SUPERUSER;" + - psql -U connect postgres -c "CREATE DATABASE connect;" + install: - pip install pipenv - pipenv install --system --dev @@ -17,6 +44,7 @@ install: env: global: - SECRET_KEY=SK + - DEFAULT_DATABASE="postgres://connect:connect@localhost:5432/connect" - OIDC_RP_SERVER_URL= - OIDC_RP_REALM_NAME= - OIDC_RP_CLIENT_ID= diff --git a/weni/api/v1/account/serializers.py b/weni/api/v1/account/serializers.py index 403160d3..5376c395 100644 --- a/weni/api/v1/account/serializers.py +++ b/weni/api/v1/account/serializers.py @@ -22,6 +22,8 @@ class Meta: "short_phone_prefix", "phone", "last_update_profile", + "utm", + "email_marketing", ] ref_name = None @@ -40,6 +42,8 @@ class Meta: help_text=_("Phone number of the user; include area code"), ) last_update_profile = serializers.DateTimeField(read_only=True) + utm = serializers.JSONField(required=False, initial=dict) + email_marketing = serializers.BooleanField(required=False) def update(self, instance, validated_data): instance.last_update_profile = timezone.now() diff --git a/weni/api/v1/tests/test_account.py b/weni/api/v1/tests/test_account.py index b66cf2bb..03cfbc01 100644 --- a/weni/api/v1/tests/test_account.py +++ b/weni/api/v1/tests/test_account.py @@ -55,6 +55,13 @@ def test_update_phone(self): self.assertEqual(content_data.get("phone"), 996498826) self.assertEqual(content_data.get("short_phone_prefix"), 55) + def test_update_utm(self): + response, content_data = self.request( + self.user, {"utm": json.dumps("{'utm_source': 'weni'}")}, self.user_token + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(content_data.get("utm"), "{'utm_source': 'weni'}") + class DestroyMyProfileTestCase(TestCase): def setUp(self): diff --git a/weni/authentication/migrations/0006_user_utm.py b/weni/authentication/migrations/0006_user_utm.py new file mode 100644 index 00000000..8548aa69 --- /dev/null +++ b/weni/authentication/migrations/0006_user_utm.py @@ -0,0 +1,21 @@ +# Generated by Django 2.2.19 on 2021-07-16 13:38 + +import django.contrib.postgres.fields.jsonb +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("authentication", "0005_user_last_update_profile"), + ] + + operations = [ + migrations.AddField( + model_name="user", + name="utm", + field=django.contrib.postgres.fields.jsonb.JSONField( + default=dict, verbose_name="UTM Marketing" + ), + ), + ] diff --git a/weni/authentication/migrations/0007_user_email_marketing.py b/weni/authentication/migrations/0007_user_email_marketing.py new file mode 100644 index 00000000..5c8ccd3f --- /dev/null +++ b/weni/authentication/migrations/0007_user_email_marketing.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.19 on 2021-07-16 15:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("authentication", "0006_user_utm"), + ] + + operations = [ + migrations.AddField( + model_name="user", + name="email_marketing", + field=models.BooleanField( + default=True, verbose_name="Allows receiving marketing emails" + ), + ), + ] diff --git a/weni/authentication/models.py b/weni/authentication/models.py index 67ca2c43..a33fa01a 100644 --- a/weni/authentication/models.py +++ b/weni/authentication/models.py @@ -4,6 +4,7 @@ from django.contrib.auth.models import PermissionsMixin from django.contrib.auth.tokens import PasswordResetTokenGenerator from django.contrib.auth.validators import UnicodeUsernameValidator +from django.contrib.postgres.fields import JSONField from django.core.mail import send_mail from django.db import models from django.template.loader import render_to_string @@ -99,6 +100,11 @@ class Meta: null=True, ) + utm = JSONField(verbose_name=_("UTM Marketing"), default=dict) + email_marketing = models.BooleanField( + verbose_name=_("Allows receiving marketing emails"), default=True + ) + objects = UserManager() @property @@ -136,6 +142,8 @@ def send_request_flow_user_info(self): "language": self.language, "short_phone_prefix": self.short_phone_prefix, "phone": self.phone, + "utm": self.utm, + "email_marketing": self.email_marketing, }, "urns": [f"mailto:{self.email}"], }, diff --git a/weni/common/signals.py b/weni/common/signals.py index 72ed6e12..4e4c9068 100644 --- a/weni/common/signals.py +++ b/weni/common/signals.py @@ -22,6 +22,16 @@ def create_service_status(sender, instance, created, **kwargs): for service in Service.objects.filter(default=True): instance.service_status.create(service=service) + for permission in instance.organization.authorizations.all(): + celery_app.send_task( + "update_user_permission_project", + args=[ + instance.flow_organization, + permission.user.email, + permission.role, + ], + ) + @receiver(post_save, sender=Service) def create_service_default_in_all_user(sender, instance, created, **kwargs):