-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
149 additions
and
39 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
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,27 @@ | ||
from django.contrib.auth.tokens import PasswordResetTokenGenerator | ||
from organizations.backends.defaults import ( | ||
InvitationBackend as BaseInvitationBackend, | ||
) | ||
|
||
from .models import Organization | ||
|
||
|
||
class InvitationTokenGenerator(PasswordResetTokenGenerator): | ||
def _make_hash_value(self, user, timestamp): | ||
return str(user.pk) + str(timestamp) | ||
|
||
|
||
class InvitationBackend(BaseInvitationBackend): | ||
""" | ||
Based on django-organizations InvitationBackend but for org user instead of user | ||
""" | ||
|
||
def __init__(self, org_model=None, namespace=None): | ||
self.user_model = None | ||
self.org_model = Organization | ||
self.namespace = namespace | ||
|
||
# TODO def get_urls(self): | ||
|
||
def get_token(self, org_user, **kwargs): | ||
return InvitationTokenGenerator().make_token(org_user) |
26 changes: 26 additions & 0 deletions
26
kobo/apps/organizations/migrations/0002_auto_20230630_1710.py
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,26 @@ | ||
# Generated by Django 3.2.15 on 2023-06-30 17:10 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('organizations', '0001_squashed_0004_remove_organization_uid'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='organizationuser', | ||
name='email', | ||
field=models.EmailField(blank=True, help_text='Email for pending invite', max_length=254, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='organizationuser', | ||
name='user', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
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
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions
7
kobo/apps/organizations/templates/organizations/email/invitation_body.html
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,7 @@ | ||
You've been invited to join {{ organization|safe }} on {{ domain.name }} by {{ sender.first_name|safe }} {{ sender.last_name|safe }}. | ||
|
||
Follow this link to create your user account. | ||
|
||
http://{{ domain.domain }}{% url "invitations_register" user.pk token %} | ||
|
||
If you are unsure about this link please contact the sender. |
1 change: 1 addition & 0 deletions
1
kobo/apps/organizations/templates/organizations/email/invitation_subject.txt
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 @@ | ||
{% spaceless %}You've been invited!{% endspaceless %} |
7 changes: 7 additions & 0 deletions
7
kobo/apps/organizations/templates/organizations/email/modeled_invitation_body.html
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,7 @@ | ||
You've been invited to join {{ organization|safe }} on {{ domain.name }} by {{ sender.first_name|safe }} {{ sender.last_name|safe }}. | ||
|
||
Follow this link to create your user account. | ||
|
||
http://{{ domain.domain }}{{ invitation }} | ||
|
||
If you are unsure about this link please contact the sender. |
1 change: 1 addition & 0 deletions
1
kobo/apps/organizations/templates/organizations/email/modeled_invitation_subject.txt
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 @@ | ||
{% spaceless %}You've been invited!{% endspaceless %} |
7 changes: 7 additions & 0 deletions
7
kobo/apps/organizations/templates/organizations/email/notification_body.html
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,7 @@ | ||
You've been added to the organization {{ organization|safe }} on {{ domain.name }} by {{ sender.full_name|safe }}.` | ||
|
||
Follow the link below to view this organization. | ||
|
||
http://{{ domain.domain }}{% url "organization_detail" organization.pk %} | ||
|
||
If you are unsure about this link please contact the sender. |
1 change: 1 addition & 0 deletions
1
kobo/apps/organizations/templates/organizations/email/notification_subject.txt
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 @@ | ||
{% spaceless %}You've been added to an organization{% endspaceless %} |
7 changes: 7 additions & 0 deletions
7
kobo/apps/organizations/templates/organizations/email/reminder_body.html
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,7 @@ | ||
You've been invited to join {{ organization|safe }} on {{ domain.name }} by {{ sender.first_name|safe }} {{ sender.last_name|safe }}. | ||
|
||
Follow this link to create your user account. | ||
|
||
http://{{ domain.domain }}{% url "invitations_register" user.pk token %} | ||
|
||
If you are unsure about this link please contact the sender. |
1 change: 1 addition & 0 deletions
1
kobo/apps/organizations/templates/organizations/email/reminder_subject.txt
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 @@ | ||
Just a reminder |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from django.contrib.auth.models import User | ||
from django.core import mail | ||
from django.urls import reverse | ||
from model_bakery import baker | ||
|
||
from kpi.tests.kpi_test_case import BaseTestCase | ||
from kpi.urls.router_api_v2 import URL_NAMESPACE | ||
from ..models import OrganizationUser | ||
|
||
|
||
class OrganizationUserTestCase(BaseTestCase): | ||
|
@@ -24,7 +26,9 @@ def setUp(self): | |
|
||
def test_list(self): | ||
org_user = baker.make( | ||
"organizations.OrganizationUser", organization=self.organization | ||
"organizations.OrganizationUser", | ||
organization=self.organization, | ||
_fill_optional=["user"], | ||
) | ||
bad_org_user = baker.make("organizations.OrganizationUser") | ||
with self.assertNumQueries(3): | ||
|
@@ -34,6 +38,16 @@ def test_list(self): | |
|
||
def test_create(self): | ||
data = {"is_admin": False, "email": "[email protected]"} | ||
with self.assertNumQueries(3): | ||
res = self.client.post(self.url_list, data) | ||
res = self.client.post(self.url_list, data) | ||
self.assertContains(res, data["email"], status_code=201) | ||
self.assertTrue( | ||
OrganizationUser.objects.get(email=data["email"], user=None) | ||
) | ||
self.assertEqual(len(mail.outbox), 1) | ||
|
||
def test_invite_accept(self): | ||
data = {"is_admin": False, "email": "[email protected]"} | ||
res = self.client.post(self.url_list, data) | ||
body = mail.outbox[0].body | ||
token = body[body.find("invitations/") :].split("/")[1] | ||
|
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