Skip to content

Commit

Permalink
add ProjectInvite.get_url() (#1485)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 5, 2024
1 parent ddb67e7 commit af05c73
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Added

- **Projectroles**
- ``get_user_by_uuid()`` common template tag (#1478)
- ``ProjectInvite.get_url()`` helper (#1485)

Changed
-------
Expand All @@ -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)
===================
Expand Down
5 changes: 2 additions & 3 deletions projectroles/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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'
),
Expand Down
13 changes: 13 additions & 0 deletions projectroles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------------------------------------------------------

Expand Down
12 changes: 11 additions & 1 deletion projectroles/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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',
Expand Down
13 changes: 0 additions & 13 deletions projectroles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af05c73

Please sign in to comment.