Skip to content

Commit 976dcc0

Browse files
committed
feat(radiation_protection): automatically creates radiation certification when starting app
- Removed direct usage of environment variable for radiation protection certification name in settings and other modules. - Introduced a new constants file to define the radiation protection certification name. - Updated related code and tests to reference the new constant, ensuring consistency and maintainability. - Cleaned up README and workflow files by removing obsolete environment variable references.
1 parent d52c7dc commit 976dcc0

11 files changed

Lines changed: 58 additions & 29 deletions

File tree

.github/workflows/test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ env:
1616
PYTHON_VERSION: 3.12.8
1717
EUPHROSYNE_TOOLS_API_URL: http://localhost:8001
1818
EROS_HTTP_TOKEN: token
19-
RADIATION_PROTECTION_CERTIFICATION_NAME: quiz
2019
RADIATION_PROTECTION_TALLY_SECRET_KEY: secret
2120
RADIATION_PROTECTION_RISK_ADVISOR_EMAIL: test@test.com
2221

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ You can copy this file to a new `.env` file to easily set up your environment.
5858
| CGU_ACCEPTANCE_DATE | Optional. Deadline from which users must accept the new Terms of Use. If a user has not accepted by this date, they will be redirected to the acceptance page |
5959
| MATOMO_SITE_ID | Matomo site ID for analytics |
6060
| ORCID_USE_SANDBOX | ORCID authentication environment selection. If set to 'true', sandbox environment is used. Defaults to false |
61-
| RADIATION_PROTECTION_CERTIFICATION_NAME | Nom de la certification New AGLAE de radioprotection dans la base de données (modèle `certification.certifications.models.Certification`) |
6261
| RADIATION_PROTECTION_TALLY_SECRET_KEY | Clé secrète utilisé pour sécuriser le webhook où Tally poste les résultats du quiz de radioprotection. Elle se trouve sur la page de configuration des integrations dans le formulaire Tally (via https://tally.so/dashboard) |
6362
| SITE_URL | The URL of this Euphrosyne instance |
6463
| SENTRY_DSN | Optional. Sentry DSN. If omitted, Sentry will not be used |

certification/notifications/tests/test_send_notifications_command.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
from tempfile import TemporaryDirectory
44
from unittest import mock
5+
56
import pytest
67
from django.core import mail
78
from django.core.management import call_command

euphrosyne/settings.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,6 @@ def _get_nav_items(request: HttpRequest) -> list:
392392
METHOD_MODEL_CLASS = "euphrosyne.methods.models.EuphrosyneMethodModel"
393393

394394
# CERTIFICATIONS
395-
RADIATION_PROTECTION_CERTIFICATION_NAME = os.environ[
396-
"RADIATION_PROTECTION_CERTIFICATION_NAME"
397-
]
398395
RADIATION_PROTECTION_TALLY_SECRET_KEY = os.environ[
399396
"RADIATION_PROTECTION_TALLY_SECRET_KEY"
400397
]

radiation_protection/certification.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import typing
33
from functools import lru_cache
44

5-
from django.conf import settings
6-
75
from certification.certifications.models import Certification
86
from certification.notifications.models import (
97
CertificationNotification,
108
NotificationType,
119
)
1210

11+
from .constants import RADIATION_PROTECTION_CERTIFICATION_NAME
12+
1313
if typing.TYPE_CHECKING:
1414
from euphro_auth.models import User
1515

@@ -18,9 +18,7 @@
1818

1919
@lru_cache
2020
def _get_radioprotection_certification() -> Certification:
21-
return Certification.objects.get(
22-
name=settings.RADIATION_PROTECTION_CERTIFICATION_NAME
23-
)
21+
return Certification.objects.get(name=RADIATION_PROTECTION_CERTIFICATION_NAME)
2422

2523

2624
def check_radio_protection_certification(user: "User"):
@@ -35,7 +33,7 @@ def user_has_active_certification(user: "User") -> bool:
3533
except Certification.DoesNotExist:
3634
logger.error(
3735
"Radiation protection certification %s does not exist.",
38-
settings.RADIATION_PROTECTION_CERTIFICATION_NAME,
36+
RADIATION_PROTECTION_CERTIFICATION_NAME,
3937
)
4038
return False
4139
return certification.user_has_valid_participation(user)

radiation_protection/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RADIATION_PROTECTION_CERTIFICATION_NAME = "Radiation protection"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from django.db import migrations
2+
3+
4+
def create_radiation_protection_certification(apps, schema_editor):
5+
"""Create the radiation protection certification."""
6+
from ..constants import RADIATION_PROTECTION_CERTIFICATION_NAME
7+
from certification.certifications.models import CertificationType
8+
9+
Certification = apps.get_model("certification", "Certification")
10+
11+
Certification.objects.get_or_create(
12+
name=RADIATION_PROTECTION_CERTIFICATION_NAME,
13+
defaults={
14+
"type_of": CertificationType.QUIZ,
15+
"description": "Radiation protection certification for AGLAE beamline users",
16+
"num_days_valid": 365,
17+
"invitation_to_complete_email_template_path": "radiation_protection/email/radioprotection_invitation.html",
18+
"success_email_template_path": "radiation_protection/email/radioprotection_success.html",
19+
},
20+
)
21+
22+
23+
def remove_radiation_protection_certification(apps, schema_editor):
24+
"""Remove the radiation protection certification."""
25+
from ..constants import RADIATION_PROTECTION_CERTIFICATION_NAME
26+
27+
Certification = apps.get_model("certification", "Certification")
28+
Certification.objects.filter(name=RADIATION_PROTECTION_CERTIFICATION_NAME).delete()
29+
30+
31+
class Migration(migrations.Migration):
32+
dependencies = [
33+
("certification", "0002_alter_certificationnotification_type_of"),
34+
]
35+
36+
operations = [
37+
migrations.RunPython(
38+
create_radiation_protection_certification,
39+
remove_radiation_protection_certification,
40+
),
41+
]

radiation_protection/migrations/__init__.py

Whitespace-only changes.

radiation_protection/signals.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22
from typing import Type, cast
33

4-
from django.conf import settings
54
from django.db.models.signals import post_save
65
from django.dispatch import receiver
76
from django.utils import timezone
@@ -10,6 +9,7 @@
109
from lab.participations.models import Participation
1110
from lab.runs.models import Run
1211

12+
from .constants import RADIATION_PROTECTION_CERTIFICATION_NAME
1313
from .document import (
1414
fill_radiation_protection_documents,
1515
send_document_to_risk_advisor,
@@ -35,10 +35,7 @@ def handle_radiation_protection_certification(
3535

3636
try:
3737
# Check if this is for the radiation protection certification
38-
if (
39-
instance.quiz.certification.name
40-
!= settings.RADIATION_PROTECTION_CERTIFICATION_NAME
41-
):
38+
if instance.quiz.certification.name != RADIATION_PROTECTION_CERTIFICATION_NAME:
4239
return
4340

4441
# Only proceed if the user passed the quiz

radiation_protection/tests/test_certification.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@
1919
create_invitation_notification,
2020
user_has_active_certification,
2121
)
22-
23-
24-
@pytest.fixture(autouse=True)
25-
def set_certification_name_settings(settings):
26-
settings.RADIATION_PROTECTION_CERTIFICATION_NAME = "radiation"
22+
from radiation_protection.constants import RADIATION_PROTECTION_CERTIFICATION_NAME
2723

2824

2925
@pytest.fixture(name="certification")
3026
def certification_fixture():
31-
return Certification.objects.create(name="radiation", num_days_valid=5)
27+
return Certification.objects.create(
28+
name=RADIATION_PROTECTION_CERTIFICATION_NAME, num_days_valid=5
29+
)
3230

3331

3432
@pytest.fixture(name="quiz")

0 commit comments

Comments
 (0)