Skip to content

Commit

Permalink
add adminalert email sending (#415), update email helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Apr 24, 2024
1 parent 52837dc commit 83899f7
Show file tree
Hide file tree
Showing 12 changed files with 438 additions and 56 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Added
- **General**
- Python v3.11 support (#1157)
- Flake8 rule in ``Makefile`` (#1387)
- **Adminalerts**
- Admin alert email sending (#415)
- ``notify_email_alert`` app setting (#415)
- **Filesfolders**
- Optional pagination for REST API list views (#1313)
- **Projectroles**
Expand All @@ -29,6 +32,7 @@ Added
- ``SODARPageNumberPagination`` pagination class (#1313)
- Optional pagination for REST API list views (#1313)
- Email notification opt-out settings (#1417)
- CC and BCC field support in sending generic emails (#415)
- **Timeline**
- ``sodar_uuid`` field in ``TimelineEventObjectRef`` model (#1415)
- REST API views (#1350)
Expand Down
20 changes: 18 additions & 2 deletions adminalerts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,28 @@
from adminalerts.models import AdminAlert


# Local constants
EMAIL_HELP_CREATE = 'Send alert as email to all users on this site'
EMAIL_HELP_UPDATE = 'Send updated alert as email to all users on this site'


class AdminAlertForm(SODARModelForm):
"""Form for AdminAlert creation/updating"""

send_email = forms.BooleanField(
initial=True,
label='Send alert as email',
required=False,
)

class Meta:
model = AdminAlert
fields = [
'message',
'date_expire',
'active',
'require_auth',
'send_email',
'description',
]

Expand All @@ -40,13 +52,17 @@ def __init__(self, current_user=None, *args, **kwargs):

# Creation
if not self.instance.pk:
self.fields['date_expire'].initial = (
timezone.now() + timezone.timedelta(days=1)
self.initial['date_expire'] = timezone.now() + timezone.timedelta(
days=1
)
self.fields['send_email'].help_text = EMAIL_HELP_CREATE
# Updating
else: # self.instance.pk
# Set description value as raw markdown
self.initial['description'] = self.instance.description.raw
self.fields['send_email'].help_text = EMAIL_HELP_UPDATE
# Sending email for update should be false by default
self.initial['send_email'] = False

def clean(self):
"""Custom form validation and cleanup"""
Expand Down
21 changes: 21 additions & 0 deletions adminalerts/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
from django.utils import timezone

# Projectroles dependency
from projectroles.models import SODAR_CONSTANTS
from projectroles.plugins import SiteAppPluginPoint

from adminalerts.models import AdminAlert
from adminalerts.urls import urlpatterns


# SODAR constants
APP_SETTING_SCOPE_USER = SODAR_CONSTANTS['APP_SETTING_SCOPE_USER']


class SiteAppPlugin(SiteAppPluginPoint):
"""Projectroles plugin for registering the app"""

Expand All @@ -22,6 +27,22 @@ class SiteAppPlugin(SiteAppPluginPoint):
#: UI URLs
urls = urlpatterns

#: App settings definition
app_settings = {
'notify_email_alert': {
'scope': APP_SETTING_SCOPE_USER,
'type': 'BOOLEAN',
'default': True,
'label': 'Receive email for admin alerts',
'description': (
'Receive email for important administrator alerts regarding '
'e.g. site downtime.'
),
'user_modifiable': True,
'global': False,
}
}

#: Iconify icon
icon = 'mdi:alert'

Expand Down
Loading

0 comments on commit 83899f7

Please sign in to comment.