Skip to content
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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

Conversation

pxwxnvermx
Copy link
Contributor

Product Description

No user-facing changes.

Technical Summary

This PR adds functionality to manage consent and keys required for messaging functionality provided by ConnectID.

Ticket

Feature Flag

Safety Assurance

Safety story

Automated test coverage

QA Plan

Migrations

  • The migrations in this code can be safely applied first independently of the code

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Labels & Review

  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@pxwxnvermx pxwxnvermx self-assigned this Oct 14, 2024
@dimagimon dimagimon added the reindex/migration Reindex or migration will be required during or before deploy label Oct 14, 2024
@pxwxnvermx pxwxnvermx changed the title Pkv/messaging api urls ConnectID: Messaging Consent and Key Oct 16, 2024
Copy link
Contributor

@calellowitz calellowitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few changes, but I think this is close



class ConnectIDMessagingKey(models.Model):
domain = models.TextField()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary since the user_link has a domain field already

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have an active boolean as well, so we rotate out keys

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 active boolean here as well.

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.create(connectid_user_link=link, domain=request.domain, key=key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be get_or_create so we don't generate a new one each time.

@@ -1685,6 +1687,25 @@ def link_connectid_user(request, domain):
return HttpResponse()


@csrf_exempt
@login_or_basic_ex(allow_cc_users=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to allow auth via connectid token, which this decorator can't do. We might need a new decorator that looks up the user via the connectid token (and validates it with connectid), or to just do it in the method.

@csrf_exempt
@require_POST
@login_or_basic_ex(allow_cc_users=True)
def update_connectid_messaging_consent(request, domain):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will come from the connectid server, not a specific user.

@@ -3282,6 +3282,14 @@ 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a channel_id as well, since that is how incoming requests will be able to show which channel they go to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reindex/migration Reindex or migration will be required during or before deploy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants