-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into pkv/otp-sender-fixes
- Loading branch information
Showing
40 changed files
with
1,861 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This will make sure the app is always imported when | ||
# Django starts so that shared_task will use this app. | ||
from .celery_app import app as celery_app | ||
|
||
__all__ = ("celery_app",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import os | ||
|
||
from celery import Celery | ||
|
||
# set the default Django settings module for the 'celery' program. | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "connectid.settings") | ||
|
||
app = Celery("connectid") | ||
|
||
# Using a string here means the worker doesn't have to serialize | ||
# the configuration object to child processes. | ||
# - namespace='CELERY' means all celery-related configuration keys | ||
# should have a `CELERY_` prefix. | ||
app.config_from_object("django.conf:settings", namespace="CELERY") | ||
|
||
# Load task modules from all registered Django app configs. | ||
app.autodiscover_tasks() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django.http import HttpResponse, JsonResponse | ||
|
||
|
||
def assetlinks_json(request): | ||
assetfile = [ | ||
{ | ||
"relation": ["delegate_permission/common.handle_all_urls"], | ||
"target": { | ||
"namespace": "android_app", | ||
"package_name": "org.commcare.dalvik", | ||
"sha256_cert_fingerprints": | ||
[ | ||
"88:57:18:F8:E8:7D:74:04:97:AE:83:65:74:ED:EF:10:40:D9:4C:E2:54:F0:E0:40:64:77:96:7F:D1:39:F9:81", | ||
"89:55:DF:D8:0E:66:63:06:D2:6D:88:A4:A3:88:A4:D9:16:5A:C4:1A:7E:E1:C6:78:87:00:37:55:93:03:7B:03" | ||
] | ||
} | ||
}, | ||
{ | ||
"relation": ["delegate_permission/common.handle_all_urls"], | ||
"target": { | ||
"namespace": "android_app", | ||
"package_name": "org.commcare.dalvik.debug", | ||
"sha256_cert_fingerprints": | ||
[ | ||
"88:57:18:F8:E8:7D:74:04:97:AE:83:65:74:ED:EF:10:40:D9:4C:E2:54:F0:E0:40:64:77:96:7F:D1:39:F9:81" | ||
] | ||
} | ||
}, | ||
] | ||
return JsonResponse(assetfile, safe=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.contrib import admin | ||
|
||
from .models import MessageServer | ||
|
||
|
||
@admin.register(MessageServer) | ||
class MessageServerAdmin(admin.ModelAdmin): | ||
list_display = ('name', 'key_url', 'callback_url', 'delivery_url', 'consent_url', 'server_id', 'secret_key') | ||
search_fields = ('name',) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import base64 | ||
import os | ||
from uuid import uuid4 | ||
|
||
import factory | ||
from django.utils import timezone | ||
from factory import LazyFunction | ||
from factory.django import DjangoModelFactory | ||
from oauth2_provider.models import Application | ||
|
||
from messaging.models import Channel, Message, MessageServer | ||
from users.factories import UserFactory | ||
|
||
|
||
class ApplicationFactory(DjangoModelFactory): | ||
class Meta: | ||
model = Application | ||
|
||
client_id = factory.Faker("uuid4") | ||
client_secret = factory.Faker("uuid4") | ||
client_type = "confidential" | ||
authorization_grant_type = factory.Faker("random_element", elements=["authorization-code", "implicit", "password", | ||
"client-credentials"]) | ||
name = factory.Faker("company") | ||
|
||
|
||
class ServerFactory(DjangoModelFactory): | ||
class Meta: | ||
model = MessageServer | ||
|
||
delivery_url = factory.Faker("url") | ||
consent_url = factory.Faker("url") | ||
callback_url = factory.Faker("url") | ||
key_url = factory.Faker("url") | ||
oauth_application = factory.SubFactory(ApplicationFactory) | ||
|
||
|
||
class ChannelFactory(DjangoModelFactory): | ||
class Meta: | ||
model = Channel | ||
|
||
channel_id = factory.LazyFunction(uuid4) | ||
user_consent = True | ||
connect_user = factory.SubFactory(UserFactory) | ||
server = factory.SubFactory(ServerFactory) | ||
|
||
|
||
def generate_random_content(): | ||
nonce = base64.b64encode(os.urandom(12)).decode('utf-8') | ||
tag = base64.b64encode(os.urandom(16)).decode('utf-8') | ||
ciphertext = base64.b64encode(os.urandom(32)).decode('utf-8') | ||
|
||
return { | ||
"nonce": nonce, | ||
"tag": tag, | ||
"ciphertext": ciphertext | ||
} | ||
|
||
|
||
class MessageFactory(DjangoModelFactory): | ||
class Meta: | ||
model = Message | ||
|
||
message_id = factory.LazyFunction(uuid4) | ||
channel = factory.SubFactory(ChannelFactory) | ||
content = LazyFunction(generate_random_content) | ||
timestamp = factory.LazyFunction(timezone.now) | ||
received = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Generated by Django 4.1.7 on 2024-10-24 09:00 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
migrations.swappable_dependency(settings.OAUTH2_PROVIDER_APPLICATION_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Channel", | ||
fields=[ | ||
( | ||
"channel_id", | ||
models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
primary_key=True, | ||
serialize=False, | ||
), | ||
), | ||
("user_consent", models.BooleanField(default=False)), | ||
("channel_source", models.TextField()), | ||
( | ||
"connect_user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="MessageServer", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(max_length=255)), | ||
("key_url", models.URLField()), | ||
("callback_url", models.URLField()), | ||
("delivery_url", models.URLField()), | ||
("consent_url", models.URLField()), | ||
( | ||
"oauth_application", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.OAUTH2_PROVIDER_APPLICATION_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="Message", | ||
fields=[ | ||
( | ||
"message_id", | ||
models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
primary_key=True, | ||
serialize=False, | ||
), | ||
), | ||
("content", models.JSONField()), | ||
("timestamp", models.DateTimeField(default=django.utils.timezone.now)), | ||
("received", models.DateTimeField(blank=True, null=True)), | ||
( | ||
"status", | ||
models.CharField( | ||
choices=[ | ||
("PENDING", "Pending"), | ||
("SENT_TO_SERVICE", "Sent To Service"), | ||
("DELIVERED", "Delivered"), | ||
("CONFIRMED_RECEIVED", "Confirmed Received"), | ||
], | ||
default="PENDING", | ||
max_length=50, | ||
), | ||
), | ||
( | ||
"channel", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="messaging.channel", | ||
), | ||
), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name="channel", | ||
name="server", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="messaging.messageserver", | ||
), | ||
), | ||
] |
Oops, something went wrong.