From f58ed355d0b5e83780fe13e18127d4b8c20c4289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Mon, 19 Feb 2024 22:28:44 +0100 Subject: [PATCH 01/12] add convert stud email method --- authentication/tests.py | 43 ++++++++++++++++++++++++++++++++++++++++- authentication/views.py | 12 ++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/authentication/tests.py b/authentication/tests.py index 63fbb1753..560ccb8a6 100644 --- a/authentication/tests.py +++ b/authentication/tests.py @@ -5,7 +5,7 @@ from social_django.utils import load_backend, load_strategy from authentication.apps import AuthenticationConfig -from authentication.views import associate_by_email, save_profile +from authentication.views import associate_by_email, convert_to_stud_email, save_profile class AuthenticationConfigTest(TestCase): @@ -126,3 +126,44 @@ def test_existing_user_profiles(self): def test_assoc_existing_user(self): associate = associate_by_email(self.backend, {}, user=self.testuser) self.assertIsNone(associate) + + def test_convert_stud_emails(self): + emails = [ + "no@stud.ntnu.no", + "some_other_stud@stud.ntnu.no", + ] + new_emails = convert_to_stud_email(*emails) + + self.assertEqual(emails, new_emails) + + def test_convert_ntnu_emails(self): + emails = [ + "no@ntnu.no", + "some_other_stud@ntnu.no", + ] + + new_emails = convert_to_stud_email(*emails) + + self.assertEqual(len(new_emails), 2) + self.assertNotEqual(emails, new_emails) + self.assertEqual(new_emails[0], "no@stud.ntnu.no") + self.assertEqual(new_emails[1], "some_other_stud@stud.ntnu.no") + + def test_convert_ntnu_and_stud_emails(self): + emails = [ + "no@stud.ntnu.no", + "some_other_stud@ntnu.no", + ] + + new_emails = convert_to_stud_email(*emails) + + self.assertEqual(len(new_emails), 2) + self.assertNotEqual(emails, new_emails) + self.assertEqual(new_emails[0], "no@stud.ntnu.no") + self.assertEqual(new_emails[0], emails[0]) + self.assertEqual(new_emails[1], "some_other_stud@stud.ntnu.no") + + def test_convert_empty_email(self): + emails = ["", "ntnu", "@ntnu", "@ntnu.no"] + new_emails = convert_to_stud_email(*emails) + self.assertEqual(new_emails, ["", "ntnu", "@stud.ntnu.no", "@stud.ntnu.no"]) diff --git a/authentication/views.py b/authentication/views.py index ea9c2be7b..f46589def 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -94,3 +94,15 @@ def get_user_by_stud_or_ntnu_email(email: str): user = User.objects.filter(email=query_email).first() if user: return user + + +def convert_to_stud_email(*user_emails: str): + new_emails = [] + for email in user_emails: + split_email = email.split("@ntnu") + if len(split_email) > 1: + new_email = split_email[0] + "@stud.ntnu.no" + new_emails.append(new_email) + else: + new_emails.append(email) + return new_emails From 558ad4062a4056149b192d64ad5a0bc1035f740c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Mon, 19 Feb 2024 22:46:57 +0100 Subject: [PATCH 02/12] change to use converter when sending internal emails --- applications/forms.py | 3 ++- authentication/tests.py | 4 ++++ authentication/views.py | 6 +++++- internalportal/views.py | 4 ++-- news/templates/news/skill_missing_email.txt | 2 +- news/views.py | 3 ++- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/applications/forms.py b/applications/forms.py index 037165159..e2e7ce2d6 100644 --- a/applications/forms.py +++ b/applications/forms.py @@ -3,6 +3,7 @@ from django.template.loader import render_to_string from django.urls import reverse +from authentication.views import convert_to_stud_email from committees.models import Committee from .models import Application, ApplicationGroupChoice @@ -94,6 +95,6 @@ def send_email(self): "[Hackerspace NTNU] Ny søknad!", new_application_message, "Hackerspace NTNU", - emails, + convert_to_stud_email(*emails), fail_silently=False, ) diff --git a/authentication/tests.py b/authentication/tests.py index 560ccb8a6..1e6fd0ed9 100644 --- a/authentication/tests.py +++ b/authentication/tests.py @@ -167,3 +167,7 @@ def test_convert_empty_email(self): emails = ["", "ntnu", "@ntnu", "@ntnu.no"] new_emails = convert_to_stud_email(*emails) self.assertEqual(new_emails, ["", "ntnu", "@stud.ntnu.no", "@stud.ntnu.no"]) + + def test_convert_none_values(self): + new_emails = convert_to_stud_email("f@ntnu.no", None, None) + self.assertEqual(new_emails, ["f@ntnu.no"]) diff --git a/authentication/views.py b/authentication/views.py index f46589def..090e68158 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -1,3 +1,5 @@ +from typing import List, Union + from django.contrib.auth import get_user_model, logout from django.shortcuts import redirect from django.urls import reverse @@ -96,9 +98,11 @@ def get_user_by_stud_or_ntnu_email(email: str): return user -def convert_to_stud_email(*user_emails: str): +def convert_to_stud_email(*user_emails: Union[str, None]) -> List[str]: new_emails = [] for email in user_emails: + if not email: + continue split_email = email.split("@ntnu") if len(split_email) > 1: new_email = split_email[0] + "@stud.ntnu.no" diff --git a/internalportal/views.py b/internalportal/views.py index 0c04454e1..11266e76e 100644 --- a/internalportal/views.py +++ b/internalportal/views.py @@ -16,7 +16,7 @@ from django.views.generic.edit import BaseDetailView from applications.models import Application, ApplicationGroup, ApplicationGroupChoice -from authentication.views import get_user_by_stud_or_ntnu_email +from authentication.views import convert_to_stud_email, get_user_by_stud_or_ntnu_email from committees.models import Committee from internalportal.forms import InterviewEmailForm from inventory.models.item_loan import ItemLoan @@ -170,7 +170,7 @@ def get(self, request, *args, **kwargs): _("Søknad sendt videre"), new_application_message, "Hackerspace NTNU", - emails, + convert_to_stud_email(*emails), fail_silently=False, ) diff --git a/news/templates/news/skill_missing_email.txt b/news/templates/news/skill_missing_email.txt index 01eaa232b..e0d2d5932 100644 --- a/news/templates/news/skill_missing_email.txt +++ b/news/templates/news/skill_missing_email.txt @@ -33,4 +33,4 @@ Access the event here: hackerspace-ntnu.no/events/{{ event.id }} If this is not accurate, you can contact LabOps. Best regards, -LabOps Hackerspace NTNU \ No newline at end of file +LabOps Hackerspace NTNU diff --git a/news/views.py b/news/views.py index 9e1115a2b..f37d92bb7 100644 --- a/news/views.py +++ b/news/views.py @@ -21,6 +21,7 @@ UpdateView, ) +from authentication.views import convert_to_stud_email from committees.models import Committee from .forms import ( @@ -425,7 +426,7 @@ def _send_mail_to_members_without_skill(self, skills, event): "[Hackerspace NTNU] Arrangement gir skill du mangler!", plain_message, "Hackerspace NTNU", - list(members_without_skill), + convert_to_stud_email(members_without_skill), fail_silently=False, ) pass From b93dde07de963785153860e819bda8b9b7fb3dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Mon, 19 Feb 2024 22:52:37 +0100 Subject: [PATCH 03/12] get emails from members without skill --- news/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/news/views.py b/news/views.py index f37d92bb7..f35fd9aaf 100644 --- a/news/views.py +++ b/news/views.py @@ -415,6 +415,7 @@ def _send_mail_to_members_without_skill(self, skills, event): get_user_model() .objects.filter(groups__name__in=list(committee_array)) .exclude(profile__skills__in=skills) + .values_list("email", flat=True) ) plain_message = render_to_string( @@ -426,7 +427,7 @@ def _send_mail_to_members_without_skill(self, skills, event): "[Hackerspace NTNU] Arrangement gir skill du mangler!", plain_message, "Hackerspace NTNU", - convert_to_stud_email(members_without_skill), + convert_to_stud_email(*members_without_skill), fail_silently=False, ) pass From 9ce0f2d7274652567a760a773216feac439518c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Mon, 19 Feb 2024 23:08:57 +0100 Subject: [PATCH 04/12] updated skill missing email --- news/templates/news/skill_missing_email.txt | 13 ++++++------- news/views.py | 1 - 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/news/templates/news/skill_missing_email.txt b/news/templates/news/skill_missing_email.txt index e0d2d5932..e79c47d69 100644 --- a/news/templates/news/skill_missing_email.txt +++ b/news/templates/news/skill_missing_email.txt @@ -1,8 +1,8 @@ Hei, Denne mailen blir sendt til deg fordi du mangler - -{% for skill in skills %}{{ skill }} {% endfor %} +{% for skill in skills %} +{{ skill }}{% endfor %} Det har nå blitt åpnet et arrangement som gir denne skillen så meld deg på. Husk at for å kunne pange må man ha oppnådd Hackerspace grunnkurs. @@ -18,15 +18,14 @@ LabOps Hackerspace NTNU ----------------------------------- - Hello, -This email is being sent to you because you are missing the following skill(s): - -{% for skill in skills %}{{ skill }} {% endfor %} +This email is being sent to you because you have not acquired the following skill(s): +{% for skill in skills %} +{{ skill }}{% endfor %} An event has now been opened that offers this skill, so sign up. -Please remember that to participate, one must have completed the Hackerspace basic course. +Please remember that to retire (pang), one must have completed the Hackerspace basic course. Access the event here: hackerspace-ntnu.no/events/{{ event.id }} diff --git a/news/views.py b/news/views.py index f35fd9aaf..6bef9791e 100644 --- a/news/views.py +++ b/news/views.py @@ -401,7 +401,6 @@ def form_valid(self, form): upload_form.save() skills = form.cleaned_data["skills"] - print(skills) if len(skills) > 0 and not form.cleaned_data["draft"]: self._send_mail_to_members_without_skill(skills, self.object) From 87c3899c0e1c3480e4359c26cb86bcce4d4dac4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:18:00 +0100 Subject: [PATCH 05/12] change union type and edit test for empty mail --- authentication/tests.py | 6 +++--- authentication/views.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/authentication/tests.py b/authentication/tests.py index 1e6fd0ed9..06645727c 100644 --- a/authentication/tests.py +++ b/authentication/tests.py @@ -164,10 +164,10 @@ def test_convert_ntnu_and_stud_emails(self): self.assertEqual(new_emails[1], "some_other_stud@stud.ntnu.no") def test_convert_empty_email(self): - emails = ["", "ntnu", "@ntnu", "@ntnu.no"] + emails = ["", "ntnu", "@ntnu.", "@ntnu.no"] new_emails = convert_to_stud_email(*emails) - self.assertEqual(new_emails, ["", "ntnu", "@stud.ntnu.no", "@stud.ntnu.no"]) + self.assertEqual(new_emails, ["ntnu", "@stud.ntnu.no", "@stud.ntnu.no"]) def test_convert_none_values(self): new_emails = convert_to_stud_email("f@ntnu.no", None, None) - self.assertEqual(new_emails, ["f@ntnu.no"]) + self.assertEqual(new_emails, ["f@stud.ntnu.no"]) diff --git a/authentication/views.py b/authentication/views.py index 090e68158..303293021 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -1,4 +1,4 @@ -from typing import List, Union +from typing import List from django.contrib.auth import get_user_model, logout from django.shortcuts import redirect @@ -98,7 +98,7 @@ def get_user_by_stud_or_ntnu_email(email: str): return user -def convert_to_stud_email(*user_emails: Union[str, None]) -> List[str]: +def convert_to_stud_email(*user_emails: str | None) -> List[str]: new_emails = [] for email in user_emails: if not email: From a43776dac17356b890bc633f480a6a9b96cb6cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:55:51 +0100 Subject: [PATCH 06/12] add union back --- authentication/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/authentication/views.py b/authentication/views.py index 303293021..090e68158 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Union from django.contrib.auth import get_user_model, logout from django.shortcuts import redirect @@ -98,7 +98,7 @@ def get_user_by_stud_or_ntnu_email(email: str): return user -def convert_to_stud_email(*user_emails: str | None) -> List[str]: +def convert_to_stud_email(*user_emails: Union[str, None]) -> List[str]: new_emails = [] for email in user_emails: if not email: From 3b8bb7d0efbcf0be80942dc3f7bcd174cd15a8d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Mon, 19 Feb 2024 22:28:44 +0100 Subject: [PATCH 07/12] add convert stud email method --- authentication/tests.py | 43 ++++++++++++++++++++++++++++++++++++++++- authentication/views.py | 12 ++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/authentication/tests.py b/authentication/tests.py index 63fbb1753..560ccb8a6 100644 --- a/authentication/tests.py +++ b/authentication/tests.py @@ -5,7 +5,7 @@ from social_django.utils import load_backend, load_strategy from authentication.apps import AuthenticationConfig -from authentication.views import associate_by_email, save_profile +from authentication.views import associate_by_email, convert_to_stud_email, save_profile class AuthenticationConfigTest(TestCase): @@ -126,3 +126,44 @@ def test_existing_user_profiles(self): def test_assoc_existing_user(self): associate = associate_by_email(self.backend, {}, user=self.testuser) self.assertIsNone(associate) + + def test_convert_stud_emails(self): + emails = [ + "no@stud.ntnu.no", + "some_other_stud@stud.ntnu.no", + ] + new_emails = convert_to_stud_email(*emails) + + self.assertEqual(emails, new_emails) + + def test_convert_ntnu_emails(self): + emails = [ + "no@ntnu.no", + "some_other_stud@ntnu.no", + ] + + new_emails = convert_to_stud_email(*emails) + + self.assertEqual(len(new_emails), 2) + self.assertNotEqual(emails, new_emails) + self.assertEqual(new_emails[0], "no@stud.ntnu.no") + self.assertEqual(new_emails[1], "some_other_stud@stud.ntnu.no") + + def test_convert_ntnu_and_stud_emails(self): + emails = [ + "no@stud.ntnu.no", + "some_other_stud@ntnu.no", + ] + + new_emails = convert_to_stud_email(*emails) + + self.assertEqual(len(new_emails), 2) + self.assertNotEqual(emails, new_emails) + self.assertEqual(new_emails[0], "no@stud.ntnu.no") + self.assertEqual(new_emails[0], emails[0]) + self.assertEqual(new_emails[1], "some_other_stud@stud.ntnu.no") + + def test_convert_empty_email(self): + emails = ["", "ntnu", "@ntnu", "@ntnu.no"] + new_emails = convert_to_stud_email(*emails) + self.assertEqual(new_emails, ["", "ntnu", "@stud.ntnu.no", "@stud.ntnu.no"]) diff --git a/authentication/views.py b/authentication/views.py index ea9c2be7b..f46589def 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -94,3 +94,15 @@ def get_user_by_stud_or_ntnu_email(email: str): user = User.objects.filter(email=query_email).first() if user: return user + + +def convert_to_stud_email(*user_emails: str): + new_emails = [] + for email in user_emails: + split_email = email.split("@ntnu") + if len(split_email) > 1: + new_email = split_email[0] + "@stud.ntnu.no" + new_emails.append(new_email) + else: + new_emails.append(email) + return new_emails From 4166db85678fc4fc5352ed3da6e8820a98c75ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Mon, 19 Feb 2024 22:46:57 +0100 Subject: [PATCH 08/12] change to use converter when sending internal emails --- applications/forms.py | 3 ++- authentication/tests.py | 4 ++++ authentication/views.py | 6 +++++- internalportal/views.py | 4 ++-- news/templates/news/skill_missing_email.txt | 2 +- news/views.py | 3 ++- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/applications/forms.py b/applications/forms.py index 037165159..e2e7ce2d6 100644 --- a/applications/forms.py +++ b/applications/forms.py @@ -3,6 +3,7 @@ from django.template.loader import render_to_string from django.urls import reverse +from authentication.views import convert_to_stud_email from committees.models import Committee from .models import Application, ApplicationGroupChoice @@ -94,6 +95,6 @@ def send_email(self): "[Hackerspace NTNU] Ny søknad!", new_application_message, "Hackerspace NTNU", - emails, + convert_to_stud_email(*emails), fail_silently=False, ) diff --git a/authentication/tests.py b/authentication/tests.py index 560ccb8a6..1e6fd0ed9 100644 --- a/authentication/tests.py +++ b/authentication/tests.py @@ -167,3 +167,7 @@ def test_convert_empty_email(self): emails = ["", "ntnu", "@ntnu", "@ntnu.no"] new_emails = convert_to_stud_email(*emails) self.assertEqual(new_emails, ["", "ntnu", "@stud.ntnu.no", "@stud.ntnu.no"]) + + def test_convert_none_values(self): + new_emails = convert_to_stud_email("f@ntnu.no", None, None) + self.assertEqual(new_emails, ["f@ntnu.no"]) diff --git a/authentication/views.py b/authentication/views.py index f46589def..090e68158 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -1,3 +1,5 @@ +from typing import List, Union + from django.contrib.auth import get_user_model, logout from django.shortcuts import redirect from django.urls import reverse @@ -96,9 +98,11 @@ def get_user_by_stud_or_ntnu_email(email: str): return user -def convert_to_stud_email(*user_emails: str): +def convert_to_stud_email(*user_emails: Union[str, None]) -> List[str]: new_emails = [] for email in user_emails: + if not email: + continue split_email = email.split("@ntnu") if len(split_email) > 1: new_email = split_email[0] + "@stud.ntnu.no" diff --git a/internalportal/views.py b/internalportal/views.py index 0c04454e1..11266e76e 100644 --- a/internalportal/views.py +++ b/internalportal/views.py @@ -16,7 +16,7 @@ from django.views.generic.edit import BaseDetailView from applications.models import Application, ApplicationGroup, ApplicationGroupChoice -from authentication.views import get_user_by_stud_or_ntnu_email +from authentication.views import convert_to_stud_email, get_user_by_stud_or_ntnu_email from committees.models import Committee from internalportal.forms import InterviewEmailForm from inventory.models.item_loan import ItemLoan @@ -170,7 +170,7 @@ def get(self, request, *args, **kwargs): _("Søknad sendt videre"), new_application_message, "Hackerspace NTNU", - emails, + convert_to_stud_email(*emails), fail_silently=False, ) diff --git a/news/templates/news/skill_missing_email.txt b/news/templates/news/skill_missing_email.txt index 01eaa232b..e0d2d5932 100644 --- a/news/templates/news/skill_missing_email.txt +++ b/news/templates/news/skill_missing_email.txt @@ -33,4 +33,4 @@ Access the event here: hackerspace-ntnu.no/events/{{ event.id }} If this is not accurate, you can contact LabOps. Best regards, -LabOps Hackerspace NTNU \ No newline at end of file +LabOps Hackerspace NTNU diff --git a/news/views.py b/news/views.py index 9e1115a2b..f37d92bb7 100644 --- a/news/views.py +++ b/news/views.py @@ -21,6 +21,7 @@ UpdateView, ) +from authentication.views import convert_to_stud_email from committees.models import Committee from .forms import ( @@ -425,7 +426,7 @@ def _send_mail_to_members_without_skill(self, skills, event): "[Hackerspace NTNU] Arrangement gir skill du mangler!", plain_message, "Hackerspace NTNU", - list(members_without_skill), + convert_to_stud_email(members_without_skill), fail_silently=False, ) pass From ecfa68a3cc51763f386fbd6c616e7398cd99a7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Mon, 19 Feb 2024 22:52:37 +0100 Subject: [PATCH 09/12] get emails from members without skill --- news/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/news/views.py b/news/views.py index f37d92bb7..f35fd9aaf 100644 --- a/news/views.py +++ b/news/views.py @@ -415,6 +415,7 @@ def _send_mail_to_members_without_skill(self, skills, event): get_user_model() .objects.filter(groups__name__in=list(committee_array)) .exclude(profile__skills__in=skills) + .values_list("email", flat=True) ) plain_message = render_to_string( @@ -426,7 +427,7 @@ def _send_mail_to_members_without_skill(self, skills, event): "[Hackerspace NTNU] Arrangement gir skill du mangler!", plain_message, "Hackerspace NTNU", - convert_to_stud_email(members_without_skill), + convert_to_stud_email(*members_without_skill), fail_silently=False, ) pass From 63328f7fa90e13024ce4bb1d50f71d8784f586d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Mon, 19 Feb 2024 23:08:57 +0100 Subject: [PATCH 10/12] updated skill missing email --- news/templates/news/skill_missing_email.txt | 13 ++++++------- news/views.py | 1 - 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/news/templates/news/skill_missing_email.txt b/news/templates/news/skill_missing_email.txt index e0d2d5932..e79c47d69 100644 --- a/news/templates/news/skill_missing_email.txt +++ b/news/templates/news/skill_missing_email.txt @@ -1,8 +1,8 @@ Hei, Denne mailen blir sendt til deg fordi du mangler - -{% for skill in skills %}{{ skill }} {% endfor %} +{% for skill in skills %} +{{ skill }}{% endfor %} Det har nå blitt åpnet et arrangement som gir denne skillen så meld deg på. Husk at for å kunne pange må man ha oppnådd Hackerspace grunnkurs. @@ -18,15 +18,14 @@ LabOps Hackerspace NTNU ----------------------------------- - Hello, -This email is being sent to you because you are missing the following skill(s): - -{% for skill in skills %}{{ skill }} {% endfor %} +This email is being sent to you because you have not acquired the following skill(s): +{% for skill in skills %} +{{ skill }}{% endfor %} An event has now been opened that offers this skill, so sign up. -Please remember that to participate, one must have completed the Hackerspace basic course. +Please remember that to retire (pang), one must have completed the Hackerspace basic course. Access the event here: hackerspace-ntnu.no/events/{{ event.id }} diff --git a/news/views.py b/news/views.py index f35fd9aaf..6bef9791e 100644 --- a/news/views.py +++ b/news/views.py @@ -401,7 +401,6 @@ def form_valid(self, form): upload_form.save() skills = form.cleaned_data["skills"] - print(skills) if len(skills) > 0 and not form.cleaned_data["draft"]: self._send_mail_to_members_without_skill(skills, self.object) From 8d65d1d6b39241e363edaccaf8cdd080ba5d170c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:18:00 +0100 Subject: [PATCH 11/12] change union type and edit test for empty mail --- authentication/tests.py | 6 +++--- authentication/views.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/authentication/tests.py b/authentication/tests.py index 1e6fd0ed9..06645727c 100644 --- a/authentication/tests.py +++ b/authentication/tests.py @@ -164,10 +164,10 @@ def test_convert_ntnu_and_stud_emails(self): self.assertEqual(new_emails[1], "some_other_stud@stud.ntnu.no") def test_convert_empty_email(self): - emails = ["", "ntnu", "@ntnu", "@ntnu.no"] + emails = ["", "ntnu", "@ntnu.", "@ntnu.no"] new_emails = convert_to_stud_email(*emails) - self.assertEqual(new_emails, ["", "ntnu", "@stud.ntnu.no", "@stud.ntnu.no"]) + self.assertEqual(new_emails, ["ntnu", "@stud.ntnu.no", "@stud.ntnu.no"]) def test_convert_none_values(self): new_emails = convert_to_stud_email("f@ntnu.no", None, None) - self.assertEqual(new_emails, ["f@ntnu.no"]) + self.assertEqual(new_emails, ["f@stud.ntnu.no"]) diff --git a/authentication/views.py b/authentication/views.py index 090e68158..303293021 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -1,4 +1,4 @@ -from typing import List, Union +from typing import List from django.contrib.auth import get_user_model, logout from django.shortcuts import redirect @@ -98,7 +98,7 @@ def get_user_by_stud_or_ntnu_email(email: str): return user -def convert_to_stud_email(*user_emails: Union[str, None]) -> List[str]: +def convert_to_stud_email(*user_emails: str | None) -> List[str]: new_emails = [] for email in user_emails: if not email: From 730f13b6df5aa47a50e02d368bf77181fab0a2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20G=C3=BCtzkow?= <70779496+CJGutz@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:55:51 +0100 Subject: [PATCH 12/12] add union back --- authentication/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/authentication/views.py b/authentication/views.py index 303293021..090e68158 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Union from django.contrib.auth import get_user_model, logout from django.shortcuts import redirect @@ -98,7 +98,7 @@ def get_user_by_stud_or_ntnu_email(email: str): return user -def convert_to_stud_email(*user_emails: str | None) -> List[str]: +def convert_to_stud_email(*user_emails: Union[str, None]) -> List[str]: new_emails = [] for email in user_emails: if not email: