-
-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConnectID: Messaging Consent and Key #35212
base: master
Are you sure you want to change the base?
Changes from all commits
35a6f51
4420e87
4c96614
d12b687
cafd2cb
095ccb2
70f9c76
7741827
7d02e73
b9bc775
a27a52c
9c3e5f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Generated by Django 4.2.15 on 2024-10-18 06:35 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("users", "0072_remove_invitation_supply_point"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="connectiduserlink", | ||
name="channel_id", | ||
field=models.CharField(blank=True, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="connectiduserlink", | ||
name="messaging_consent", | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.CreateModel( | ||
name="ConnectIDMessagingKey", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("domain", models.TextField()), | ||
("key", models.CharField(blank=True, max_length=44, null=True)), | ||
("created_on", models.DateTimeField(auto_now_add=True)), | ||
("active", models.BooleanField(default=True)), | ||
( | ||
"connectid_user_link", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="users.connectiduserlink", | ||
), | ||
), | ||
], | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3282,6 +3282,16 @@ class ConnectIDUserLink(models.Model): | |
connectid_username = models.TextField() | ||
commcare_user = models.ForeignKey(User, related_name='connectid_user', on_delete=models.CASCADE) | ||
domain = models.TextField() | ||
messaging_consent = models.BooleanField(default=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. 7d02e73 |
||
channel_id = models.CharField(null=True, blank=True) | ||
|
||
class Meta: | ||
unique_together = ('domain', 'commcare_user') | ||
|
||
|
||
class ConnectIDMessagingKey(models.Model): | ||
domain = models.TextField() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is necessary since the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should have an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the domain here to support the domain deletion test. It was complaining before. I will add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. 7d02e73 |
||
connectid_user_link = models.ForeignKey(ConnectIDUserLink, on_delete=models.CASCADE) | ||
key = models.CharField(max_length=44, null=True, blank=True) | ||
created_on = models.DateTimeField(auto_now_add=True) | ||
active = models.BooleanField(default=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
HttpResponseRedirect, | ||
) | ||
from django.http.response import HttpResponseServerError, JsonResponse | ||
from django.shortcuts import redirect, render | ||
from django.shortcuts import get_object_or_404, redirect, render | ||
from django.template.loader import render_to_string | ||
from django.urls import reverse | ||
from django.utils.decorators import method_decorator | ||
|
@@ -30,6 +30,7 @@ | |
from memoized import memoized | ||
|
||
from casexml.apps.phone.models import SyncLogSQL | ||
from corehq.util.hmac_request import validate_request_hmac | ||
from couchexport.models import Format | ||
from couchexport.writers import Excel2007ExportWriter | ||
from dimagi.utils.web import json_response | ||
|
@@ -53,7 +54,7 @@ | |
from corehq.apps.custom_data_fields.models import ( | ||
CUSTOM_DATA_FIELD_PREFIX, | ||
) | ||
from corehq.apps.domain.auth import get_connectid_userinfo | ||
from corehq.apps.domain.auth import connectid_token_auth, get_connectid_userinfo | ||
from corehq.apps.domain.decorators import ( | ||
domain_admin_required, | ||
login_and_domain_required, | ||
|
@@ -81,6 +82,7 @@ | |
can_edit_workers_location, | ||
location_safe | ||
) | ||
from corehq.apps.mobile_auth.utils import generate_aes_key | ||
from corehq.apps.ota.utils import demo_restore_date_created, turn_off_demo_mode | ||
from corehq.apps.registration.forms import ( | ||
MobileWorkerAccountConfirmationBySMSForm, | ||
|
@@ -119,6 +121,7 @@ | |
) | ||
from corehq.apps.users.models import ( | ||
CommCareUser, | ||
ConnectIDMessagingKey, | ||
CouchUser, | ||
DeactivateMobileWorkerTrigger, | ||
check_and_send_limit_email, | ||
|
@@ -1685,6 +1688,27 @@ def link_connectid_user(request, domain): | |
return HttpResponse() | ||
|
||
|
||
@csrf_exempt | ||
@connectid_token_auth | ||
def connectid_messaging_key(request, domain): | ||
link = get_object_or_404(ConnectIDUserLink, commcare_user=request.user, domain=request.domain) | ||
key = generate_aes_key().decode("utf-8") | ||
messaging_key, _ = ConnectIDMessagingKey.objects.get_or_create( | ||
connectid_user_link=link, domain=request.domain, active=True, defaults={"key": key} | ||
) | ||
return JsonResponse({"key": messaging_key.key}) | ||
|
||
|
||
@csrf_exempt | ||
@require_POST | ||
@validate_request_hmac("CONNECTID_SECRET_KEY") | ||
def update_connectid_messaging_consent(request, domain): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will come from the connectid server, not a specific user. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. b9bc775 |
||
link = get_object_or_404(ConnectIDUserLink, commcare_user=request.user, domain=request.domain) | ||
link.messaging_consent = request.POST.get("consent", False) | ||
link.save() | ||
return HttpResponse(status=200) | ||
|
||
|
||
@waf_allow('XSS_BODY') | ||
@csrf_exempt | ||
@require_POST | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to DRY this with
ConnectIDAuthBackend