Skip to content

Commit a2542fd

Browse files
authored
Merge pull request #5 from City-of-Helsinki/release/0.1.0
Release/0.1.0
2 parents 874845d + 1e56184 commit a2542fd

42 files changed

Lines changed: 731 additions & 120 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitlab-ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,27 @@ staging:
4242
K8S_SECRET_DEFAULT_FROM_EMAIL: "no-reply@hel.ninja"
4343
K8S_SECRET_SENTRY_DSN: "$GL_SENTRY_DNS"
4444
K8S_SECRET_SENTRY_ENVIRONMENT: "test"
45+
K8S_SECRET_QURIIRI_API_KEY: "$GL_QURIIRI_API_KEY"
46+
K8S_SECRET_QURIIRI_API_URL: "$GL_QURIIRI_API_URL"
47+
production:
48+
# It is highly discouraged to define own triggering rules in production. Don't do it.
49+
# only:
50+
# refs:
51+
# - master
52+
# These variables are available only for production env and are merged with the general variables defined above
53+
variables:
54+
K8S_SECRET_ALLOWED_HOSTS: "*"
55+
K8S_SECRET_CORS_ORIGIN_ALLOW_ALL: 1
56+
K8S_SECRET_SECRET_KEY: "$GL_PRODUCTION_DJANGO_SECRET_KEY"
57+
K8S_SECRET_SKIP_DATABASE_CHECK: 1
58+
K8S_SECRET_TOKEN_AUTH_AUTHSERVER_URL: "https://api.hel.fi/sso/openid"
59+
K8S_SECRET_ILMOITIN_QUEUE_NOTIFICATIONS: 1
60+
K8S_SECRET_MAIL_MAILGUN_KEY: "$SECRET_MAILGUN_API_KEY"
61+
K8S_SECRET_MAIL_MAILGUN_DOMAIN: "mail.hel.ninja"
62+
K8S_SECRET_MAIL_MAILGUN_API: "https://api.eu.mailgun.net/v3"
63+
K8S_SECRET_MAILER_EMAIL_BACKEND: "anymail.backends.mailgun.EmailBackend"
64+
K8S_SECRET_DEFAULT_FROM_EMAIL: "no-reply@hel.ninja"
65+
K8S_SECRET_SENTRY_DSN: "$GL_SENTRY_DNS"
66+
K8S_SECRET_SENTRY_ENVIRONMENT: "production"
67+
K8S_SECRET_QURIIRI_API_KEY: "$GL_QURIIRI_API_KEY"
68+
K8S_SECRET_QURIIRI_API_URL: "$GL_QURIIRI_API_URL"

.prod/uwsgi.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[uwsgi]
22
http-socket = :8000
33
chdir = /app
4-
module = palvelutarjotin.wsgi
4+
module = notification_service.wsgi
55
static-map = /static=/var/static
66
static-map = /media=/app/var/media
77
uid = appuser

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!-- REMINDER: While updating changelog, also remember to update
2+
the version in notification_service/__init.py__ -->
3+
4+
## [0.1.0] - 5 Oct 2020
5+
### Added
6+
7+
- Notification REST API:
8+
- Add API token authentication
9+
- Add API to send SMS to phone numbers
10+
- Add delivery log endpoint to receive delivery report from webhook
11+
- Add API to query delivery report by message UUID
12+
13+
[Unreleased]: https://github.com/City-of-Helsinki/notificartion-service/compare/release-v0.1.0...HEAD
14+
[0.1.0]: https://github.com/City-of-Helsinki/notification-service/releases/tag/release-v0.1.0
15+

api/admin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
# from django.contrib import admin
1+
from api.models import DeliveryLog
2+
from django.contrib import admin
23

3-
# Register your models here.
4+
admin.site.register(DeliveryLog)

api/apps.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33

44
class ApiConfig(AppConfig):
55
name = "api"
6+
7+
def ready(self):
8+
import api.signals # noqa

api/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NOTIFICATION_TYPE_MOBILE = "mobile"

api/factories.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import factory
2+
from api.models import DeliveryLog
3+
from users.factories import UserFactory
4+
5+
6+
class DeliveryLogFactory(factory.django.DjangoModelFactory):
7+
report = factory.Faker("pystr", max_chars=255)
8+
user = factory.SubFactory(UserFactory)
9+
10+
class Meta:
11+
model = DeliveryLog

api/migrations/0001_initial.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Generated by Django 2.2.13 on 2020-07-27 13:18
2+
3+
import uuid
4+
5+
import django.contrib.postgres.fields.jsonb
6+
import django.db.models.deletion
7+
from django.conf import settings
8+
from django.db import migrations, models
9+
10+
11+
class Migration(migrations.Migration):
12+
13+
initial = True
14+
15+
dependencies = [
16+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
17+
]
18+
19+
operations = [
20+
migrations.CreateModel(
21+
name="DeliveryLog",
22+
fields=[
23+
(
24+
"id",
25+
models.UUIDField(
26+
default=uuid.uuid4,
27+
editable=False,
28+
primary_key=True,
29+
serialize=False,
30+
verbose_name="UUID",
31+
),
32+
),
33+
(
34+
"created_at",
35+
models.DateTimeField(auto_now_add=True, verbose_name="created at"),
36+
),
37+
(
38+
"updated_at",
39+
models.DateTimeField(auto_now=True, verbose_name="updated_at"),
40+
),
41+
(
42+
"report",
43+
django.contrib.postgres.fields.jsonb.JSONField(
44+
blank=True, null=True, verbose_name="report"
45+
),
46+
),
47+
(
48+
"user",
49+
models.ForeignKey(
50+
on_delete=django.db.models.deletion.CASCADE,
51+
related_name="delivery_logs",
52+
to=settings.AUTH_USER_MODEL,
53+
verbose_name="user",
54+
),
55+
),
56+
],
57+
options={
58+
"verbose_name": "delivery log",
59+
"verbose_name_plural": "delivery logs",
60+
"ordering": ["-updated_at"],
61+
},
62+
),
63+
]

api/models.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1-
# from django.db import models
2-
31
# Create your models here.
2+
from copy import deepcopy
3+
4+
from common.models import TimestampedModel, UUIDPrimaryKeyModel
5+
from django.contrib.postgres.fields import JSONField
6+
from django.db import models
7+
from django.utils.translation import ugettext_lazy as _
8+
9+
10+
class DeliveryLog(UUIDPrimaryKeyModel, TimestampedModel):
11+
user = models.ForeignKey(
12+
"users.User",
13+
related_name="delivery_logs",
14+
on_delete=models.CASCADE,
15+
verbose_name=_("user"),
16+
)
17+
report = JSONField(verbose_name=_("report"), blank=True, null=True)
18+
19+
class Meta:
20+
verbose_name = _("delivery log")
21+
verbose_name_plural = _("delivery logs")
22+
ordering = ["-updated_at"]
23+
24+
def update_report(self, report_data):
25+
"""
26+
Update delivery of single message base on json data sent from Quriiri to
27+
our service
28+
:param report_data: JSON
29+
:return:
30+
"""
31+
report = self.report
32+
updated_messages = deepcopy(report["messages"])
33+
destination = report_data["destination"]
34+
for k, v in report["messages"].items():
35+
if k == destination or v["converted"] == destination:
36+
updated_messages[k] = report_data
37+
report["messages"] = updated_messages
38+
self.report = report
39+
self.save()

api/serializers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from api.models import DeliveryLog
2+
from rest_framework import serializers
3+
4+
5+
class DeliveryLogSerializer(serializers.ModelSerializer):
6+
report = serializers.JSONField()
7+
8+
class Meta:
9+
model = DeliveryLog
10+
fields = ("id", "report")

0 commit comments

Comments
 (0)