Skip to content

Commit

Permalink
Merge branch 'master' into 789-common-header
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrusegard authored Mar 13, 2024
2 parents bb43b54 + 8e44fa8 commit 755b6a6
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 60 deletions.
41 changes: 19 additions & 22 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Deploy to Server

on:
pull_request:
# Change to merge when implemented (still beta)
types: [closed]
push:
branches:
- master

Expand All @@ -12,22 +10,21 @@ jobs:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands using key
uses: appleboy/[email protected]
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/[email protected]
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
46 changes: 24 additions & 22 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion applications/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
47 changes: 46 additions & 1 deletion authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = [
"[email protected]",
"[email protected]",
]
new_emails = convert_to_stud_email(*emails)

self.assertEqual(emails, new_emails)

def test_convert_ntnu_emails(self):
emails = [
"[email protected]",
"[email protected]",
]

new_emails = convert_to_stud_email(*emails)

self.assertEqual(len(new_emails), 2)
self.assertNotEqual(emails, new_emails)
self.assertEqual(new_emails[0], "[email protected]")
self.assertEqual(new_emails[1], "[email protected]")

def test_convert_ntnu_and_stud_emails(self):
emails = [
"[email protected]",
"[email protected]",
]

new_emails = convert_to_stud_email(*emails)

self.assertEqual(len(new_emails), 2)
self.assertNotEqual(emails, new_emails)
self.assertEqual(new_emails[0], "[email protected]")
self.assertEqual(new_emails[0], emails[0])
self.assertEqual(new_emails[1], "[email protected]")

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("[email protected]", None, None)
self.assertEqual(new_emails, ["[email protected]"])
16 changes: 16 additions & 0 deletions authentication/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions internalportal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)

Expand Down
15 changes: 7 additions & 8 deletions news/templates/news/skill_missing_email.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
LabOps Hackerspace NTNU
5 changes: 3 additions & 2 deletions news/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
UpdateView,
)

from authentication.views import convert_to_stud_email
from committees.models import Committee

from .forms import (
Expand Down Expand Up @@ -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)

Expand All @@ -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(
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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
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
Expand Down

0 comments on commit 755b6a6

Please sign in to comment.