Skip to content

Commit

Permalink
Merge pull request #44 from Ilhasoft/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
dyohan9 committed Aug 3, 2021
2 parents fcc8016 + a27628d commit c244af2
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=
Expand Down
4 changes: 4 additions & 0 deletions weni/api/v1/account/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Meta:
"short_phone_prefix",
"phone",
"last_update_profile",
"utm",
"email_marketing",
]
ref_name = None

Expand All @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions weni/api/v1/tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
21 changes: 21 additions & 0 deletions weni/authentication/migrations/0006_user_utm.py
Original file line number Diff line number Diff line change
@@ -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"
),
),
]
20 changes: 20 additions & 0 deletions weni/authentication/migrations/0007_user_email_marketing.py
Original file line number Diff line number Diff line change
@@ -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"
),
),
]
8 changes: 8 additions & 0 deletions weni/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"],
},
Expand Down
10 changes: 10 additions & 0 deletions weni/common/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit c244af2

Please sign in to comment.