diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 68d89cc9e..ae8cf0a45 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@v1.0.3 + 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..fd7c11935 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/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 63fbb1753..06645727c 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,48 @@ 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"]) + + def test_convert_none_values(self): + new_emails = convert_to_stud_email("f@ntnu.no", None, None) + self.assertEqual(new_emails, ["f@stud.ntnu.no"]) diff --git a/authentication/views.py b/authentication/views.py index ea9c2be7b..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 @@ -94,3 +96,17 @@ 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: 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" + new_emails.append(new_email) + else: + new_emails.append(email) + return new_emails 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..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,19 +18,18 @@ 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 }} 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..6bef9791e 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 ( @@ -400,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) @@ -414,6 +414,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( @@ -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 diff --git a/requirements.txt b/requirements.txt index a7319ca86..d5b52c655 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ pre-commit==2.15.0 -Django==3.2.18 +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