From af05c73cf5af4128009e335ff0c210bef6ac477f Mon Sep 17 00:00:00 2001 From: Mikko Nieminen Date: Thu, 5 Sep 2024 12:48:08 +0200 Subject: [PATCH] add ProjectInvite.get_url() (#1485) --- CHANGELOG.rst | 7 +++++++ projectroles/email.py | 5 ++--- projectroles/models.py | 13 +++++++++++++ projectroles/tests/test_models.py | 12 +++++++++++- projectroles/utils.py | 13 ------------- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bfa2e230..83ead18c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,7 @@ Added - **Projectroles** - ``get_user_by_uuid()`` common template tag (#1478) + - ``ProjectInvite.get_url()`` helper (#1485) Changed ------- @@ -35,6 +36,12 @@ Fixed - Incorrect boolean comparison in ``AppSettingAPI._compare_value()`` with string value (#1473) - Boolean app setting update status in remote sync (#1473) +Removed +------- + +- **Projectroles** + - ``build_invite_url()`` utility method (#1485) + v1.0.1 (2024-08-08) =================== diff --git a/projectroles/email.py b/projectroles/email.py index 8bfa7be0..2a3bccc0 100644 --- a/projectroles/email.py +++ b/projectroles/email.py @@ -12,7 +12,7 @@ from projectroles.app_settings import AppSettingAPI from projectroles.models import SODARUserAdditionalEmail from projectroles.plugins import get_app_plugin -from projectroles.utils import build_invite_url, get_display_name +from projectroles.utils import get_display_name app_settings = AppSettingAPI() @@ -502,12 +502,11 @@ def send_invite_mail(invite, request): :param request: HttpRequest object :return: Amount of sent email (int) """ - invite_url = build_invite_url(invite, request) message = get_invite_body( project=invite.project, issuer=invite.issuer, role_name=invite.role.name, - invite_url=invite_url, + invite_url=invite.get_url(request), date_expire_str=localtime(invite.date_expire).strftime( '%Y-%m-%d %H:%M' ), diff --git a/projectroles/models.py b/projectroles/models.py index 01602443..08a17a49 100644 --- a/projectroles/models.py +++ b/projectroles/models.py @@ -1126,6 +1126,19 @@ def is_ldap(self): return True return False + def get_url(self, request): + """ + Return invite URL for a project invitation. + + :param request: HttpRequest object + :return: URL (string) + """ + return request.build_absolute_uri( + reverse( + 'projectroles:invite_accept', kwargs={'secret': self.secret} + ) + ) + # RemoteSite ------------------------------------------------------------------- diff --git a/projectroles/tests/test_models.py b/projectroles/tests/test_models.py index b080b469..7347f0ef 100644 --- a/projectroles/tests/test_models.py +++ b/projectroles/tests/test_models.py @@ -8,7 +8,7 @@ from django.forms.models import model_to_dict from django.urls import reverse from django.utils import timezone -from django.test import override_settings +from django.test import RequestFactory, override_settings from test_plus.test import TestCase @@ -1006,6 +1006,16 @@ def test_is_ldap_non_ldap_domain(self): """Test is_ldap() with non-LDAP domain in email""" self.assertEqual(self.invite.is_ldap(), False) + def test_get_url(self): + """Test get_url()""" + url = reverse( + 'projectroles:invite_accept', kwargs={'secret': self.invite.secret} + ) + request = RequestFactory().get(url) + self.assertEqual( + self.invite.get_url(request), request.build_absolute_uri() + ) + @override_settings( ENABLE_LDAP=True, AUTH_LDAP_USERNAME_DOMAIN='xyz', diff --git a/projectroles/utils.py b/projectroles/utils.py index 950737b2..70837d5d 100644 --- a/projectroles/utils.py +++ b/projectroles/utils.py @@ -77,19 +77,6 @@ def build_secret(length=SECRET_LENGTH): ) -def build_invite_url(invite, request): - """ - Return invite URL for a project invitation. - - :param invite: ProjectInvite object - :param request: HTTP request - :return: URL (string) - """ - return request.build_absolute_uri( - reverse('projectroles:invite_accept', kwargs={'secret': invite.secret}) - ) - - def get_expiry_date(): """ Return expiry date based on current date + INVITE_EXPIRY_DAYS