From 3da922a08450bbf9a0c96912a8cde723d4ebcedd Mon Sep 17 00:00:00 2001 From: AnsibleGuy Date: Sun, 12 May 2024 18:09:14 +0200 Subject: [PATCH] support for custom email templates --- docs/source/usage/alerts.rst | 4 +++- src/ansibleguy-webui/aw/config/defaults.py | 1 + .../aw/config/form_metadata.py | 2 ++ .../aw/execute/alert_plugin/plugin_email.py | 17 ++++++++++++++--- src/ansibleguy-webui/aw/model/system.py | 5 +++-- .../aw/templates/settings/alert.html | 4 +--- src/ansibleguy-webui/aw/views/forms/system.py | 19 +++++++++++++++---- 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/docs/source/usage/alerts.rst b/docs/source/usage/alerts.rst index 123905d..a290434 100644 --- a/docs/source/usage/alerts.rst +++ b/docs/source/usage/alerts.rst @@ -37,6 +37,8 @@ After that you can receive e-mails on job finish/failure. |alert_email| +You can modify the email templates by setting the :code:`Template Directory` in your system config. If you want to do so - copy `the existing templates `_ and modify them as needed. Note: the `Django template syntax `_ is required. + ---- Plugins @@ -63,7 +65,7 @@ There is a generic alert-plugin interface for custom solutions. "name": "ansible", "first_name": "", "last_name": "", - "email": "guy@ansibleguy.net", + "email": "ansible@localhost", "phone": null, "description": "test", "is_active": true, diff --git a/src/ansibleguy-webui/aw/config/defaults.py b/src/ansibleguy-webui/aw/config/defaults.py index 5903f48..47123e6 100644 --- a/src/ansibleguy-webui/aw/config/defaults.py +++ b/src/ansibleguy-webui/aw/config/defaults.py @@ -41,6 +41,7 @@ def _get_defaults_docker(var: str) -> any: 'path_run': '/tmp/ansible-webui', 'path_play': getcwd(), 'path_log': f"{environ['HOME']}/.local/share/ansible-webui", + 'path_template': None, # only for custom overrides 'db': f"{environ['HOME']}/.config/ansible-webui", 'timezone': datetime.now().astimezone().tzname(), 'secret': ''.join(random_choice(ascii_letters + digits + punctuation) for _ in range(50)), diff --git a/src/ansibleguy-webui/aw/config/form_metadata.py b/src/ansibleguy-webui/aw/config/form_metadata.py index cae3b06..389362a 100644 --- a/src/ansibleguy-webui/aw/config/form_metadata.py +++ b/src/ansibleguy-webui/aw/config/form_metadata.py @@ -73,6 +73,7 @@ 'path_run': 'Runtime directory', 'path_play': 'Playbook base-directory', 'path_log': 'Directory for execution-logs', + 'path_template': 'Directory for templates', 'run_timeout': 'Timeout for playbook execution', 'session_timeout': 'Timeout for WebUI login-sessions', 'path_ansible_config': 'Ansible Config-File', @@ -200,6 +201,7 @@ 'path_play': 'Path to the Ansible base/playbook directory', 'path_log': 'Define the path where full job-logs are saved', + 'path_template': 'Define the path where custom templates are placed', 'path_ansible_config': 'Path to a Ansible config-file to use', 'path_ssh_known_hosts': 'Path to a - {% include "../button/refresh.html" %} + {% include "../button/refresh.html" %} diff --git a/src/ansibleguy-webui/aw/views/forms/system.py b/src/ansibleguy-webui/aw/views/forms/system.py index aad884a..d4fa9df 100644 --- a/src/ansibleguy-webui/aw/views/forms/system.py +++ b/src/ansibleguy-webui/aw/views/forms/system.py @@ -22,20 +22,31 @@ class Meta: labels = FORM_LABEL['system']['config'] help_texts = FORM_HELP['system']['config'] - path_run = forms.CharField(max_length=500, initial=CONFIG_DEFAULTS['path_run'], required=True) - path_play = forms.CharField(max_length=500, initial=CONFIG_DEFAULTS['path_play'], required=True) - path_log = forms.CharField(max_length=500, initial=CONFIG_DEFAULTS['path_log'], required=True) + path_run = forms.CharField( + max_length=500, initial=CONFIG_DEFAULTS['path_run'], required=True, + label=Meta.labels['path_run'], + ) + path_play = forms.CharField( + max_length=500, initial=CONFIG_DEFAULTS['path_play'], required=True, + label=Meta.labels['path_play'], + ) + path_log = forms.CharField( + max_length=500, initial=CONFIG_DEFAULTS['path_log'], required=True, + label=Meta.labels['path_log'], + ) path_ansible_config = forms.CharField( max_length=500, initial=CONFIG_DEFAULTS['path_ansible_config'], required=False, + label=Meta.labels['path_ansible_config'], ) path_ssh_known_hosts = forms.CharField( max_length=500, initial=CONFIG_DEFAULTS['path_ssh_known_hosts'], required=False, + label=Meta.labels['path_ssh_known_hosts'], ) timezone = forms.ChoiceField( required=False, widget=forms.Select, choices=[(tz, tz) for tz in sorted(all_timezones)], - label=FORM_LABEL['system']['config']['timezone'], + label=Meta.labels['timezone'], ) debug = forms.ChoiceField( initial=CONFIG_DEFAULTS['debug'] or deployment_dev(), choices=CHOICES_BOOL,