Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

En cas de modification des évaluateurs, des gabarits moulinette peuvent être attachés à des résultats désormais obsolètes #461

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,4 @@
}

OPS_MATTERMOST_HANDLERS = env.list("DJANGO_OPS_MATTERMOST_HANDLERS", default=[])
CONFIG_MATTERMOST_HANDLERS = env.list("DJANGO_CONFIG_MATTERMOST_HANDLERS", default=[])
4 changes: 4 additions & 0 deletions cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
{
"command": "*/15 * * * * python manage.py new_files_user_alert",
"size": "M"
},
{
"command": "0 2 * * 1 python manage.py obsolete_moulinette_template_admin_alert",
"size": "M"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def handle(self, *args, **options):
Une demande d'avis a été mise à jour.
Adresse : {request.address}
{len(list(files))} nouveaux fichiers ont été ajoutés.
[Admin django](https://envergo.beta.gouv.fr/{url})
[Admin django](https://envergo.beta.gouv.fr{url})

ping {", ".join(settings.OPS_MATTERMOST_HANDLERS)}
"""
Expand Down
4 changes: 3 additions & 1 deletion envergo/moulinette/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ class Meta:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
templates = list(list_moulinette_templates())
self.fields["key"].choices = zip(templates, templates)
self.fields["key"].choices = [
("", "---------"),
] + list(zip(templates, templates))


class MoulinetteConfigTemplateInline(MoulinetteTemplateInline):
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from textwrap import dedent

from django.conf import settings
from django.contrib.sites.models import Site
from django.core.management.base import BaseCommand
from django.urls import reverse

from envergo.moulinette.models import MoulinetteTemplate, get_all_template_keys
from envergo.utils.mattermost import notify


class Command(BaseCommand):
help = "Post a message when a moulinette template has an obsolete key."

def handle(self, *args, **options):
obsolete_templates = MoulinetteTemplate.objects.exclude(
key__in=[tuple[0] for tuple in get_all_template_keys()]
).select_related("config__department", "criterion")

current_site = Site.objects.get(domain=settings.ENVERGO_AMENAGEMENT_DOMAIN)

for template in obsolete_templates:
if template.criterion:
url = reverse(
"admin:moulinette_criterion_change",
args=[template.criterion.id],
)
absolute_url = f"https://{current_site.domain}{url}"
intro = f'Le critère ["{template.criterion.title}"]({absolute_url}) [{template.criterion.id}]'
elif template.config:
url = reverse(
"admin:moulinette_configamenagement_change",
args=[template.config.id],
)
absolute_url = f"https://{current_site.domain}{url}"
config = template.config
intro = f'La config Aménagement du département ["{config.department}"]({absolute_url}) [{config.id}]'
else:
raise NotImplementedError(
"This template is not linked to a criterion or a config"
)

ping = (
f'ping {", ".join(settings.CONFIG_MATTERMOST_HANDLERS)}'
if settings.CONFIG_MATTERMOST_HANDLERS
else ""
)

message = dedent(
f"""\
### Anomalie de configuration

{intro} référence un gabarit moulinette obsolète : id={template.id} clef="{template.key}".

Pour résoudre l’anomalie :
* naviguer en bas du critère [à ce lien]({absolute_url})
* corriger en choisissant une valeur dans le menu déroulant, ou supprimer ce gabarit

{ping}
"""
)

notify(message)
Loading