From f2a6f9a2aaf9f828b18df915131cd31db6e26353 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 5 Jul 2023 23:23:46 +0000 Subject: [PATCH 01/21] Bump django from 3.2.18 to 3.2.20 Bumps [django](https://github.com/django/django) from 3.2.18 to 3.2.20. - [Commits](https://github.com/django/django/compare/3.2.18...3.2.20) --- updated-dependencies: - dependency-name: django dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a7319ca86..abfe58555 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ pre-commit==2.15.0 -Django==3.2.18 +Django==3.2.20 django-ckeditor==6.2.0 coverage==6.3.2 sorl-thumbnail==12.8.0 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 02/21] 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 03/21] 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 04/21] 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 05/21] 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 06/21] 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 07/21] 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 ddc15dc38b7aafb791eb2d39004e61801c4ef1b1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 25 Feb 2024 21:59:07 +0000 Subject: [PATCH 08/21] Bump pillow from 9.3.0 to 10.2.0 Bumps [pillow](https://github.com/python-pillow/Pillow) from 9.3.0 to 10.2.0. - [Release notes](https://github.com/python-pillow/Pillow/releases) - [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst) - [Commits](https://github.com/python-pillow/Pillow/compare/9.3.0...10.2.0) --- updated-dependencies: - dependency-name: pillow dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index abfe58555..402f57dde 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ python-coveralls==2.9.3 djangorestframework==3.13.1 django-filter==21.1 Markdown==3.3.6 -Pillow==9.3.0 +Pillow==10.2.0 python-dataporten-auth==2.0.0 social-auth-app-django==5.0.0 rapidfuzz==1.8.2 From 40cc867e976002d05e4f160b1685ffcfa27b1e3d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 19:28:12 +0000 Subject: [PATCH 09/21] Bump django from 3.2.20 to 3.2.24 Bumps [django](https://github.com/django/django) from 3.2.20 to 3.2.24. - [Commits](https://github.com/django/django/compare/3.2.20...3.2.24) --- updated-dependencies: - dependency-name: django dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 402f57dde..c1ce4980f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ pre-commit==2.15.0 -Django==3.2.20 +Django==3.2.24 django-ckeditor==6.2.0 coverage==6.3.2 sorl-thumbnail==12.8.0 From f0210263829178926053f8489f0bcfdd3c0a0f05 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:19:54 +0100 Subject: [PATCH 10/21] fix: :ambulance: pillow version 10 not compatible with django 3 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c1ce4980f..d5b52c655 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ python-coveralls==2.9.3 djangorestframework==3.13.1 django-filter==21.1 Markdown==3.3.6 -Pillow==10.2.0 +Pillow==9.5.0 python-dataporten-auth==2.0.0 social-auth-app-django==5.0.0 rapidfuzz==1.8.2 From 77525f2d36e2125e9ae30733e3f1d0aec7f37d7e Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:26:16 +0100 Subject: [PATCH 11/21] fix: :ambulance: bump back to 9.3 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d5b52c655..52062c9e2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ python-coveralls==2.9.3 djangorestframework==3.13.1 django-filter==21.1 Markdown==3.3.6 -Pillow==9.5.0 +Pillow==9.3.0 python-dataporten-auth==2.0.0 social-auth-app-django==5.0.0 rapidfuzz==1.8.2 From 77ee27ea31862ad757cb3bf26f4f6bc45d465504 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:30:07 +0100 Subject: [PATCH 12/21] revert: django version bump --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 52062c9e2..abfe58555 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ pre-commit==2.15.0 -Django==3.2.24 +Django==3.2.20 django-ckeditor==6.2.0 coverage==6.3.2 sorl-thumbnail==12.8.0 From d061a06f5a92e2b8489399c76e294ae11fca6475 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Thu, 7 Mar 2024 15:26:36 +0100 Subject: [PATCH 13/21] fix: update the workflows --- .github/workflows/deploy.yml | 41 +++++++++++++-------------- .github/workflows/integration.yml | 46 ++++++++++++++++--------------- requirements.txt | 4 +-- 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 68d89cc9e..c3ed83567 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,9 +1,7 @@ name: Deploy to Server on: - pull_request: - # Change to merge when implemented (still beta) - types: [closed] + push: branches: - master @@ -12,22 +10,21 @@ jobs: name: Deploy runs-on: ubuntu-latest steps: - - name: executing remote ssh commands using key - uses: appleboy/ssh-action@v0.1.4 - if: github.event.pull_request.merged == true - with: - host: ${{ secrets.host }} - username: ${{ secrets.user }} - key: ${{ secrets.id }} - port: ${{ secrets.port }} - script: | - cd ${{ secrets.deploy_dir }} - . venv-prod/bin/activate - cd website - git pull - python -m pip install --upgrade pip - pip install --upgrade --force-reinstall -r prod_requirements.txt - python manage.py migrate - python manage.py collectstatic --noinput - python manage.py compilemessages - echo "${{ secrets.dingseboms_password }}" | sudo -S systemctl restart gunicorn + - name: executing remote ssh commands using key + uses: appleboy/ssh-action@v0.1.4 + with: + host: ${{ secrets.host }} + username: ${{ secrets.user }} + key: ${{ secrets.id }} + port: ${{ secrets.port }} + script: | + cd ${{ secrets.deploy_dir }} + . venv-prod/bin/activate + cd website + git pull + python -m pip install --upgrade pip + pip install --upgrade --force-reinstall -r prod_requirements.txt + python manage.py migrate + python manage.py collectstatic --noinput + python manage.py compilemessages + echo "${{ secrets.dingseboms_password }}" | sudo -S systemctl restart gunicorn diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 92ca91d3a..476ec19c3 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -5,31 +5,33 @@ on: branches: - master pull_request: + branches: + - master jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - name: Set up Python 3.8 - uses: actions/setup-python@v1 - with: - python-version: 3.8 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install --upgrade --force-reinstall -r prod_requirements.txt - - name: Initialize Django - # Stop the build if migrations are not committed to repo. If action stops here, - # run `pt manage.py makemigrations` and commit the generated files. - run: | - python manage.py makemigrations --check - python manage.py migrate - - name: Run pre-commit hooks - run: | - pre-commit run --all-files - - name: Run Django tests - run: | - python manage.py test + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: 3.10 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --upgrade --force-reinstall -r prod_requirements.txt + - name: + Initialize Django + # Stop the build if migrations are not committed to repo. If action stops here, + # run `pt manage.py makemigrations` and commit the generated files. + run: | + python manage.py makemigrations --check + python manage.py migrate + - name: Run pre-commit hooks + run: | + pre-commit run --all-files + - name: Run Django tests + run: | + python manage.py test diff --git a/requirements.txt b/requirements.txt index abfe58555..d5b52c655 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ pre-commit==2.15.0 -Django==3.2.20 +Django==3.2.24 django-ckeditor==6.2.0 coverage==6.3.2 sorl-thumbnail==12.8.0 @@ -7,7 +7,7 @@ python-coveralls==2.9.3 djangorestframework==3.13.1 django-filter==21.1 Markdown==3.3.6 -Pillow==9.3.0 +Pillow==9.5.0 python-dataporten-auth==2.0.0 social-auth-app-django==5.0.0 rapidfuzz==1.8.2 From 687a21b4f16befdfe68d4c727815281b6bf978d3 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Thu, 7 Mar 2024 15:30:21 +0100 Subject: [PATCH 14/21] chore: specify python version in string --- .github/workflows/integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 476ec19c3..fd7c11935 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -17,7 +17,7 @@ jobs: - name: Set up Python 3.10 uses: actions/setup-python@v5 with: - python-version: 3.10 + python-version: "3.10" - name: Install dependencies run: | python -m pip install --upgrade pip From 57d422534ea4d22af76ec81af4227f83c0db0fb9 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Thu, 7 Mar 2024 15:34:48 +0100 Subject: [PATCH 15/21] chore: update ssh action --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c3ed83567..ae8cf0a45 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - name: executing remote ssh commands using key - uses: appleboy/ssh-action@v0.1.4 + uses: appleboy/ssh-action@v1.0.3 with: host: ${{ secrets.host }} username: ${{ secrets.user }} 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 16/21] 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 17/21] 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 18/21] 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 19/21] 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 20/21] 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 21/21] 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: