From a916861da2695c3e75a80b55ca10bb93f6a68c3e Mon Sep 17 00:00:00 2001 From: Lukas Weichelt <lukas.weichelt@teckids.org> Date: Fri, 5 May 2023 22:24:39 +0200 Subject: [PATCH] Remove the django prefix in invitations email --- CHANGELOG.rst | 1 + aleksis/core/frontend/routes.js | 8 +++++++ aleksis/core/models.py | 39 +++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5a8c03cda..b43f0c2ce 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -44,6 +44,7 @@ Fixed * Dynamic routes were not removed/hid when the respective object registering it was deleted. * Django messages were not displayed in Vue frontend. * Links to data check objects did not work properly. +* Urls in invitation email were broken. `3.0b3`_ - 2023-03-19 --------------------- diff --git a/aleksis/core/frontend/routes.js b/aleksis/core/frontend/routes.js index e7fc1e4fe..aa84f36c4 100644 --- a/aleksis/core/frontend/routes.js +++ b/aleksis/core/frontend/routes.js @@ -1055,6 +1055,14 @@ const routes = [ titleKey: "about.page_title", }, }, + { + path: "/invitations/accept-invite/:code", + component: () => import("./components/LegacyBaseTemplate.vue"), + props: { + byTheGreatnessOfTheAlmightyAleksolotlISwearIAmWorthyOfUsingTheLegacyBaseTemplate: true, + }, + name: "invitations.accept_invite", + }, ]; // This imports all known AlekSIS app entrypoints diff --git a/aleksis/core/models.py b/aleksis/core/models.py index 964306358..9f200c1d4 100644 --- a/aleksis/core/models.py +++ b/aleksis/core/models.py @@ -13,6 +13,7 @@ from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.contrib.postgres.fields import ArrayField from django.contrib.sites.models import Site +from django.contrib.sites.shortcuts import get_current_site from django.core.exceptions import ValidationError from django.core.validators import MaxValueValidator from django.db import models, transaction @@ -1223,8 +1224,42 @@ class PersonInvitation(AbstractBaseInvitation, PureDjangoModel): instance = cls.objects.create(email=email, inviter=inviter, key=code, **kwargs) return instance - key_expired = Invitation.key_expired - send_invitation = Invitation.send_invitation + def key_expired(self): + expiration_date = self.sent + timedelta( + days=settings.INVITATIONS_INVITATION_EXPIRY, + ) + return expiration_date <= timezone.now() + + def send_invitation(self, request, **kwargs): + current_site = get_current_site(request) + invite_url = reverse("invitations:accept-invite", args=[self.key]) + invite_url = request.build_absolute_uri(invite_url).replace("/django", "") + ctx = kwargs + ctx.update( + { + "invite_url": invite_url, + "site_name": current_site.name, + "email": self.email, + "key": self.key, + "inviter": self.inviter, + }, + ) + + email_template = "invitations/email/email_invite" + + get_invitations_adapter().send_mail(email_template, self.email, ctx) + self.sent = timezone.now() + self.save() + + signals.invite_url_sent.send( + sender=self.__class__, + instance=self, + invite_url_sent=invite_url, + inviter=self.inviter, + ) + + key_expired = key_expired + send_invitation = send_invitation class PDFFile(ExtensibleModel): -- GitLab